blob: 2e35ce97b2f7df0e85a305af5272e1312af2da06 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Alexander Couzens5283f552020-07-28 15:39:04 +020038import from Native_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020040import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010041
42import from RSL_Types all;
Vadim Yanitskiy18684882021-07-04 04:15:58 +020043import from RTP_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010044import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010045import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020046import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010047import from RSL_Emulation all;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +020048import from RTP_Emulation all;
Harald Welte70767382018-02-21 12:16:40 +010049
50import from IPL4asp_Types all;
51import from TRXC_Types all;
52import from TRXC_CodecPort all;
53import from TRXC_CodecPort_CtrlFunct all;
54
Harald Welte883340c2018-02-28 18:59:29 +010055import from PCUIF_Types all;
56import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020057import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010058
Harald Welte7484fc42018-02-24 14:09:45 +010059import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010060import from MobileL3_RRM_Types all;
61import from MobileL3_Types all;
62import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020063import from L3_Common all;
64import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010065
Harald Welte8da48242018-02-27 20:41:32 +010066import from Osmocom_VTY_Functions all;
67import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020068import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010069
Harald Welte505cf9b2018-09-15 17:47:23 +030070friend module BTS_Tests_SMSCB;
Vadim Yanitskiy73878132021-05-05 02:22:45 +020071friend module BTS_Tests_VAMOS;
Harald Weltead033dc2019-05-25 17:28:16 +020072friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020073friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010074friend module BTS_Tests_perf;
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +020075friend module BTS_Tests_OML;
Harald Welte505cf9b2018-09-15 17:47:23 +030076
Harald Welte70767382018-02-21 12:16:40 +010077/* The tests assume a BTS with the following timeslot configuration:
78 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020079 * TS1 : TCH/F
80 * TS2 : TCH/F
81 * TS3 : TCH/F_PDCH (IPA Style)
82 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010083 * TS5 : TCH/H
84 * TS6 : SDCCH/8
85 * TS7 : PDCH
86 */
87
88modulepar {
89 charstring mp_rsl_ip := "127.0.0.2";
90 integer mp_rsl_port := 3003;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070091 charstring mp_bts_trxc_ip := "127.0.0.1";
92 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010093 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020094 charstring mp_ctrl_ip := "127.0.0.1";
95 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020096 charstring mp_bsc_ctrl_ip := "127.0.0.1";
97 integer mp_bsc_ctrl_port := 4249;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +020098 charstring mp_rtpem_bind_ip := "127.0.0.1";
99 integer mp_rtpem_bind_port := 6766;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200100 integer mp_tolerance_rxqual := 1;
101 integer mp_tolerance_rxlev := 3;
102 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200103 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200104 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200105 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200106 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
107 integer mp_bts_tx_pwr_att_exp := 20; /* Expected Tx Power attenuation wrt to Tx Nominal Output Power, in dB */
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200108 integer mp_ms_actual_ta_exp := 0;
109 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700110 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700111 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100112 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200113 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200114 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200115 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
116 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700117 /* how many transceivers do we expect to connect */
118 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700119 /* frequency hopping status */
120 boolean mp_freq_hop_enabled := false;
121 /* frequency hopping parameters */
122 FreqHopConfig mp_fh_config;
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700123 /* configuration for each individual transceiver */
124 TrxPars mp_trx_pars; /* see BTS_Tests.default */
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700125 /* default Training Sequence Code */
126 GsmTsc mp_tsc_def := 7;
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +0200127 /* Default interference boundaries in osmo-bsc (in dBm):
128 * 0(-85) X1(-91) X2(-97) X3(-103) X4(-109) X5(-115)
129 * Default interference level reported by fake_trx.py:
130 * 0: -109 >= -85 dBm (no)
131 * X1: -109 >= -91 dBm (no)
132 * X2: -109 >= -97 dBm (no)
133 * X3: -109 >= -103 dBm (no)
134 * X4: -109 >= -109 dBm (yes)
135 * X5: -109 >= -115 dBm (no)
136 * So all channels should be in band 4. */
137 uint3_t mp_interf_band := 4;
Harald Welte70767382018-02-21 12:16:40 +0100138}
139
Harald Welte629cc6b2018-03-11 17:19:05 +0100140type record of RslChannelNr ChannelNrs;
141
Harald Welte70767382018-02-21 12:16:40 +0100142type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100143 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100144 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100145 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100146 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100147 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100148 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100149
150 /* L1CTL port (for classic tests) */
151 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100152
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700153 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700154 port TRXC_CODEC_PT BTS_TRXC;
155 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100156
Harald Weltef50e3ae2018-09-10 10:27:56 +0200157 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100158 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200159 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100160
Harald Welte883340c2018-02-28 18:59:29 +0100161 /* PCU Interface of BTS */
162 port PCUIF_CODEC_PT PCU;
163 var integer g_pcu_conn_id;
164 /* Last PCU INFO IND we received */
165 var PCUIF_Message g_pcu_last_info;
166
Harald Welte48494ca2018-02-25 16:59:50 +0100167 /* SI configuration */
168 var SystemInformationConfig si_cfg := {
169 bcch_extended := false,
170 si1_present := false,
171 si2bis_present := false,
172 si2ter_present := false,
173 si2quater_present := false,
174 si7_present := false,
175 si8_present := false,
176 si9_present := false,
177 si13_present := false,
178 si13alt_present := false,
179 si15_present := false,
180 si16_present := false,
181 si17_present := false,
182 si2n_present := false,
183 si21_present := false,
184 si22_present := false
185 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100186
187 /* all logical channels available on the BTS */
188 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100189 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100190}
191
192/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200193type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100194 port L1CTL_PT L1CTL;
195
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700196 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700197 port TRXC_CODEC_PT BTS_TRXC;
198 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100199
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200200 /* port to be initialized optionally to access BSC VTY */
201 port TELNETasp_PT BSCVTY;
202
Harald Welte70767382018-02-21 12:16:40 +0100203 timer g_Tguard;
204 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
205
206 var ConnHdlrPars g_pars;
207 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100208 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200209
210 /* PCU Interface of BTS */
211 port PCUIF_CODEC_PT PCU;
Vadim Yanitskiydd228c42021-07-04 02:37:30 +0200212
213 var RTP_Emulation_CT vc_RTPEM;
214 port RTPEM_CTRL_PT RTPEM_CTRL;
215 port RTPEM_DATA_PT RTPEM_DATA;
Harald Welte70767382018-02-21 12:16:40 +0100216}
217
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700218private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700219 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200220 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700221 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200222 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700223 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200224 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700225 timer T;
226
Harald Welte70767382018-02-21 12:16:40 +0100227 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
228 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
229
230 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
231 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
232 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
233
234 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
235 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700236
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700237 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700238 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700239 T.start(mp_ipa_up_timeout);
240 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700241 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700242 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
243 /* Make sure that all transceivers use unique stream ID */
244 if (trx_mask[enum2int(ev.sid)] == '1'B) {
245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
246 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
247 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700248
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700249 trx_mask[enum2int(ev.sid)] := '1'B;
250 trx_count := trx_count + 1;
251
252 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200253 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700254 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200255 /* This message (RF RESource INDication) is sent by the IUT itself */
256 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
257 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
259 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
260 }
261 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
263 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
264 }
265
266 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
267 rfind_count := rfind_count + 1;
268 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
269 if (rfind_count < mp_transceiver_num) { repeat; }
270 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700271 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
272 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
273 [] T.timeout {
274 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
275 "Timeout waiting for RSL bring up");
276 }
277 }
Harald Welte70767382018-02-21 12:16:40 +0100278}
279
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700280friend type record length(1 .. 256) of TrxParsItem TrxPars;
281friend type record TrxParsItem {
282 GsmArfcn arfcn,
283 TrxTsPars ts
284};
285
286friend type record length(8) of TrxTsParsItem TrxTsPars;
287friend type record TrxTsParsItem {
288 PchanConfig config
289};
290
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700291friend type record FreqHopPars {
292 /* Whether frequency hopping is in use */
293 boolean enabled,
294 /* Mobile Allocation Index Offset / Hopping Sequence Number */
295 MaioHsn maio_hsn,
296 /* MA bitmap to be indicated in RR Immediate Assignment */
297 MobileAllocationLV ma_map,
298 /* The actual Mobile Allocation (ARFCN list) to be used */
299 L1ctlMA ma
300};
301
Harald Welte70767382018-02-21 12:16:40 +0100302type record ConnHdlrPars {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700303 uint8_t trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100304 RslChannelNr chan_nr,
305 RSL_IE_ChannelMode chan_mode,
306 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100307 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200308 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200309 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700310 BtsBand bts0_band optional,
311
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700312 /* Training Sequence Code */
313 GsmTsc tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700314 /* Frequency hopping parameters */
315 FreqHopPars fhp
316};
Harald Welte0472ab42018-03-12 15:02:26 +0100317
318/* Test-specific parameters */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +0200319friend type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100320 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100321}
322
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700323private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100324 max_retrans := RACH_MAX_RETRANS_7,
325 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100326 cell_barr_access := false,
327 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100328 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100329};
330
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700331private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100332 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200333 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100334 acs := '0'B,
335 neci := true,
336 rxlev_access_min := 0
337}
338
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700339private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100340 mcc_mnc := '262F42'H,
341 lac := 42
342}
343
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700344private template (value) GPRSIndicator ts_GPRSIndicator_def := {
345 ra_colour := 0,
346 si13_pos := '0'B
347}
348
349private template (value) SI3RestOctets ts_SI3RestOctets_def
350modifies ts_SI3RestOctets := {
351 gprs_ind := {
352 presence := CSN1_H,
353 ind := ts_GPRSIndicator_def
354 }
355}
356
357private template (value) SI4RestOctets ts_SI4RestOctets_def
358modifies ts_SI4RestOctets := {
359 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700360 presence := CSN1_H,
361 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700362 }
363}
364
Harald Welte7484fc42018-02-24 14:09:45 +0100365/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700366private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100367 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100368 payload := {
369 si3 := {
370 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100371 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100372 ctrl_chan_desc := {
373 msc_r99 := true,
374 att := true,
375 bs_ag_blks_res := 1,
376 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100377 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100378 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
379 spare := '00'B,
380 bs_pa_mfrms := 0, /* 2 multiframes */
381 t3212 := 1 /* 6 minutes */
382 },
Harald Welte82ccef72018-02-25 16:17:33 +0100383 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100384 dn_ind := false,
385 pwrc := false,
386 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100387 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100388 },
Harald Weltef10153f2018-02-25 16:34:05 +0100389 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100390 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200391 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100392 }
393 }
394}
Harald Welte70767382018-02-21 12:16:40 +0100395
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700396private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100397 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100398 payload := {
399 si2 := {
400 bcch_freq_list := '00000000000000000000000000000000'O,
401 ncc_permitted := '11111111'B,
402 rach_control := ts_RachCtrl_default
403 }
404 }
405}
406
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700407private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100408 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100409 payload := {
410 si4 := {
411 lai := ts_LAI_default,
412 cell_sel_par := ts_CellSelPar_default,
413 rach_control := ts_RachCtrl_default,
414 cbch_chan_desc := omit,
415 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200416 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100417 }
418 }
419}
420
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700421private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100422runs on test_CT {
423 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700424 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100425}
426
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700427private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100428runs on test_CT {
429 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
430 log("Setting ", rsl_si_type, ": ", si_dec);
431 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
432}
433
Harald Welte505cf9b2018-09-15 17:47:23 +0300434friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100435 map(self:BTSVTY, system:BTSVTY);
436 f_vty_set_prompts(BTSVTY);
437 f_vty_transceive(BTSVTY, "enable");
438}
439
Harald Welte505cf9b2018-09-15 17:47:23 +0300440friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200441 map(self:BSCVTY, system:BSCVTY);
442 f_vty_set_prompts(BSCVTY, "OsmoBSC");
443 f_vty_transceive(BSCVTY, "enable");
444}
445
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200446friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
447 map(self:BSCVTY, system:BSCVTY);
448 f_vty_set_prompts(BSCVTY, "OsmoBSC");
449 f_vty_transceive(BSCVTY, "enable");
450}
451
Harald Welte883340c2018-02-28 18:59:29 +0100452/* PCU socket may at any time receive a new INFO.ind */
Pau Espin Pedrol65d712e2021-06-25 13:55:38 +0200453friend altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
Harald Weltef26de0b2018-04-04 20:28:05 +0200454 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100455 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200456 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
457 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100458 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200459 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100461 }
462}
463
Harald Weltef26de0b2018-04-04 20:28:05 +0200464private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
465 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100466 timer T := 2.0;
467 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100468 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200469 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100470 return;
471 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200472 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100473
474 T.start;
475 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200476 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100477 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200478 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100479 }
480 }
481}
482
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700483private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
484 out integer trxc_conn_id) {
485 var Result res;
486
487 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
488 "", -1, -1, { udp := {} }, {});
489 if (not ispresent(res.connId)) {
490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
491 "Could not connect to the control (TRXC) interface " &
492 "of FakeTRX, check your configuration");
493 }
494 trxc_conn_id := res.connId;
495}
496
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100497/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700498friend function f_init(uint8_t trx_nr := 0)
499runs on test_CT
500{
501 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200502 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100503
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700504 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
505 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700506 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200507 g_AllChanTypes := {
508 /* TS 1..4: TCH/F */
509 valueof(ts_RslChanNr_Bm(1)),
510 /* TS 5: TCH/H */
511 valueof(ts_RslChanNr_Lm(5,1)),
512 /* TS 0: SDCCH/4 */
513 valueof(ts_RslChanNr_SDCCH4(0,2)),
514 /* TS 6: SDCCH/8 */
515 valueof(ts_RslChanNr_SDCCH8(6,4))
516 };
517 } else {
518 g_AllChanTypes := {
519 /* TS 1..4: TCH/F */
520 valueof(ts_RslChanNr_Bm(1)),
521 /* TS 0: SDCCH/4 */
522 valueof(ts_RslChanNr_SDCCH4(0,2)),
523 /* TS 6: SDCCH/8 */
524 valueof(ts_RslChanNr_SDCCH8(6,4))
525 };
526 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700527
528 g_AllChannels := { };
529
530 /* Generate list of all logical channels from module parameters */
531 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
532 select (trx_pars.ts[tn].config) {
533 case (GSM_PCHAN_CCCH_SDCCH4) {
534 g_AllChannels := g_AllChannels &
535 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
536 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
537 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
538 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
539 }
540 case (GSM_PCHAN_SDCCH8) {
541 g_AllChannels := g_AllChannels &
542 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
543 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
544 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
545 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
546 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
547 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
548 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
549 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
550 }
551 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
552 g_AllChannels := g_AllChannels &
553 { valueof(ts_RslChanNr_Lm(tn, 0)),
554 valueof(ts_RslChanNr_Lm(tn, 1)),
555 valueof(ts_RslChanNr_Bm(tn)) };
556 }
557 case (GSM_PCHAN_TCHH) {
558 g_AllChannels := g_AllChannels &
559 { valueof(ts_RslChanNr_Lm(tn, 0)),
560 valueof(ts_RslChanNr_Lm(tn, 1)) };
561 }
562 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
563 g_AllChannels := g_AllChannels &
564 { valueof(ts_RslChanNr_Bm(tn)) };
565 }
566 }
567 }
568
Harald Welte70767382018-02-21 12:16:40 +0100569 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100570 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100571 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100572 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100573
574 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100575 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
576 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
577 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
578 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100579
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700580 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100581 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700582
583 /* Init TRXC interface to FakeTRX */
584 map(self:BTS_TRXC, system:BTS_TRXC);
585 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
586
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700587 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600588 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(2*256));
589 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(-60));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700590 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600591 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(60));
Harald Welte84271622018-03-10 17:21:03 +0100592 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200593
594 /* Wait some extra time to make sure the BTS emits a stable carrier.
595 * (this is only relevant when running the tests with a physical BTS.) */
596 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100597}
598
Harald Welte68e495b2018-02-25 00:05:57 +0100599/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700600friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100601 map(self:L1CTL, system:L1CTL);
602 f_connect_reset(L1CTL);
603}
604
Vadim Yanitskiy73878132021-05-05 02:22:45 +0200605friend type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100606
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700607private type record length(8) of FreqHopGroups FreqHopConfig;
608
609private type record of FreqHopGroup FreqHopGroups;
610private type record FreqHopGroup {
611 uint6_t hsn,
612 FreqHopGroupItems trx_maio
613};
614
615private type record of FreqHopGroupItem FreqHopGroupItems;
616private type record FreqHopGroupItem {
617 uint8_t trx_nr,
618 uint6_t maio
619};
620
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700621friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
622 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700623{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700624 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700625 var integer i, j;
626
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700627 fhp.enabled := false;
628
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700629 for (i := 0; i < lengthof(groups); i := i + 1) {
630 var FreqHopGroup g := groups[i];
631 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
632 var FreqHopGroupItem gi := g.trx_maio[j];
633 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700634 fhp.maio_hsn.maio := gi.maio;
635 fhp.maio_hsn.hsn := g.hsn;
636 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700637 break;
638 }
639 }
640
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700641 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700642 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700643 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
644 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
645 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700646
647 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700648 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
649 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700650 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700651 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700652 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700653 }
654
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700655 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700656 break; /* We're done */
657 }
658 }
659}
660
Harald Welte70767382018-02-21 12:16:40 +0100661/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700662friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
663 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200664 boolean trxc_comp := false,
665 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100666runs on test_CT return ConnHdlr {
667 var charstring id := testcasename();
668 var ConnHdlr vc_conn;
669
670 vc_conn := ConnHdlr.create(id);
671 /* connect to RSL Emulation main component */
672 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
673 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700674
675 /* The ConnHdlr component may want to talk to some ports directly,
676 * so we disconnect it from the test_CT and connect it to the component.
677 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200678 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200679 unmap(self:PCU, system:PCU);
680 map(vc_conn:PCU, system:PCU);
681 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700682 if (trxc_comp) {
683 unmap(self:BTS_TRXC, system:BTS_TRXC);
684 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
685 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200686 if (l1ctl) {
687 map(vc_conn:L1CTL, system:L1CTL);
688 }
Harald Welte70767382018-02-21 12:16:40 +0100689
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700690 /* Obtain frequency hopping parameters for a given timeslot */
691 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700692 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700693 }
694
Harald Welte70767382018-02-21 12:16:40 +0100695 vc_conn.start(f_handler_init(fn, id, pars));
696 return vc_conn;
697}
698
Harald Welte70767382018-02-21 12:16:40 +0100699private altstep as_Tguard() runs on ConnHdlr {
700 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200701 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100702 }
703}
704
Harald Welte990a3612019-05-27 14:02:13 +0200705friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700706 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700707 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100708}
709
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700710private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100711 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600712 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_RSSI(rssi));
Harald Welte70767382018-02-21 12:16:40 +0100713}
714
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700715private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100716 var TrxcMessage ret;
Vadim Yanitskiy418066a2021-10-03 14:04:17 +0600717 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte70767382018-02-21 12:16:40 +0100718}
719
720/* first function started in ConnHdlr component */
721private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
722runs on ConnHdlr {
723 g_pars := pars;
724 g_chan_nr := pars.chan_nr;
725
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200726 if (L1CTL.checkstate("Mapped")) {
727 f_connect_reset(L1CTL);
728 }
Harald Welte70767382018-02-21 12:16:40 +0100729
Harald Welted48c0c72019-06-05 10:01:15 +0200730 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700731 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100732 }
Harald Welte70767382018-02-21 12:16:40 +0100733
734 g_Tguard.start(pars.t_guard);
735 activate(as_Tguard());
736
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700737 f_rslem_register(pars.trx_nr, pars.chan_nr);
Harald Welte70767382018-02-21 12:16:40 +0100738
739 /* call the user-supplied test case function */
740 fn.apply(id);
741}
742
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700743private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
744 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200745runs on ConnHdlr return RSL_Message {
746 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100747 timer T := 3.0;
748 RSL.send(tx);
749 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100750 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200751 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100752 T.stop;
753 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100754 }
Harald Welte1eba3742018-02-25 12:48:14 +0100755 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200756 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100757 }
Harald Welte21240e62018-03-11 21:43:35 +0100758 [not ignore_other] as_l1_sacch();
759 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700760 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700761 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100762 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100764 }
Harald Welte21240e62018-03-11 21:43:35 +0100765 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100766 }
Harald Welteb1726c92018-03-30 11:56:38 +0200767 return rx;
768}
769
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700770friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
771 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200772runs on ConnHdlr {
773 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100774}
775
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700776friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
777 boolean encr_enable := false,
778 RSL_IE_List more_ies := {},
779 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
780runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200781 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200782 if (encr_enable) {
783 /* append encryption related IEs, if requested */
784 var RSL_IE_EncryptionInfo encr_info;
785 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
786 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
787encr_info})) };
788 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200789 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200790 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100791}
792
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700793friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100794 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100795 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100796}
797
Harald Welte2f2b2b72019-05-31 22:24:57 +0200798friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200799 template RSL_IE_ChannelMode chan_mode,
800 template (omit) TestSpecUnion spec := omit,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +0700801 uint8_t trx_nr := 0, float t_guard := 20.0) := {
802 trx_nr := trx_nr,
Harald Welte70767382018-02-21 12:16:40 +0100803 chan_nr := valueof(chan_nr),
804 chan_mode := valueof(chan_mode),
805 t_guard := t_guard,
806 l1_pars := {
807 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100808 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100809 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100810 meas_ul := {
811 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200812 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100813 rxqual := 0
814 },
815 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200816 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100817 rxqual := 0
818 }
819 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200820 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100821 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200822 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200823 ms_actual_ta := mp_ms_actual_ta_exp,
824 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100825 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200826 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200827 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700828 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700829 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700830 fhp := {
831 enabled := false,
832 maio_hsn := ts_HsnMaio(0, 0),
833 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700834 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700835 }
Harald Welte70767382018-02-21 12:16:40 +0100836}
837
Harald Welte93640c62018-02-25 16:59:33 +0100838/***********************************************************************
839 * Channel Activation / Deactivation
840 ***********************************************************************/
841
Harald Welte70767382018-02-21 12:16:40 +0100842/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700843private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100844 for (var integer i := 0; i < 500; i := i+1) {
845 f_rsl_chan_act(g_pars.chan_mode);
846 f_rsl_chan_deact();
847 }
848 setverdict(pass);
849}
850testcase TC_chan_act_stress() runs on test_CT {
851 var ConnHdlr vc_conn;
852 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200853 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100854 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
855 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100857}
858
859/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700860private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100861 f_rsl_chan_act(g_pars.chan_mode);
862 /* attempt to activate the same lchan again -> expect reject */
863 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
864 alt {
865 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200866 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100867 }
868 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
869 setverdict(pass);
870 }
871 }
872 f_rsl_chan_deact();
873}
874testcase TC_chan_act_react() runs on test_CT {
875 var ConnHdlr vc_conn;
876 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100877 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100878 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
879 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100881}
882
883/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700884private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100885 timer T := 3.0;
886 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
887 T.start;
888 alt {
889 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
890 setverdict(pass);
891 }
892 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100894 }
895 }
896}
897testcase TC_chan_deact_not_active() runs on test_CT {
898 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100899 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100900 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
901 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200902 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100903}
904
905/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700906private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100907 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
908 alt {
909 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100911 }
912 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
913 setverdict(pass);
914 }
915 }
916}
917private type record WrongChanNrCase {
918 RslChannelNr chan_nr,
919 charstring description
920}
921private type record of WrongChanNrCase WrongChanNrCases;
922private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
923 chan_nr := chan_nr,
924 description := desc
925}
926
927testcase TC_chan_act_wrong_nr() runs on test_CT {
928 var ConnHdlr vc_conn;
929 var ConnHdlrPars pars;
930
Harald Welte294b0a22018-03-10 23:26:48 +0100931 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100932
933 var WrongChanNrCases wrong := {
934 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
935 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
936 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
937 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
938 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
939 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
940 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
941 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
942 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
943 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
944 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
945 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
946 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
947 };
948
949 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
950 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
951 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
952 vc_conn.done;
953 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100955}
956
Harald Weltee613f962018-04-18 22:38:16 +0200957/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200958friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200959 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200960 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200961
962 /* test on each of the channels we have */
963 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
964 pars.chan_nr := valueof(g_AllChanTypes[i]);
965
966 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
967 vc_conn := f_start_handler(fn, pars);
968 vc_conn.done;
969 }
970
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200971 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200972}
973
Harald Welte93640c62018-02-25 16:59:33 +0100974/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100975 * SACCH handling
976 ***********************************************************************/
977
978private function f_exp_sacch(boolean exp) runs on ConnHdlr {
979 timer T_sacch := 3.0;
980 T_sacch.start;
981 alt {
982 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100984 }
985 [not exp] T_sacch.timeout {
986 setverdict(pass);
987 }
988 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
989 setverdict(pass);
990 }
991 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100993 }
994 [] L1CTL.receive { repeat; }
995 [] RSL.receive { repeat; }
996 }
997}
998
999/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
1000private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
1001 f_l1_tune(L1CTL);
1002 RSL.clear;
1003
1004 /* activate the logical channel */
1005 f_est_dchan();
1006 L1CTL.clear;
1007
1008 /* check that SACCH actually are received as expected */
1009 f_exp_sacch(true);
1010
1011 /* deactivate SACCH on the logical channel */
1012 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1013 f_sleep(1.0);
1014 L1CTL.clear;
1015
1016 /* check that no SACCH are received anymore */
1017 f_exp_sacch(false);
1018
1019 /* release the channel */
1020 f_rsl_chan_deact();
1021 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1022}
1023testcase TC_deact_sacch() runs on test_CT {
1024 var ConnHdlr vc_conn;
1025 var ConnHdlrPars pars;
1026 f_init();
1027 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1028 //for (var integer i := 0; i < 1; i := i+1) {
1029 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1030 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1031 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1032 vc_conn.done;
1033 }
1034 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001035 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001036}
1037
Harald Welte55700662018-03-12 13:15:43 +01001038/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +01001039private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
1040 var L1ctlDlMessage dl;
1041 /* check that the specified SI5 value is actually sent */
1042 timer T_sacch := 3.0;
1043 L1CTL.clear;
1044 T_sacch.start;
1045 alt {
1046 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1047 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1048 if (match(l3, l3_exp)) {
1049 setverdict(pass);
1050 } else {
1051 repeat;
1052 }
1053 }
1054 [] L1CTL.receive { repeat; }
1055 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +01001057 }
1058 }
1059}
1060
Harald Welte55700662018-03-12 13:15:43 +01001061/* verify that given SACCH payload is not present */
1062private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1063 var L1ctlDlMessage dl;
1064 /* check that the specified SI5 value is actually sent */
1065 timer T_sacch := 3.0;
1066 L1CTL.clear;
1067 T_sacch.start;
1068 alt {
1069 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1070 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1071 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001073 } else {
1074 repeat;
1075 }
1076 }
1077 [] L1CTL.receive { repeat; }
1078 [] T_sacch.timeout {
1079 setverdict(pass);
1080 }
1081 }
1082}
1083
Harald Welte629cc6b2018-03-11 17:19:05 +01001084/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001085private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1086 /* Set a known default SACCH filling for SI5 */
1087 var octetstring si5 := f_rnd_octstring(19);
1088 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1089
1090 f_l1_tune(L1CTL);
1091 RSL.clear;
1092
1093 /* activate the logical channel */
1094 f_est_dchan();
1095
1096 /* check that the specified SI5 value is actually sent */
1097 f_sacch_present(si5);
1098
1099 /* release the channel */
1100 RSL.clear;
1101 f_rsl_chan_deact();
1102 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1103}
1104testcase TC_sacch_filling() runs on test_CT {
1105 var ConnHdlr vc_conn;
1106 var ConnHdlrPars pars;
1107 f_init();
1108 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1109 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1110 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1111 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1112 vc_conn.done;
1113 }
1114 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001116}
1117
Harald Welte629cc6b2018-03-11 17:19:05 +01001118/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001119private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1120 /* Set a known default SACCH filling for SI5 */
1121 var octetstring si5 := f_rnd_octstring(19);
1122 var octetstring si5_diff := f_rnd_octstring(19);
1123 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1124
1125 f_l1_tune(L1CTL);
1126 RSL.clear;
1127
1128 log("Activating channel, expecting standard SI5");
1129 /* activate the logical channel */
1130 f_est_dchan();
1131 /* check that the specified SI5 value is actually sent */
1132 f_sacch_present(si5);
1133
1134 /* set channel-specific different SI5 */
1135 log("Setting channel specific SACCH INFO, expecting it");
1136 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1137 /* check that the specified lchan-specific value is now used */
1138 f_sacch_present(si5_diff);
1139
1140 /* deactivate the channel and re-activate it, this should result in default SI5 */
1141 log("De-activating and re-activating channel, expecting standard SI5");
1142 f_rsl_chan_deact();
1143 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1144 /* Verify that the TRX-wide default SACCH filling is present again */
1145 f_sacch_present(si5);
1146
1147 /* release the channel */
1148 RSL.clear;
1149 f_rsl_chan_deact();
1150 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1151}
1152testcase TC_sacch_info_mod() runs on test_CT {
1153 var ConnHdlr vc_conn;
1154 var ConnHdlrPars pars;
1155 f_init();
1156 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1157 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1158 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1159 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1160 vc_conn.done;
1161 }
1162 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001163 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001164}
1165
Harald Welte075d84c2018-03-12 13:07:24 +01001166/* Test SACCH scheduling of multiple different SI message types */
1167private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1168 var octetstring si5 := f_rnd_octstring(19);
1169 var octetstring si5bis := f_rnd_octstring(19);
1170 var octetstring si5ter := f_rnd_octstring(19);
1171 var octetstring si6 := f_rnd_octstring(19);
1172
1173 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1174 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1175 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1176 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1177
1178 f_l1_tune(L1CTL);
1179 RSL.clear;
1180
1181 /* activate the logical channel */
1182 f_est_dchan();
1183 L1CTL.clear;
1184
1185 /* check that SACCH actually are received as expected */
1186 f_sacch_present(si5);
1187 f_sacch_present(si5bis);
1188 f_sacch_present(si5ter);
1189 f_sacch_present(si6);
1190
1191 /* release the channel */
1192 f_rsl_chan_deact();
1193 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1194}
1195testcase TC_sacch_multi() runs on test_CT {
1196 var ConnHdlr vc_conn;
1197 var ConnHdlrPars pars;
1198 f_init();
1199 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1200 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1201 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1202 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1203 vc_conn.done;
1204 }
1205 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001207}
1208
Harald Welte55700662018-03-12 13:15:43 +01001209/* Test if SACH information is modified as expected */
1210private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1211 var octetstring si5 := f_rnd_octstring(19);
1212 var octetstring si6 := f_rnd_octstring(19);
1213
1214 /* First, configure both SI5 and SI6 to be transmitted */
1215 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1216 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1217
1218 f_l1_tune(L1CTL);
1219 RSL.clear;
1220
1221 /* activate the logical channel */
1222 f_est_dchan();
1223 L1CTL.clear;
1224
1225 /* check that SACCH actually are received as expected */
1226 f_sacch_present(si5);
1227 f_sacch_present(si6);
1228
1229 /* disable SI6 */
1230 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1231
1232 /* check that SI5 is still transmitted */
1233 f_sacch_present(si5);
1234 /* check if SI6 is now gone */
1235 f_sacch_missing(si6);
1236
1237 /* release the channel */
1238 f_rsl_chan_deact();
1239 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1240}
1241testcase TC_sacch_multi_chg() runs on test_CT {
1242 var ConnHdlr vc_conn;
1243 var ConnHdlrPars pars;
1244 f_init();
1245 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1246 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1247 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1248 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1249 vc_conn.done;
1250 }
1251 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001253}
1254
Harald Weltec8d363c2019-05-19 20:36:48 +02001255/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1256private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1257 var octetstring si5 := f_rnd_octstring(19);
1258 var octetstring si6 := f_rnd_octstring(19);
1259 var octetstring si5_specific := f_rnd_octstring(19);
1260 var octetstring si6_specific := f_rnd_octstring(19);
1261
1262 /* First, configure both SI5 and SI6 to be transmitted */
1263 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1264 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1265
1266 f_l1_tune(L1CTL);
1267 RSL.clear;
1268
1269 /* activate channel with different SACCH filling */
1270 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1271 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1272 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1273 }));
1274 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1275 RSL_IE_Body:{sacch_info := sacch_info})) };
1276 f_est_dchan(more_ies := addl_ies);
1277
1278 /* check that SACCH actually are received as expected */
1279 f_sacch_present(si5_specific);
1280 f_sacch_present(si6_specific);
1281
1282 /* release the channel */
1283 f_rsl_chan_deact();
1284 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1285}
1286testcase TC_sacch_chan_act() runs on test_CT {
1287 var ConnHdlr vc_conn;
1288 var ConnHdlrPars pars;
1289 f_init();
1290
1291 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1292 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1293 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1294 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1295 vc_conn.done;
1296 }
1297 /* TODO: do the above in parallel, rather than sequentially? */
1298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1299}
1300
Harald Welte8b01c792019-05-19 22:51:25 +02001301/* verify that SACCH DL transmission is started only if MS power IE present
1302 * see section 4.1.3 of 3GPP TS 48.058 */
1303private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1304 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001305 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001306
1307 f_l1_tune(L1CTL);
1308 RSL.clear;
1309
1310 /* Step 1: Activate ASYNC HO channel without MS power IE */
1311
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001312 var integer ho_ref := oct2int(f_rnd_octstring(1));
1313 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1314 RSL_IE_Body:{ handover_ref := ho_ref }));
1315 var RSL_IE_List addl_ies := {
1316 ho_ref_ie
1317 };
1318
Harald Welte8b01c792019-05-19 22:51:25 +02001319 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001320 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001321 /* don't perform immediate assignment here, as we're testing non-IA case */
1322 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001323 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001324
1325 /* Verify that no DL SACCH is being received */
1326 f_sacch_missing(?);
1327
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001328 /* Send handover Access Burst and expect SACCH to start */
1329 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1330
1331 f_sacch_present(si5);
1332
Harald Welte8b01c792019-05-19 22:51:25 +02001333 f_rsl_chan_deact();
1334 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1335
1336
1337 /* Step 2: Activate ASYNC HO channel with MS power IE */
1338
1339 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001340 addl_ies := {
1341 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001342 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1343 };
1344 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1345 /* don't perform immediate assignment here, as we're testing non-IA case */
1346 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001347 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001348
1349 /* Verify that DL SACCH is being received */
1350 f_sacch_present(si5);
1351
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001352 /* Send handover Access Burst and expect SACCH to remain present */
1353 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1354
1355 f_sacch_present(si5);
1356
Harald Welte8b01c792019-05-19 22:51:25 +02001357 f_rsl_chan_deact();
1358 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1359}
1360testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1361 var ConnHdlr vc_conn;
1362 var ConnHdlrPars pars;
1363 f_init();
1364
1365 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1366 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1367 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1368 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1369 vc_conn.done;
1370 }
1371 /* TODO: do the above in parallel, rather than sequentially? */
1372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1373}
1374
1375/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1376 * see section 4.1.4 of 3GPP TS 48.058 */
1377private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1378 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001379 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1380
Harald Welte8b01c792019-05-19 22:51:25 +02001381 var RSL_IE_List addl_ies;
1382
1383 f_l1_tune(L1CTL);
1384 RSL.clear;
1385
1386 /* Step 1: Activate SYNC HO channel without MS power IE */
1387
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001388 var integer ho_ref := oct2int(f_rnd_octstring(1));
1389 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1390 RSL_IE_Body:{ handover_ref := ho_ref }));
1391 addl_ies := {
1392 ho_ref_ie
1393 };
1394
Harald Welte8b01c792019-05-19 22:51:25 +02001395 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001396 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001397 /* don't perform immediate assignment here, as we're testing non-IA case */
1398 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001399 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001400
1401 /* Verify that no DL SACCH is being received */
1402 f_sacch_missing(?);
1403
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001404 /* Send handover Access Burst and expect SACCH to start */
1405 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1406
1407 f_sacch_present(si5);
1408
Harald Welte8b01c792019-05-19 22:51:25 +02001409 f_rsl_chan_deact();
1410 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1411
1412
1413 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1414
1415 /* Activate channel on BTS side */
1416 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001417 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001418 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1419 };
1420 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1421 /* don't perform immediate assignment here, as we're testing non-IA case */
1422 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001423 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001424
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001425 /* Verify that DL SACCH is being received, because MS Power IE was sent */
1426 f_sacch_present(si5);
Harald Welte8b01c792019-05-19 22:51:25 +02001427
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001428 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001429 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1430
1431 f_sacch_present(si5);
1432
Harald Welte8b01c792019-05-19 22:51:25 +02001433 f_rsl_chan_deact();
1434 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1435
1436
1437 /* Step 2b: Activate SYNC HO channel with TA IE */
1438
1439 /* Activate channel on BTS side */
1440 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001441 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001442 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1443 };
1444 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1445 /* don't perform immediate assignment here, as we're testing non-IA case */
1446 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001447 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001448
1449 /* Verify that no DL SACCH is being received */
1450 f_sacch_missing(?);
1451
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001452 /* Send handover Access Burst and expect SACCH to start */
1453 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1454
1455 f_sacch_present(si5);
1456
Harald Welte8b01c792019-05-19 22:51:25 +02001457 f_rsl_chan_deact();
1458 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1459
1460
1461 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1462
1463 /* Activate channel on BTS side */
1464 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001465 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001466 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1467 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1468 };
1469 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1470 /* don't perform immediate assignment here, as we're testing non-IA case */
1471 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001472 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001473
1474 /* Verify that DL SACCH is being received */
1475 f_sacch_present(si5);
1476
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001477 /* Send handover Access Burst and expect SACCH to remain present */
1478 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1479
1480 f_sacch_present(si5);
1481
Harald Welte8b01c792019-05-19 22:51:25 +02001482 f_rsl_chan_deact();
1483 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1484}
1485testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1486 var ConnHdlr vc_conn;
1487 var ConnHdlrPars pars;
1488 f_init();
1489
1490 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1491 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1492 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1493 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1494 vc_conn.done;
1495 }
1496 /* TODO: do the above in parallel, rather than sequentially? */
1497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1498}
Harald Welte629cc6b2018-03-11 17:19:05 +01001499
1500
1501/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001502 * RACH Handling
1503 ***********************************************************************/
1504
Harald Welte8c24c2b2018-02-26 08:31:31 +01001505/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001506private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001507 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001508 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001509 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001510
Harald Welte8c24c2b2018-02-26 08:31:31 +01001511 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001512 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001513 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001514 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001515 if (emerg == true) {
1516 ra := f_rnd_ra_emerg();
1517 } else {
1518 ra := f_rnd_ra_cs();
1519 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001520 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1521 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001523 }
1524 fn_last := fn;
1525
1526 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001527 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001528 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001529 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001530 T.stop;
1531 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001532 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001533 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001534 }
1535 [] RSL_CCHAN.receive { repeat; }
1536 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001537 test_failed := true;
1538 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001539 }
1540 }
1541 }
Maxba06feb2019-03-05 10:52:46 +01001542 if (test_failed) {
1543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001544 }
Maxba06feb2019-03-05 10:52:46 +01001545 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001546 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001547}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001548
Philipp Maier16ade782020-07-08 21:36:00 +02001549/* Normal variant */
1550testcase TC_rach_content() runs on test_CT {
1551 f_TC_rach_content(emerg := false);
1552}
1553
1554/* Emergency call variant */
1555testcase TC_rach_content_emerg() runs on test_CT {
1556 f_TC_rach_content(emerg := true);
1557}
1558
Harald Welte8c24c2b2018-02-26 08:31:31 +01001559/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1560testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001561 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001562 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001563 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001564 f_l1_tune(L1CTL);
1565
1566 var GsmFrameNumber fn_last := 0;
1567 for (var integer i := 0; i < 1000; i := i+1) {
1568 var OCT1 ra := f_rnd_ra_cs();
1569 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1570 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001572 }
1573 fn_last := fn;
1574 }
1575 var integer rsl_chrqd := 0;
1576 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001577 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001578 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001579 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001580 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001581 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001582 repeat;
1583 }
1584 [] RSL_CCHAN.receive { repeat; }
1585 [] T.timeout { }
1586 }
1587 if (rsl_chrqd == 1000) {
1588 setverdict(pass);
1589 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001591 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001593}
1594
Harald Welte3453ab42019-05-24 21:19:58 +02001595private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1596 var charstring bts_str := "bts " & int2str(bts_nr);
1597 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1598}
1599
1600/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1601private template integer tr_rach_slots_per_interval := (90 .. 130);
1602
1603/* Expect 0 RACH load on an idle BTS that has just started up */
1604testcase TC_rach_load_idle_thresh0() runs on test_CT {
1605 var ASP_RSL_Unitdata rx_ud;
1606
1607 f_init_vty_bsc();
1608 /* send load indications even at 0% load */
1609 f_vty_load_ind_thresh(0);
1610 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1611 f_sleep(2.0);
1612
1613 f_init();
1614
Harald Weltee37f9a52020-10-11 20:45:23 +02001615 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1616 alt {
1617 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1618 [] RSL_CCHAN.receive { repeat }
1619 }
1620
Harald Welte3453ab42019-05-24 21:19:58 +02001621 timer T := 5.0;
1622 T.start;
1623 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001624 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
Harald Welte3453ab42019-05-24 21:19:58 +02001625 setverdict(pass);
1626 repeat;
1627 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001628 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001629 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1630 repeat;
1631 }
1632 [] RSL_CCHAN.receive {
1633 repeat;
1634 }
1635 [] T.timeout { }
1636 }
1637
1638 f_vty_load_ind_thresh(10);
1639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1640}
1641
1642/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1643testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1644 var ASP_RSL_Unitdata rx_ud;
1645
1646 f_init_vty_bsc();
1647 f_init();
1648
1649 timer T := 5.0;
1650 T.start;
1651 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001652 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001653 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1654 repeat;
1655 }
1656 [] RSL_CCHAN.receive {
1657 repeat;
1658 }
1659 [] T.timeout {
1660 setverdict(pass);
1661 }
1662 }
1663
1664 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1665}
1666
1667/* Expect 0 RACH load on an idle BTS that has just started up */
1668testcase TC_rach_load_count() runs on test_CT {
1669 var ASP_RSL_Unitdata rx_ud;
1670 var integer load_access_count := 0;
1671
1672 f_init_vty_bsc();
1673 /* send load indications even at 0% load */
1674 f_vty_load_ind_thresh(0);
1675 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1676 f_sleep(2.0);
1677 f_init();
1678
1679 f_init_l1ctl();
1680 f_sleep(1.0);
1681 f_l1_tune(L1CTL);
1682
Harald Welte52ae1682020-10-11 20:45:55 +02001683 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1684 alt {
1685 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1686 [] RSL_CCHAN.receive { repeat }
1687 }
1688
Harald Welte3453ab42019-05-24 21:19:58 +02001689 var GsmFrameNumber fn_last := 0;
1690 for (var integer i := 0; i < 1000; i := i+1) {
1691 var OCT1 ra := f_rnd_ra_cs();
1692 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1693 if (fn == fn_last) {
1694 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1695 }
1696 fn_last := fn;
1697 }
1698
1699 timer T := 5.0;
1700 T.start;
1701 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001702 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001703 -> value rx_ud {
1704 var RSL_IE_Body ie;
1705 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1706 load_access_count := load_access_count + ie.rach_load.access_count;
1707 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1708 setverdict(fail, "Access count cannot be < Busy count");
1709 }
1710 repeat;
1711 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001712 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001713 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1714 repeat;
1715 }
1716 [] RSL_CCHAN.receive {
1717 repeat;
1718 }
1719 [] T.timeout { }
1720 }
1721 if (load_access_count == 1000) {
1722 setverdict(pass);
1723 } else {
1724 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1725 }
1726
1727 f_vty_load_ind_thresh(10);
1728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1729}
1730
Harald Welte54a2a2d2018-02-26 09:14:05 +01001731private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001732 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001733 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06001734 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_TIMING(toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001735 f_sleep(0.5);
1736
1737 /* Transmit RACH request + wait for confirmation */
1738 var OCT1 ra := f_rnd_ra_cs();
1739 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1740
1741 /* Check for expected result */
1742 timer T := 1.5;
1743 T.start;
1744 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001745 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001746 setverdict(pass);
1747 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001748 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001750 }
1751 [] RSL_CCHAN.receive { repeat; }
1752 [not expect_pass] T.timeout {
1753 setverdict(pass);
1754 }
1755 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001756 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001757 }
1758 }
1759}
1760
1761/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1762testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001763 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001764 f_init_l1ctl();
1765 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001766 f_sleep(1.0);
1767
1768 /* default max-ta is 63 (full range of GSM timing advance */
1769
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001770 /* We allow early arrival up to 2 symbols */
1771 f_rach_toffs(-1*256, true);
1772 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001773 f_rach_toffs(-10*256, false);
1774
1775 /* 0 / 32 / 63 bits is legal / permitted */
1776 f_rach_toffs(0, true);
1777 f_rach_toffs(32*256, true);
1778 f_rach_toffs(63*256, true);
1779
1780 /* more than 63 bits is not legal / permitted */
1781 f_rach_toffs(64*256, false);
1782 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001783 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001784}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001785
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001786private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001787 var GsmFrameNumber fn;
1788 var RSL_Message rm;
1789
1790 f_l1_tune(L1CTL);
1791 RSL.clear;
1792
1793 /* Generate a random Handover Reference */
1794 var integer ho_ref := oct2int(f_rnd_octstring(1));
1795
1796 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1797 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1798 RSL_IE_Body:{ handover_ref := ho_ref }));
1799
1800 /* Activate a channel on the BTS side (no encryption) */
1801 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1802 act_type := t_RSL_IE_ActType_HO_SYNC);
1803
1804 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1805 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001806 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001807
1808 /* Send handover Access Burst */
1809 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1810
1811 /* TODO: test mismatching Handover Reference, and missing IE */
1812
1813 /* Wait for handover detection */
1814 timer T := 3.0;
1815 T.start;
1816 alt {
1817 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1818 log("Handover RACH has been detected: ", rm);
1819 setverdict(pass);
1820 }
1821 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1823 log2str("RSL_CHAN_RQD was not expected: ", rm));
1824 }
1825 [] RSL.receive { repeat; }
1826 [] T.timeout {
1827 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1828 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1829 }
1830 }
1831
1832 /* Release the channel */
1833 f_rsl_chan_deact();
1834 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1835}
1836
1837/* Test handover RACH detection */
1838testcase TC_ho_rach() runs on test_CT {
1839 var ConnHdlrPars pars;
1840 var ConnHdlr vc_conn;
1841
1842 f_init();
1843
1844 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1845 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1846 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1847 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1848 vc_conn.done;
1849 }
1850
1851 /* TODO: do the above in parallel, rather than sequentially? */
1852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1853}
1854
Harald Welte93640c62018-02-25 16:59:33 +01001855/***********************************************************************
1856 * Measurement Processing / Reporting
1857 ***********************************************************************/
1858
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001859private template (value) LapdmAddressField
1860ts_LapdmAddr(template (value) LapdmSapi sapi,
1861 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001862 spare := '0'B,
1863 lpd := 0,
1864 sapi := sapi,
1865 c_r := c_r,
1866 ea := true
1867}
1868
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001869private template (value) LapdmFrameAB
1870ts_LAPDm_AB(template (value) LapdmSapi sapi,
1871 template (value) GsmRrL3Message l3,
1872 template (value) boolean c_r := false,
1873 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01001874 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001875 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01001876 len := 0, /* overwritten */
1877 m := false,
1878 el := 1,
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001879 payload := enc_GsmRrL3Message(valueof(l3))
Harald Welte70767382018-02-21 12:16:40 +01001880}
1881
1882/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001883private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001884 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01001885 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001886
Harald Weltef8df4cb2018-03-10 15:15:08 +01001887 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001888 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001889
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001890 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07001891 g_pars.l1_pars.meas_ul.full.rxlev,
1892 g_pars.l1_pars.meas_ul.sub.rxlev,
1893 g_pars.l1_pars.meas_ul.full.rxqual,
1894 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01001895 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001896
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001897 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1898 g_pars.l1_pars.ms_power_level, false,
1899 g_pars.l1_pars.ms_actual_ta);
1900
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01001901 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
1902 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001903
1904 log("Sending Measurement Report: ", l1h, l2);
1905 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001906 repeat;
1907 }
1908}
1909
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07001910/* handle incoming downlink SACCH, decode the L1 header into the given record */
1911private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
1912 boolean do_apply := true)
1913runs on ConnHdlr
1914{
1915 var L1ctlDlMessage l1_dl;
1916
1917 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1918 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
1919 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
1920 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
1921
1922 if (do_apply) {
1923 /* Update TA and MS power to follow what BTS requests */
1924 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
1925 }
1926 }
1927}
1928
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001929private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001930 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001931 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001932 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1933 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001934 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1935 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001936 repeat;
1937 }
1938}
1939
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001940private altstep as_l1_tch_loop() runs on ConnHdlr {
1941 var L1ctlDlMessage l1_dl;
1942 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1943 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001944
1945 /* occasionaly inject FACCH frames into the uplink */
1946 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1947 var octetstring pl := '010301'O;
1948 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1949 f_pad_oct(pl, 23, '2B'O)));
1950 } else {
1951 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1952 l1_dl.payload.traffic_ind.data));
1953 }
1954
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001955 repeat;
1956 }
1957}
1958
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001959private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001960 uint6_t rxlev,
1961 uint3_t rxqual
1962}
1963
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001964private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001965 MeasElem full,
1966 MeasElem sub
1967}
1968
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001969private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001970 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001971 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001972 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01001973 MeasElemFS meas_ul,
1974 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001975 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001976 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02001977 uint8_t ms_actual_ta,
1978 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01001979}
1980
1981/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1982private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1983 return 63 + (toffs256s/256);
1984}
1985
Harald Welted5684392018-03-10 18:22:04 +01001986private function f_max(integer a, integer b) return integer {
1987 if (a > b) {
1988 return a;
1989 } else {
1990 return b;
1991 }
1992}
1993
1994private function f_min(integer a, integer b) return integer {
1995 if (a < b) {
1996 return a;
1997 } else {
1998 return b;
1999 }
2000}
2001
2002/* compute negative tolerance val-tolerance, ensure >= min */
2003private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
2004 val := val - tolerance;
2005 return f_max(val, min);
2006}
2007
2008/* compute positive tolerance val+tolerance, ensure <= max */
2009private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
2010 val := val + tolerance;
2011 return f_min(val, max);
2012}
2013
2014/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2015private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2016return template integer {
2017 var template integer ret;
2018 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2019 return ret;
2020}
2021
2022
Harald Welte70767382018-02-21 12:16:40 +01002023/* build a template for matching measurement results against */
2024private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2025 var ConnL1Pars l1p := g_pars.l1_pars;
2026 var template RSL_IE_UplinkMeas ul_meas := {
2027 len := 3,
2028 rfu := '0'B,
2029 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002030 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002031 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002032 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002033 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002034 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2035 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002036 supp_meas_info := omit
2037 };
Harald Welte685d5982018-02-27 20:42:05 +01002038 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002039 ul_meas.len := (3+8);
2040 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002041 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002042 toa256_min := ?,
2043 toa256_max := ?,
2044 toa256_std_dev := ?
2045 }
Harald Welte685d5982018-02-27 20:42:05 +01002046 }
Harald Welte70767382018-02-21 12:16:40 +01002047 var template RSL_IE_BS_Power bs_power := {
2048 reserved := 0,
2049 epc := false,
2050 fpc := false,
2051 power_level := l1p.bs_power_level
2052 };
2053 var template RSL_IE_L1Info l1_info := {
2054 ms_power_lvl := l1p.ms_power_level,
2055 fpc := false,
2056 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002057 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002058 };
2059 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002060 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002061 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2062 ?, t_toffs);
2063}
2064
Philipp Maierdd841d32019-12-17 14:44:54 +01002065/* build a template for matching measurement results that do not contain any
2066 * MS related measurement (l1_info, l3_info and ms timing offset). */
2067private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2068 var ConnL1Pars l1p := g_pars.l1_pars;
2069 var template RSL_IE_UplinkMeas ul_meas := {
2070 len := 3,
2071 rfu := '0'B,
2072 dtx_d := l1p.dtx_enabled,
2073 rxlev_f_u := ?,
2074 reserved1 := '00'B,
2075 rxlev_s_u := ?,
2076 reserved2 := '00'B,
2077 rxq_f_u := ?,
2078 rxq_s_u := ?,
2079 supp_meas_info := omit
2080 };
2081 if (l1p.toa256_enabled) {
2082 ul_meas.len := (3+8);
2083 ul_meas.supp_meas_info := {
2084 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2085 toa256_min := ?,
2086 toa256_max := ?,
2087 toa256_std_dev := ?
2088 }
2089 }
2090 var template RSL_IE_BS_Power bs_power := {
2091 reserved := 0,
2092 epc := false,
2093 fpc := false,
2094 power_level := l1p.bs_power_level
2095 };
2096
2097 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2098}
2099
Harald Welte70767382018-02-21 12:16:40 +01002100/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002101private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002102 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002103 var boolean chan_est := false;
2104
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002105 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002106
2107 /* Receive osmocom specific measurement reports. This is the normal
2108 * case. Here we verify that the measurement reports we sent are
2109 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002110 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2111 /* increment counter of next to-be-expected meas rep */
2112 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2113 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002114 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002115
2116 /* The following two cases may only happen in the beginning
2117 * of the channel establishment phase. Once we have received
2118 * the "our" measurement report the first time, the channel
2119 * is established and empty or hardcoded TRXCON reports must
2120 * not occur anymore. */
2121 chan_est := true;
2122
2123 repeat;
2124 }
2125
2126 /* When the BTS has established the channel, the MS might need slightly
2127 * more time to establish the channel and actually start sending. The
2128 * result is then a measurement report that just lacks the measurement
2129 * information of the MS. This is normal and we tolerate this behavior. */
2130 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2131 /* increment counter of next to-be-expected meas rep */
2132 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2133 /* Re-start the timer expecting the next MEAS RES */
2134 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002135 repeat;
2136 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002137
2138 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2139 * measurements if the TTCN3 side does not supply measurement input in
2140 * time. In those cases TRXCON will either use a cached measurement
2141 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2142 * report the templates above will not match. We tolerate this
2143 * behavior, but only once. */
2144 [chan_est == false] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01002145 /* increment counter of next to-be-expected meas rep */
2146 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2147 if (g_first_meas_res) {
2148 g_first_meas_res := false;
2149 repeat;
2150 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002152 }
Harald Welte70767382018-02-21 12:16:40 +01002153 }
2154 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002156 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002157 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002158 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002159 }
2160}
2161
Harald Weltee613f962018-04-18 22:38:16 +02002162private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2163 select (rsl_alg_id) {
2164 case (RSL_ALG_ID_A5_0) { return 0; }
2165 case (RSL_ALG_ID_A5_1) { return 1; }
2166 case (RSL_ALG_ID_A5_2) { return 2; }
2167 case (RSL_ALG_ID_A5_3) { return 3; }
2168 case (RSL_ALG_ID_A5_4) { return 4; }
2169 case (RSL_ALG_ID_A5_5) { return 5; }
2170 case (RSL_ALG_ID_A5_6) { return 6; }
2171 case (RSL_ALG_ID_A5_7) { return 7; }
2172 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2174 /* Make compiler happy by calling mtc.stop here. It is already
2175 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002176 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002177 }
2178 }
2179}
2180
2181private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2182 select (rsl_alg_id) {
2183 case (RSL_ALG_ID_A5_1) { return '000'B; }
2184 case (RSL_ALG_ID_A5_2) { return '001'B; }
2185 case (RSL_ALG_ID_A5_3) { return '010'B; }
2186 case (RSL_ALG_ID_A5_4) { return '011'B; }
2187 case (RSL_ALG_ID_A5_5) { return '100'B; }
2188 case (RSL_ALG_ID_A5_6) { return '101'B; }
2189 case (RSL_ALG_ID_A5_7) { return '110'B; }
2190 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002191 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2192 /* Make compiler happy by calling mtc.stop here. It is already
2193 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002194 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002195 }
2196 }
2197}
2198
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002199/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2200private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2201 var GsmFrameNumber fn;
2202 timer T := 8.0;
2203
2204 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2205 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2206
2207 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2208 /* Send the actual RACH */
2209 fn := f_L1CTL_RACH(L1CTL, ra);
2210
2211 T.start;
2212 alt {
2213 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2214 [] T.timeout {
2215 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2216 }
2217 }
2218 T.stop
2219 return fn;
2220}
Harald Weltee613f962018-04-18 22:38:16 +02002221
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002222/* Tune to a dedicated channel: L1CTL only */
2223private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002224 if (not pars.fhp.enabled) {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002225 var TrxParsItem trx_pars := mp_trx_pars[pars.trx_nr];
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002226 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002227 trx_pars.arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002228 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002229 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002230 pars.fhp.maio_hsn.hsn,
2231 pars.fhp.maio_hsn.maio,
2232 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002233 }
2234}
2235
Harald Welte70767382018-02-21 12:16:40 +01002236/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002237private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002238 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002239
2240 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002241 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002242
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002243 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002244 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002245 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002246 } else {
Vadim Yanitskiyf54db112020-11-16 18:00:15 +07002247 var TrxParsItem trx_pars := mp_trx_pars[g_pars.trx_nr];
2248 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, trx_pars.arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002249 }
2250
Harald Welte70767382018-02-21 12:16:40 +01002251 /* enable dedicated mode */
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06002252 f_l1ctl_est_dchan(L1CTL, g_pars);
2253
Harald Weltee613f962018-04-18 22:38:16 +02002254 /* enable encryption, if requested */
2255 if (encr_enable) {
2256 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2257 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2258 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002259
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002260 /* Send TCH Mode Request to the L1 if needed */
2261 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2262 var L1ctlTchMode tch_mode;
2263
2264 select (g_pars.chan_mode.coding_alg_rate) {
2265 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2266 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2267 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2268 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2269 case else {
2270 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2271 " is not supported by the L1, falling back to signalling");
2272 tch_mode := L1CTL_CHAN_MODE_SIGN;
2273 }
2274 }
2275
2276 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2277 }
2278
Harald Weltefa45e9e2018-03-10 18:59:03 +01002279 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002280}
2281
Vadim Yanitskiydd228c42021-07-04 02:37:30 +02002282/* Initialize and start the RTP emulation component for a ConnHdlr */
2283friend function f_rtpem_activate(inout octetstring payload,
2284 RtpemConfig cfg := c_RtpemDefaultCfg,
2285 RtpemMode mode := RTPEM_MODE_BIDIR)
2286runs on ConnHdlr {
2287 /* Step 0: initialize, connect and start the emulation component */
2288 vc_RTPEM := RTP_Emulation_CT.create(testcasename() & "-RTPEM");
2289 map(vc_RTPEM:RTP, system:RTP);
2290 map(vc_RTPEM:RTCP, system:RTCP);
2291 connect(vc_RTPEM:CTRL, self:RTPEM_CTRL);
2292 connect(vc_RTPEM:DATA, self:RTPEM_DATA);
2293 vc_RTPEM.start(RTP_Emulation.f_main());
2294
2295 /* Step 1: configure the RTP parameters */
2296 var integer payload_len := 0;
2297 var octetstring hdr := ''O;
2298
2299 select (g_pars.chan_mode) {
2300 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)) /* TCH/FS */
2301 { payload_len := 33; hdr := 'D0'O; }
2302 case (tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)) /* TCH/HS */
2303 { payload_len := 15; hdr := '00'O; }
2304 case (tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)) /* TCH/EFS */
2305 { payload_len := 31; hdr := 'C0'O; }
2306 case else { /* FIXME: also handle TCH/AFS and TCH/AHS */
2307 setverdict(fail, "Unhandled RSL channel mode := ", g_pars.chan_mode);
2308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2309 }
2310 }
2311
2312 /* Pad the payload to conform the expected length */
2313 payload := f_pad_oct(hdr & payload, payload_len, '00'O);
2314 cfg.tx_fixed_payload := payload;
2315 f_rtpem_configure(RTPEM_CTRL, cfg);
2316
2317 /* Step 2: bind the RTP emulation to the configured address */
2318 var PortNumber rtpem_bind_port := mp_rtpem_bind_port;
2319 f_rtpem_bind(RTPEM_CTRL, mp_rtpem_bind_ip, rtpem_bind_port);
2320
2321 /* Step 3: send CRCX with the configured address/port to the IUT */
2322 var RSL_Message rsl_pdu := f_rsl_transceive_ret(
2323 ts_RSL_IPA_CRCX(g_chan_nr, f_inet_addr(mp_rtpem_bind_ip), rtpem_bind_port),
2324 tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2325 "IPA CRCX ACK");
2326
2327 /* Step 4: connect to the IUT's address/port parsed from CRCX ACK */
2328 var HostName local_addr := f_inet_ntoa(rsl_pdu.ies[2].body.ipa_local_ip);
2329 var PortNumber local_port := rsl_pdu.ies[3].body.ipa_local_port;
2330 f_rtpem_connect(RTPEM_CTRL, local_addr, local_port);
2331
2332 /* Step 5: set the given RTP emulation mode */
2333 f_rtpem_mode(RTPEM_CTRL, mode);
2334}
2335
Harald Welte70767382018-02-21 12:16:40 +01002336/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002337private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002338 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002339 RSL.clear;
2340
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002341 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002342 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002343 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002344 }
Harald Welte70767382018-02-21 12:16:40 +01002345
2346 f_est_dchan();
2347
2348 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2349 * RSL measurement reports on Abis side */
2350 timer T := 8.0;
2351 T.start;
2352 alt {
2353 [] as_l1_sacch();
2354 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002355 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002356 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002357 [] L1CTL.receive { repeat; }
2358 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002359 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002360 * of any earlier errors, so if we reach this timeout, we're good */
2361 setverdict(pass);
2362 }
2363 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002365 }
2366 }
2367 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002368 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002369}
Harald Welte0472ab42018-03-12 15:02:26 +01002370
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002371/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2372private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002373 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002374 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2375 timer Tup := 10.0;
2376 Tup.start;
2377 alt {
2378 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2379 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2380 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002381
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002382 if (rx_lvl != max_rx_lvl) {
2383 repeat;
2384 }
2385 Tup.stop;
2386 }
2387 [] L1CTL.receive { repeat; }
2388 [] Tup.timeout {
2389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2390 log2str("Didn't reach full power ", max_rx_lvl));
2391 }
2392 }
2393 return max_rx_lvl;
2394}
2395
2396/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2397private function f_verify_ramp_up() runs on ConnHdlr {
2398 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002399 var integer initial_rx_lvl := -1;
2400 var integer last_rx_lvl := -1;
2401 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2402
2403 timer T := 2.0;
2404 alt {
2405 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2406 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2407 log("Received rx_level=", rx_lvl);
2408 if (initial_rx_lvl == -1) {
2409 initial_rx_lvl := rx_lvl;
2410 last_rx_lvl := rx_lvl;
2411
2412 /* Expect a somehow low value during first received messages */
2413 if (initial_rx_lvl >= max_rx_lvl / 2) {
2414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2415 log2str("Detected high initial tx power during ramp up: ",
2416 initial_rx_lvl , ", full power is", max_rx_lvl));
2417 }
2418 }
2419
2420 /* received Rx level bigger than maximum allowed power by CN */
2421 if (rx_lvl > max_rx_lvl) {
2422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2423 log2str("Detected Tx power higher than full power: ",
2424 rx_lvl , " > ", max_rx_lvl));
2425 }
2426
2427 /* Make sure it never decreases, since we are rumping up */
2428 if (last_rx_lvl > rx_lvl) {
2429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2430 log2str("Detected Tx power decrease during ramp up: ",
2431 last_rx_lvl , " -> ", rx_lvl));
2432 }
2433
2434 if (rx_lvl == max_rx_lvl and not T.running) {
2435 /* We reached the maximum power, start timer and receive
2436 /* a few more to make sure we don't surpass it */
2437 log("Reached full power, wating a bit more until success");
2438 T.start;
2439 }
2440
2441 last_rx_lvl := rx_lvl;
2442 repeat;
2443 }
2444 [] L1CTL.receive { repeat; }
2445 [] T.timeout { }
2446 }
2447
2448 /* We didn't increase tx power during ramp up */
2449 if (initial_rx_lvl < last_rx_lvl) {
2450 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2451 } else {
2452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2453 log2str("No Tx power increase during whole ramp up: ",
2454 initial_rx_lvl , " -> ", last_rx_lvl));
2455 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002456}
2457
2458/* verify BTS ramps power down to rx_level 0 */
2459private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2460 var L1ctlDlMessage l1_dl;
2461 var integer last_rx_lvl := max_rx_lvl;
2462
2463 timer Tdown := 5.0;
2464 Tdown.start;
2465 alt {
2466 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2467 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2468 log("Received rx_level=", rx_lvl);
2469
2470 /* received Rx level bigger than maximum allowed power by CN */
2471 if (rx_lvl > max_rx_lvl) {
2472 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2473 log2str("Detected Tx power higher than full power: ",
2474 rx_lvl , " > ", max_rx_lvl));
2475 }
2476
2477 /* Make sure it never increases, since we are rumping down */
2478 if (last_rx_lvl < rx_lvl) {
2479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2480 log2str("Detected Tx power increase during ramp up: ",
2481 last_rx_lvl , " -> ", rx_lvl));
2482 }
2483
2484 last_rx_lvl := rx_lvl;
2485 if (last_rx_lvl != 0) {
2486 repeat;
2487 }
2488 /* we reached power level 0, we are done */
2489 Tdown.stop;
2490 }
2491 [] L1CTL.receive { repeat; }
2492 [] Tdown.timeout { }
2493 }
2494
2495 /* We didn't increase tx power during ramp down */
2496 if (max_rx_lvl > last_rx_lvl) {
2497 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2498 } else {
2499 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2500 log2str("No Tx power decrease during whole ramp down: ",
2501 max_rx_lvl , " -> ", last_rx_lvl));
2502 }
2503}
2504
2505/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002506private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002507 f_l1_tune(L1CTL);
2508 RSL.clear;
2509
2510 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002511
2512 setverdict(pass);
2513}
2514testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2515 var ConnHdlr vc_conn;
2516 var ConnHdlrPars pars;
2517 f_init();
2518 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2519 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2520 pcu_comp := false, trxc_comp := true);
2521 vc_conn.done;
2522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2523}
2524
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002525/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002526private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002527 f_connhdlr_init_vty_bsc();
2528
2529 f_l1_tune(L1CTL);
2530 RSL.clear;
2531
2532 /* Wait until BTS is started and at full power */
2533 var integer max_rx_lvl := f_wait_ramp_up();
2534 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2535
2536 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2537 f_verify_ramp_down(max_rx_lvl);
2538
2539 setverdict(pass);
2540}
2541testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2542 var ConnHdlr vc_conn;
2543 var ConnHdlrPars pars;
2544 f_init();
2545 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2546 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2547 pcu_comp := false, trxc_comp := true);
2548 vc_conn.done;
2549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2550}
2551
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002552/* Verify Tx power:
2553 * + ramping down during ADM state UNLOCKED->LOCKED
2554 * + ramping up during ADM state LOCKED->UNLOCKED
2555 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002556private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002557 var L1ctlDlMessage l1_dl;
2558 var integer last_rx_lvl;
2559
2560 f_connhdlr_init_vty_bsc();
2561
2562 f_l1_tune(L1CTL);
2563 RSL.clear;
2564
2565 /* Wait until BTS is started and at full power */
2566 var integer max_rx_lvl := f_wait_ramp_up();
2567 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2568
2569 log("ADM STATE UNLOCKED->LOCKED");
2570 f_vty_enter_cfg_trx(BSCVTY);
2571 f_vty_transceive(BSCVTY, "rf_locked 1");
2572 last_rx_lvl := max_rx_lvl;
2573 f_verify_ramp_down(max_rx_lvl);
2574
2575 /* Let some time after we received 0dBm, then check we don't receive BCCH
2576 * anymore because scheduler has stopped after ramping down */
2577 f_sleep(2.0);
2578 L1CTL.clear;
2579 timer Tlocked := 2.0;
2580 Tlocked.start;
2581 alt {
2582 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2584 log2str("Received data_ind during rf_locked: ", l1_dl));
2585 }
2586 [] L1CTL.receive { repeat; }
2587 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2588 }
2589
2590 log("ADM STATE LOCKED->UNLOCKED");
2591 f_vty_transceive(BSCVTY, "rf_locked 0");
2592 f_verify_ramp_up();
2593 setverdict(pass);
2594}
2595testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2596 var ConnHdlr vc_conn;
2597 var ConnHdlrPars pars;
2598 f_init();
2599 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2600 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2601 pcu_comp := false, trxc_comp := true);
2602 vc_conn.done;
2603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2604}
2605
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002606private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002607 timer T := 8.0;
2608 T.start;
2609 var RSL_Message rsl;
2610 alt {
2611 [] as_l1_sacch();
2612 [] L1CTL.receive { repeat; }
2613 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2614 if (rsl.ies[3].body.bs_power.power_level == level) {
2615 setverdict(pass)
2616 } else {
2617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2618 }
2619 }
2620 [] T.timeout {
2621 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2622 }
2623 }
2624}
2625
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002626/* See if the RSL MEASurement RESult contains expeced BS power level
2627 * set _during_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002628private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002629 f_l1_tune(L1CTL);
2630 RSL.clear;
2631
2632 if (mp_bts_trxc_port != -1) {
2633 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2634 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2635 }
2636
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002637 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002638 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2639 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2640
2641 f_est_dchan(more_ies :={valueof(pwr)});
2642
2643 f_check_meas_bs_power_level(pwr_var);
2644
2645 f_rsl_chan_deact();
2646 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2647}
2648
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002649/* See if the RSL MEASurement RESult contains expeced BS power level
2650 * set _after_ the CHANnel ACTIVation procedure. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002651private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002652 f_l1_tune(L1CTL);
2653 RSL.clear;
2654
2655 if (mp_bts_trxc_port != -1) {
2656 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2657 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2658 }
2659
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002660 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002661 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2662
2663 f_est_dchan();
2664
2665 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2666
2667 f_check_meas_bs_power_level(pwr_var);
2668
2669 f_rsl_chan_deact();
2670 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2671}
2672
2673testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2674 var ConnHdlr vc_conn;
2675 var ConnHdlrPars pars;
2676 f_init();
2677 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2678 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2679 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2680 pcu_comp := false, trxc_comp := true);
2681 vc_conn.done;
2682 }
2683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2684}
2685
2686testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2687 var ConnHdlr vc_conn;
2688 var ConnHdlrPars pars;
2689 f_init();
2690 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2691 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2692 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2693 pcu_comp := false, trxc_comp := true);
2694 vc_conn.done;
2695 }
2696 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2697}
2698
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002699/* Target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2700 * second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds.
2701 * These power levels are valid for all bands and require no special handling. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002702private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002703 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002704 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002705
2706 f_trxc_fake_rssi(rxlev2dbm(10));
2707 f_l1_tune(L1CTL);
2708 RSL.clear;
2709
2710 var RSL_IE_List addl_ies;
2711 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2712
2713 addl_ies := {
2714 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2715 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2716 };
2717
2718 /* establish with power parameters */
2719 f_est_dchan(more_ies := addl_ies);
2720
2721 /* set a high value to ensure L1 power control level increases */
2722 f_trxc_fake_rssi(rxlev2dbm(20));
2723
2724 timer T2 := 6.0;
2725 T2.start;
2726 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002727 [] as_l1_sacch_l1h(l1h) {
2728 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002729 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002730 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002731 T2.stop;
2732 }
2733 [] L1CTL.receive { repeat; }
2734 [] T2.timeout {
2735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2736 "Power Level in L1 header has not increased sufficiently");
2737 }
2738 }
2739
2740 /* set a low value to ensure L1 power control level decreases */
2741 f_trxc_fake_rssi(rxlev2dbm(0));
2742
2743 timer T4 := 6.0;
2744 T4.start;
2745 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002746 [] as_l1_sacch_l1h(l1h) {
2747 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002748 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002749 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002750 T4.stop;
2751 setverdict(pass, "Power level in L1 decreased/increased as expected");
2752 }
2753 [] L1CTL.receive { repeat; }
2754 [] T4.timeout {
2755 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2756 "Power Level in L1 header has not decreased sufficiently");
2757 }
2758 }
2759
2760 f_rsl_chan_deact();
2761 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2762
2763}
2764
2765/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002766private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002767 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002768 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002769
2770 /* set a low value to ensure power increases */
2771 f_trxc_fake_rssi(rxlev2dbm(10));
2772 f_l1_tune(L1CTL);
2773 RSL.clear;
2774
2775 var RSL_IE_List addl_ies;
2776 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2777
2778 addl_ies := {
2779 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2780 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2781 };
2782
2783 /* establish with power parameters */
2784 f_est_dchan(more_ies := addl_ies);
2785
2786 timer T1 := 10.0;
2787 T1.start;
2788 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002789 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002790 [] L1CTL.receive { repeat; }
2791 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002792 if (not isbound(l1h)) {
2793 setverdict(fail, "No SACCH blocks were received");
2794 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002795 setverdict(fail, "Power level in L1 header should not have changed");
2796 }
2797 }
2798 }
2799
2800 f_rsl_chan_deact();
2801 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2802
2803}
2804
2805/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002806private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002807 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002808 var uint5_t pwr_var := 15;
2809 var uint5_t pwr_max_var := f_get_max_power_from_band();
2810
2811 /* set a low value to ensure power increases */
2812 f_trxc_fake_rssi(rxlev2dbm(10));
2813 f_l1_tune(L1CTL);
2814 RSL.clear;
2815
2816 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2817 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2818
2819 /* establish with fixed power level */
2820 f_est_dchan(more_ies :={valueof(pwr)});
2821
2822 /* check our initial power level */
2823 f_wait_for_l1_power_level(pwr_var);
2824
2825 /* update power param to enable power loop
2826 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2827 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2828
2829 /* wait, then check that our power level was reduced */
2830 timer T1 := 10.0;
2831 T1.start;
2832 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002833 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002834 [] L1CTL.receive { repeat; }
2835 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002836 if (not isbound(l1h)) {
2837 setverdict(fail, "No SACCH blocks were received");
2838 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002839 setverdict(pass, "Power level in L1 header reduced as expected");
2840 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002841 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
2842 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02002843 }
2844 }
2845 }
2846
2847 f_rsl_chan_deact();
2848 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2849
2850}
2851
2852/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002853private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002854 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002855
2856 /* set a high value to ensure power decreases */
2857 f_trxc_fake_rssi(rxlev2dbm(50));
2858 f_l1_tune(L1CTL);
2859 RSL.clear;
2860
2861 var uint5_t pwr_var := 5;
2862 var uint5_t pwr_target_val := 15;
2863
2864 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2865 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2866
2867 /* establish with fixed power level */
2868 f_est_dchan(more_ies :={valueof(pwr)});
2869
2870 /* check our initial power level */
2871 f_wait_for_l1_power_level(pwr_var);
2872
2873 /* update power param to enable power loop
2874 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002875 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002876
2877 /* wait, then check that our power level was increased */
2878 timer T1 := 10.0;
2879 T1.start;
2880 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002881 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002882 [] L1CTL.receive { repeat; }
2883 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002884 if (not isbound(l1h)) {
2885 setverdict(fail, "No SACCH blocks were received");
2886 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
2887 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002888 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002889 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002890 }
2891 }
2892 }
2893
2894 f_rsl_chan_deact();
2895 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2896
2897}
2898
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002899/* See if the power level remains constant when MS Power Parameters IE
2900 * is _absent_ in the CHANnel ACTIVation message. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002901private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002902 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02002903
2904 /* set a high value to ensure power decreases */
2905 f_trxc_fake_rssi(rxlev2dbm(50));
2906 f_l1_tune(L1CTL);
2907 RSL.clear;
2908
2909 var uint5_t pwr_var := 5;
2910
2911 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2912 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2913
2914 /* establish with fixed power level */
2915 f_est_dchan(more_ies :={valueof(pwr)});
2916
2917 /* check our initial power level */
2918 f_wait_for_l1_power_level(pwr_var);
2919
2920 /* wait, then check that our power level did not change */
2921 timer T1 := 10.0;
2922 T1.start;
2923 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002924 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2925 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02002926 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2927 "BS power control should not be active unless we receive a power parameters IE!");
2928 }
2929 repeat;
2930 }
2931 [] L1CTL.receive { repeat; }
2932 [] T1.timeout { setverdict(pass); }
2933 }
2934
2935 f_rsl_chan_deact();
2936 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2937
2938}
2939
Vadim Yanitskiy6860e862021-06-30 00:16:26 +02002940/* See if the power level remains constant when MS Power Parameters IE
2941 * is _absent_ in the CHANnel ACTIVation and MS Power Control messages. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002942private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002943 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02002944
2945 /* set a high value to ensure power decreases */
2946 f_trxc_fake_rssi(rxlev2dbm(50));
2947 f_l1_tune(L1CTL);
2948 RSL.clear;
2949
2950 var uint5_t pwr_var := 5;
2951
2952 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2953 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2954
2955 /* establish with fixed power level */
2956 f_est_dchan(more_ies :={valueof(pwr)});
2957
2958 /* check our initial power level */
2959 f_wait_for_l1_power_level(pwr_var);
2960
2961 /* pwr control without power params IE, should NOT activate MS power control*/
2962 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2963
2964 /* wait, then check that our power level did not change */
2965 timer T1 := 10.0;
2966 T1.start;
2967 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002968 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2969 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02002970 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2971 "BS power control should not be active unless we receive a power parameters IE!");
2972 }
2973 repeat;
2974 }
2975 [] L1CTL.receive { repeat; }
2976 [] T1.timeout { setverdict(pass); }
2977 }
2978
2979 f_rsl_chan_deact();
2980 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2981
2982}
2983
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002984private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002985 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002986 timer T0 := 10.0;
2987 T0.start;
2988 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002989 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2990 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2992 "Power level in L1 header != signaled (RSL) power level.");
2993 }
2994 }
2995 [] L1CTL.receive { repeat; }
2996 [] T0.timeout {
2997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2998 "Timeout waiting for initial power level");
2999 }
3000 }
3001 T0.stop;
3002}
3003
3004private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
3005 var IntegerRecord min_dbm_level;
3006 var IntegerRecord max_dbm_level;
3007 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3008
3009 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
3010 if (min_dbm_level[i] == level) {
3011 return true;
3012 }
3013 }
3014 return false;
3015}
3016
3017private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
3018 var IntegerRecord min_dbm_level;
3019 var IntegerRecord max_dbm_level;
3020 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3021
3022 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
3023 if (max_dbm_level[i] == level) {
3024 return true;
3025 }
3026 }
3027 return false;
3028}
3029
3030private function f_get_max_power_from_band() runs on ConnHdlr return integer {
3031 var IntegerRecord min_dbm_level;
3032 var IntegerRecord max_dbm_level;
3033 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
3034 return max_dbm_level[0];
3035}
3036
3037type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003038private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02003039private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
3040 // 45.005 4.1.1
3041 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
3042 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
3043 2, 1, 0};
3044 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
3045 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
3046 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
3047 var IntegerRecord rv;
3048
3049 select(band){
3050 case (BtsBand_allGSM){
3051 rv := gsm_power;
3052 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3053 max_dbm_level := {2, 1, 0};
3054 }
3055 case("DCS1800"){
3056 rv := dcs_power;
3057 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3058 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3059 }
3060 case("PCS1900"){
3061 rv := pcs_power;
3062 min_dbm_level := {15};
3063 max_dbm_level := {30};
3064 }
Harald Welte194b6912020-10-11 21:01:55 +02003065 case else {
3066 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3067 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003068 }
3069
3070 return rv;
3071}
3072
3073private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003074 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 +02003075}
3076
3077testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3078 var ConnHdlr vc_conn;
3079 var ConnHdlrPars pars;
3080 f_init();
3081 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3082 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3083 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3084 pars.bts0_band := f_vty_get_bts0_band();
3085 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3086 vc_conn.done;
3087 }
3088 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3090}
3091
3092testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3093 var ConnHdlr vc_conn;
3094 var ConnHdlrPars pars;
3095 f_init();
3096 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3097 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3098 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3099 pars.bts0_band := f_vty_get_bts0_band();
3100 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3101 vc_conn.done;
3102 }
3103 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3105}
3106
3107testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3108 var ConnHdlr vc_conn;
3109 var ConnHdlrPars pars;
3110 f_init();
3111 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3112 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3113 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3114 pars.bts0_band := f_vty_get_bts0_band();
3115 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3116 vc_conn.done;
3117 }
3118 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3120}
3121
3122testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3123 var ConnHdlr vc_conn;
3124 var ConnHdlrPars pars;
3125 f_init();
3126 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3127 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3128 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3129 pars.bts0_band := f_vty_get_bts0_band();
3130 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3131 vc_conn.done;
3132 }
3133 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3134 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3135}
3136
Eric Wild280ccb82019-06-17 11:11:52 +02003137testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3138 var ConnHdlr vc_conn;
3139 var ConnHdlrPars pars;
3140 f_init();
3141 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3142 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3143 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3144 pars.bts0_band := f_vty_get_bts0_band();
3145 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3146 vc_conn.done;
3147 }
3148 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3149 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3150}
3151
Eric Wild095024b2019-06-17 15:08:57 +02003152testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3153 var ConnHdlr vc_conn;
3154 var ConnHdlrPars pars;
3155 f_init();
3156 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3157 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3158 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3159 pars.bts0_band := f_vty_get_bts0_band();
3160 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3161 vc_conn.done;
3162 }
3163 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3165}
3166
Philipp Maier149c3922020-10-22 17:29:36 +02003167function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003168 var template RSL_IE_ChannelMode ch_mode;
3169 var ConnHdlr vc_conn;
3170 var ConnHdlrPars pars;
3171 f_init();
3172 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3173 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3174 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003175 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003176 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3177 pcu_comp := false, trxc_comp := true);
3178 vc_conn.done;
3179 }
3180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3181}
Philipp Maier149c3922020-10-22 17:29:36 +02003182
3183testcase TC_meas_res_speech_tchf() runs on test_CT {
3184 f_TC_meas_res_speech_tchf(false);
3185}
3186
3187testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3188 f_TC_meas_res_speech_tchf(true);
3189}
3190
3191function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003192 var template RSL_IE_ChannelMode ch_mode;
3193 var ConnHdlr vc_conn;
3194 var ConnHdlrPars pars;
3195 f_init();
3196 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3197 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3198 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003199 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003200 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3201 pcu_comp := false, trxc_comp := true);
3202 vc_conn.done;
3203 }
3204 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3205}
Philipp Maier149c3922020-10-22 17:29:36 +02003206
3207testcase TC_meas_res_speech_tchh() runs on test_CT {
3208 f_TC_meas_res_speech_tchh(false)
3209}
3210
3211testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3212 f_TC_meas_res_speech_tchh(true)
3213}
3214
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003215testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3216 var template RSL_IE_ChannelMode ch_mode;
3217 var ConnHdlr vc_conn;
3218 var ConnHdlrPars pars;
3219 f_init();
3220 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3221 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3222 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3223 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3224 pars.l1_pars.toa256_enabled := true;
3225 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3226 pcu_comp := false, trxc_comp := true);
3227 vc_conn.done;
3228 }
3229 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3230}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003231
Harald Welte70767382018-02-21 12:16:40 +01003232testcase TC_meas_res_sign_tchf() runs on test_CT {
3233 var ConnHdlr vc_conn;
3234 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003235 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003236 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003237 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003238 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003239 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3240 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003241 vc_conn.done;
3242 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003243 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003244}
3245testcase TC_meas_res_sign_tchh() runs on test_CT {
3246 var ConnHdlr vc_conn;
3247 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003248 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003249 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003250 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003251 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003252 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3253 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003254 vc_conn.done;
3255 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003256 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003257}
3258testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3259 var ConnHdlr vc_conn;
3260 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003261 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003262 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003263 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3264 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003265 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3266 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003267 vc_conn.done;
3268 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003269 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003270}
3271testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3272 var ConnHdlr vc_conn;
3273 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003274 f_init();
Pau Espin Pedrol93a7b8b2021-10-08 16:57:50 +02003275 f_vty_config(BTSVTY, "bts 0", "no supp-meas-info toa256");
Harald Welte70767382018-02-21 12:16:40 +01003276 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3277 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003278 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3279 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003280 vc_conn.done;
3281 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003283}
Harald Welte685d5982018-02-27 20:42:05 +01003284testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3285 var ConnHdlr vc_conn;
3286 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003287 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003288 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3289 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003290 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003291 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003292 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3293 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003294 vc_conn.done;
3295 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003297}
3298
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03003299/* Make sure that we always get RSL MEASurement RESult messages regardless
3300 * of what is sent on SACCH: (RR) Measurement Report or SAPI=3 data (SMS). */
3301private function f_TC_meas_res_sapi3(charstring id) runs on ConnHdlr {
3302 timer Texec := 8.0;
3303 timer Timpf := 2.0;
3304 timer Tmr;
3305
3306 f_l1_tune(L1CTL);
3307 RSL.clear;
3308
3309 f_est_dchan();
3310 L1CTL.clear;
3311
3312 /* Establish the main SAPI=0 link on DCCH first */
3313 f_tx_lapdm(ts_LAPDm_SABM(0, cr_MO_CMD, true, ''O), ts_RslLinkID_DCCH(0));
3314
3315 /* Give more time for the first RSL MEASurement RESult */
3316 Tmr.start(0.480 * 2.0);
3317 Texec.start; /* EXECution timer */
3318 Timpf.start; /* IMPFung timer */
3319
3320 alt {
3321 /* We expect RSL MEASurement RESult messages every ~480ms (plus some guard) */
3322 [] RSL.receive(tr_RSL_MEAS_RES(g_pars.chan_nr)) {
3323 /* Reschedule the MEAS RES timer */
3324 Tmr.start(0.480 + 0.120);
3325 repeat;
3326 }
3327 [] RSL.receive { repeat; }
3328 [] Tmr.timeout {
3329 setverdict(fail, "Timeout waiting for RSL MEAS RES");
3330 }
3331 /* Inject some SAPI=3 traffic on SACCH every 2 seconds */
3332 [] Timpf.timeout {
3333 f_tx_lapdm(ts_LAPDm_SABM(3, cr_MO_CMD, true, ''O), ts_RslLinkID_SACCH(3));
3334 log("Injected SAPI=3 traffic on SACCH");
3335 Timpf.start;
3336 repeat;
3337 }
3338 /* We're good if survived so far */
3339 [] Texec.timeout {
3340 setverdict(pass);
3341 }
3342 }
3343
3344 f_rsl_chan_deact();
3345 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3346 f_rslem_unregister(0, g_chan_nr);
3347}
3348testcase TC_meas_res_speech_tchf_sapi3() runs on test_CT {
3349 var template RSL_IE_ChannelMode ch_mode;
3350 var template ConnHdlrPars pars;
3351 var ConnHdlr vc_conn;
3352
3353 f_init();
3354
3355 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3356 pars := t_Pars(t_RslChanNr_Bm(1), ch_mode);
3357
3358 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3359 vc_conn.done;
3360
3361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3362}
3363testcase TC_meas_res_speech_tchh_sapi3() runs on test_CT {
3364 var template RSL_IE_ChannelMode ch_mode;
3365 var template ConnHdlrPars pars;
3366 var ConnHdlr vc_conn;
3367
3368 f_init();
3369
3370 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3371 pars := t_Pars(t_RslChanNr_Lm(5, 0), ch_mode);
3372
3373 vc_conn := f_start_handler(refers(f_TC_meas_res_sapi3), valueof(pars));
3374 vc_conn.done;
3375
3376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3377}
3378
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003379/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3380 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003381private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003382 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003383 var RSL_IE_MS_Power ms_power;
3384 var RSL_Message rsl;
3385 var uint5_t power_level := 0;
3386
3387 f_l1_tune(L1CTL);
3388 RSL.clear;
3389
3390 f_est_dchan();
3391
3392 ms_power.reserved := 0;
3393 ms_power.fpc_epc := false;
3394
3395 /* Send the first power control command. This will disable any BTS/TRX
3396 * internal power control and switch the MS (which is not in scope of
3397 * this test) to a constant power level. We start with a power level
3398 * of 0 */
3399 ms_power.power_level := power_level;
3400 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3401 RSL.send(rsl);
3402
3403 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003404 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3405 if (l1h.ms_power_lvl != power_level) {
3406 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3407 "match the signaled (RSL) power level := ", power_level);
3408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003409 }
3410
3411 /* Signal a new power level via RSL for the next turn. */
3412 if (power_level < 31) {
3413 power_level := power_level + 1;
3414 ms_power.power_level := power_level;
3415 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3416 RSL.send(rsl);
3417 repeat;
3418 }
3419
3420 }
3421
3422 /* Ignore all other blocks */
3423 [] L1CTL.receive { repeat; }
3424
3425 }
3426
3427 f_rsl_chan_deact();
3428 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3429
3430 setverdict(pass);
3431}
3432
3433testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3434 var ConnHdlr vc_conn;
3435 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003436 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003437
3438 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3439 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3440 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3441 vc_conn.done;
3442 }
3443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3444}
Harald Welte70767382018-02-21 12:16:40 +01003445
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003446/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003447TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003448private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003449 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003450 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003451
3452 f_l1_tune(L1CTL);
3453 RSL.clear;
3454
3455 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003456 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003457
3458 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3459
3460
3461 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003462 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3463 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003464 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3465 }
3466
3467 }
3468
3469 /* Ignore all other blocks */
3470 [] L1CTL.receive { repeat; }
3471
3472 }
3473
3474 f_rsl_chan_deact();
3475 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3476
3477 setverdict(pass);
3478}
3479
3480testcase TC_rsl_chan_initial_ta() runs on test_CT {
3481 var ConnHdlr vc_conn;
3482 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003483 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003484 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003485 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3486 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003487 vc_conn.done;
3488 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3489}
3490
Eric Wilde57e1a62019-05-28 13:30:55 +02003491/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003492private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003493 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003494 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003495
3496 var RSL_IE_MS_Power ms_power;
3497 ms_power.reserved := 0;
3498 ms_power.fpc_epc := false;
3499 ms_power.power_level := ms_power_level;
3500
3501 f_l1_tune(L1CTL);
3502 RSL.clear;
3503
3504 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3505
3506 timer T := 1.0;
3507 T.start;
3508 alt {
3509 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003510 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3511 if (l1h.ms_power_lvl != ms_power_level) {
3512 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3513 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003514 }
3515 }
3516 /* Ignore all other blocks */
3517 [] L1CTL.receive { repeat; }
3518 [] T.timeout {
3519 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3520 }
3521 }
3522
3523 f_rsl_chan_deact();
3524 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3525 setverdict(pass);
3526}
3527
3528testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3529 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3530 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3531}
3532
Harald Welte0472ab42018-03-12 15:02:26 +01003533/* 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 +01003534private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003535 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003536 RSL.clear;
3537
3538 f_est_dchan();
3539 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003540 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003541
3542 timer T := 40.0;
3543 T.start;
3544 alt {
3545 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3546 setverdict(pass)
3547 }
3548 [] RSL.receive { repeat };
3549 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003550 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003551 }
3552 }
3553 f_rsl_chan_deact();
3554}
3555testcase TC_conn_fail_crit() runs on test_CT {
3556 var ConnHdlr vc_conn;
3557 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003558 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003559 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3560 pars.t_guard := 60.0;
3561 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3562 vc_conn.done;
3563}
3564
Harald Welte93640c62018-02-25 16:59:33 +01003565/***********************************************************************
3566 * Paging
3567 ***********************************************************************/
3568
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003569private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003570 if (tmsi == 'FFFFFFFF'O) {
3571 return true;
3572 } else {
3573 return false;
3574 }
3575}
Harald Welte70767382018-02-21 12:16:40 +01003576
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003577private type record allowedFn { integer frame_nr }
3578private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3579private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3580private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3581private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3582private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3583private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3584private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3585private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3586private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003587{
3588 var integer frame_nr_51;
3589 frame_nr_51 := frame_nr mod 51
3590
3591 var allowedFn fn_check;
3592 fn_check.frame_nr := frame_nr_51;
3593
3594 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003595 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003596 return;
3597 }
3598
3599 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3600 return;
3601 }
3602 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3603 return;
3604 }
3605 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3606 return;
3607 }
3608 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3609 return;
3610 }
3611 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3612 return;
3613 }
3614 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3615 return;
3616 }
3617 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3618 return;
3619 }
3620 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3621 return;
3622 }
3623
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003624 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003625 return;
3626}
3627
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003628private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3629 inout integer num_paging_rcv_ids,
3630 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003631runs on test_CT {
3632 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003633 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003634 repeat;
3635 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003636 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003637 var octetstring without_plen :=
3638 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3639 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003640
3641 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3642
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003643 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3644 /* Ignore empty RR Paging Request (PCH filling) messages.
3645 * TODO: does it make sense to count them? */
3646 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003647 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3648 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003649 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003650 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3651 }
3652 } else if (match(rr, tr_PAGING_REQ2)) {
3653 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3654 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3655 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3656 }
3657 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3658 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3659 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003660 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003661 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3662 }
3663 } else if (match(rr, tr_PAGING_REQ3)) {
3664 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3665 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3666 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3667 }
3668 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3669 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3670 }
3671 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3672 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3673 }
3674 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3675 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3676 }
3677 }
3678 repeat;
3679 }
3680}
3681
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003682private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003683 boolean combined_ccch,
3684 integer bs_ag_blks_res,
3685 float load_factor,
Philipp Maierca058272021-06-23 10:35:23 +02003686 /* Mix in a paging request through the PCU socket for every Nth (ps_load_modulus)
3687 * paging command that is issued via RSL. */
3688 integer ps_load_modulus,
3689 /* Wait until the paging queue inside the BTS is congested before starting to add
3690 * pagings via the PCU socket (0 = disabled) */
3691 boolean ps_wait_cong,
3692 /* Maximum time to wait until the paging queue is drained at the end of the test.
3693 * This usually takes about 15s (size: 200, ~ 13 per s -> 15s), it is recommended
3694 * to set this value to 18s, however the draining process may take significantly
3695 * longer when the queue contains paging requests for PS as those are implemented
3696 * as immediate assignments and require an entire MAC block alone. */
3697 float queue_drain_timeout,
Harald Welte68e495b2018-02-25 00:05:57 +01003698 boolean exp_load_ind,
3699 boolean exp_overload,
3700 boolean use_tmsi
3701}
3702
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003703private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003704 integer num_paging_sent,
3705 integer num_paging_rcv_msgs,
3706 integer num_paging_rcv_ids,
Philipp Maierca058272021-06-23 10:35:23 +02003707 integer num_overload,
3708 /* When free space inside the paging queue reaches more than 2 thirds
3709 * of its capacity cong_detected is set to true. */
3710 boolean cong_detected
Harald Welte68e495b2018-02-25 00:05:57 +01003711}
3712
Harald Welte68e495b2018-02-25 00:05:57 +01003713/* Helper function for paging related testing */
3714private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Philipp Maierca058272021-06-23 10:35:23 +02003715 /* Using the PCU socket affects the timing of the paging processing. We only
3716 * activate the PCU socket if we do paging load tests that include additional
3717 * paging load that is introduced through the PCU socket. */
3718 if (cfg.ps_load_modulus > 0) {
3719 f_init_with_pcuif();
3720 } else {
3721 f_init();
3722 }
Harald Welte68e495b2018-02-25 00:05:57 +01003723 f_init_l1ctl();
3724 f_l1_tune(L1CTL);
3725
Philipp Maierca058272021-06-23 10:35:23 +02003726 var octetstring imm_ass := f_rnd_octstring(23);
3727 var ASP_RSL_Unitdata load_ind;
3728
Harald Welte68e495b2018-02-25 00:05:57 +01003729 var PagingTestState st := {
3730 num_paging_sent := 0,
3731 num_paging_rcv_msgs := 0,
3732 num_paging_rcv_ids := 0,
Philipp Maierca058272021-06-23 10:35:23 +02003733 num_overload := 0,
3734 cong_detected := false
Harald Welte68e495b2018-02-25 00:05:57 +01003735 };
3736
3737 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3738 var float max_pch_imsi_per_sec;
3739 if (cfg.use_tmsi) {
3740 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3741 } else {
3742 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3743 }
3744 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3745 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003746 var float time_total := 20.0;
3747 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3748 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003749
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003750 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3751 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003752
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003753 timer T_itv := 0.0;
3754 T_itv.start;
3755 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003756 alt {
3757 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003758 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003759 st.num_overload := st.num_overload + 1;
3760 repeat;
3761 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003762 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003764 }
Philipp Maierca058272021-06-23 10:35:23 +02003765 [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 +01003766 log("Rx LOAD_IND");
Philipp Maierca058272021-06-23 10:35:23 +02003767
3768 /* Detect paging congestion: The logic inside the BTS will diagnose the
3769 * paging queue as congested when the fill state is more than 66% (which
3770 * is two thirds fill state, or approx. 66 of 200 paging slots. When a
3771 * paging congestion is detected pagings that are issued through the PCU
3772 * socket (PS) are dropped in order to prefer the CS related pagings. */
3773 if (load_ind.rsl.ies[1].body.paging_load < 66) {
3774 st.cong_detected := true;
3775 }
3776
Harald Welte68e495b2018-02-25 00:05:57 +01003777 /* FIXME: analyze/verify interval + contents */
3778 repeat;
3779 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003780 /* ignore other RSL messages like RF RESource INDication */
3781 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003782 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003783 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003784 [] L1CTL.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003785 /* Only relevant when testing including with PCU sock connected */
3786 [] PCU.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003787 [] T_itv.timeout {
3788 /* Send paging cmds based on elapsed time */
3789 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3790 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003791 var MobileIdentityV mi;
3792
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003793 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003794 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003795 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003796 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003797 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003798 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003799
3800 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003801 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 +02003802
Philipp Maierca058272021-06-23 10:35:23 +02003803 /* Add additional pagings through the PCU socket interface. */
3804 if (cfg.ps_load_modulus > 0 and st.num_paging_sent mod cfg.ps_load_modulus == 0) {
3805 if (st.cong_detected == true or cfg.ps_wait_cong == false) {
3806 f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H, wait_for_cnf := false);
3807 }
3808 }
3809
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003810 st.num_paging_sent := st.num_paging_sent + 1;
3811 }
3812 if (st.num_paging_sent < pkt_total) {
3813 /* Wait for interval to next PAGING COMMAND */
3814 var float time_now := T_total.read;
3815 var float next_sched := int2float(st.num_paging_sent)*interval;
3816 if (next_sched > time_now) {
3817 T_itv.start(next_sched - time_now);
3818 } else {
3819 T_itv.start(0.0);
3820 }
3821 } else {
3822 /* We are done, no need to keep counting */
3823 T_total.stop;
3824 }
3825 }
3826 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003827 }
3828 }
3829
Philipp Maierca058272021-06-23 10:35:23 +02003830 timer T_wait := cfg.queue_drain_timeout
Harald Welte68e495b2018-02-25 00:05:57 +01003831 T_wait.start;
3832 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003833 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003834 [] L1CTL.receive { repeat; }
3835 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003836 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
Philipp Maierca058272021-06-23 10:35:23 +02003837 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) -> value load_ind { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003838 /* ignore other RSL messages like RF RESource INDication */
3839 [] RSL_CCHAN.receive { repeat; }
Philipp Maierca058272021-06-23 10:35:23 +02003840 /* Only relevant when testing including with PCU sock connected */
3841 [] PCU.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003842 [] T_wait.timeout {
Philipp Maierca058272021-06-23 10:35:23 +02003843 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 +01003844 }
Harald Welte68e495b2018-02-25 00:05:57 +01003845 }
3846
3847 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3848 " rcvd_ids=", st.num_paging_rcv_ids);
3849 return st;
3850}
3851
3852/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3853 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3854 * - that CCCH LOAD IND (PCH) are being generated
3855 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3856testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003857 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003858 var PagingTestCfg cfg := {
3859 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003860 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003861 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003862 ps_load_modulus := 0,
3863 ps_wait_cong := false,
3864 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003865 exp_load_ind := true,
3866 exp_overload := false,
3867 use_tmsi := false
3868 };
3869 var PagingTestState st := f_TC_paging(cfg);
3870 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003871 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3872 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003873 } else {
3874 setverdict(pass);
3875 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003876 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003877}
3878
3879/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3880 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3881 * - that CCCH LOAD IND (PCH) are being generated
3882 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3883testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003884 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003885 var PagingTestCfg cfg := {
3886 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003887 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003888 load_factor := 0.8,
Philipp Maierca058272021-06-23 10:35:23 +02003889 ps_load_modulus := 0,
3890 ps_wait_cong := false,
3891 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003892 exp_load_ind := true,
3893 exp_overload := false,
3894 use_tmsi := true
3895 };
3896 var PagingTestState st := f_TC_paging(cfg);
3897 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3899 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003900 } else {
3901 setverdict(pass);
3902 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003903 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003904}
3905
3906/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3907 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3908 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3909 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3910testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003911 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003912 var PagingTestCfg cfg := {
3913 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003914 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003915 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02003916 ps_load_modulus := 0,
3917 ps_wait_cong := false,
3918 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003919 exp_load_ind := true,
3920 exp_overload := true,
3921 use_tmsi := false
3922 };
3923 var PagingTestState st := f_TC_paging(cfg);
3924 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3925 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003926 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003927 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003928 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 +01003929 } else {
3930 setverdict(pass);
3931 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003932 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003933}
3934
3935/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3936 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3937 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3938 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3939testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003940 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003941 var PagingTestCfg cfg := {
3942 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003943 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003944 load_factor := 2.0,
Philipp Maierca058272021-06-23 10:35:23 +02003945 ps_load_modulus := 0,
3946 ps_wait_cong := false,
3947 queue_drain_timeout := 18.0,
Harald Welte68e495b2018-02-25 00:05:57 +01003948 exp_load_ind := true,
3949 exp_overload := true,
3950 use_tmsi := true
3951 };
3952 var PagingTestState st := f_TC_paging(cfg);
3953 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3954 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003955 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003956 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003957 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 +01003958 } else {
3959 setverdict(pass);
3960 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003962}
3963
Philipp Maierca058272021-06-23 10:35:23 +02003964/* Same as above, but with additional paging load created by PS pagings that
3965 * are issued through the PCU socket. The additional load is introduced when
3966 * the paging queue is already two thirds full. Since the BTS implements a
3967 * prioritization logic that drops the pagings from the PCU under in those
3968 * congestive sitautions the behaviour on the PS side is expected to be
3969 * unaffected and match the behavior of TC_paging_imsi_200percent() */
3970testcase TC_paging_imsi_200percent_with_ps() runs on test_CT {
3971 var SystemInformation si3 := valueof(ts_SI3_default);
3972 var PagingTestCfg cfg := {
3973 combined_ccch := true,
3974 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
3975 load_factor := 2.0,
3976 ps_load_modulus := 16,
3977 ps_wait_cong := true,
3978 queue_drain_timeout := 18.0,
3979 exp_load_ind := true,
3980 exp_overload := true,
3981 use_tmsi := false
3982 };
3983 var PagingTestState st := f_TC_paging(cfg);
3984 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3985 * slots and will fully drain that buffer before returning */
3986 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
3987 if (not match(st.num_paging_rcv_ids, tpl)) {
3988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
3989 } else {
3990 setverdict(pass);
3991 }
3992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3993}
3994
3995
Harald Welte68e495b2018-02-25 00:05:57 +01003996
Harald Welte93640c62018-02-25 16:59:33 +01003997/***********************************************************************
3998 * Immediate Assignment / AGCH
3999 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07004000private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02004001 len := 0,
4002 ma := ''B
4003}
Harald Welte93640c62018-02-25 16:59:33 +01004004
Harald Weltee8d750e2018-06-10 21:41:35 +02004005private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
4006 return int2str(num_tx) & " sent, "
4007 & int2str(num_rx) & " received, "
4008 & int2str(num_del) & " deleted";
4009}
4010
4011private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
4012 var L1ctlDlMessage l1_dl;
4013 timer T := 10.0;
4014 var integer num_tx := 0;
4015 var integer num_rx := 0;
4016 var integer num_del := 0;
4017 var charstring res_str;
4018 var float rx_ratio;
4019
Harald Welte10474062019-05-30 16:48:17 +02004020 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02004021 f_init_l1ctl();
4022 f_l1_tune(L1CTL);
4023
4024 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07004025 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07004026 mp_trx_pars[0].arfcn,
4027 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02004028 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
4029 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004030 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02004031 num_tx := num_tx+1;
4032 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01004033 }
4034 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02004035 T.start;
4036 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004037 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02004038 num_del := num_del+1;
4039 repeat;
4040 }
4041 [] RSL_CCHAN.receive {
4042 repeat;
4043 }
4044 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02004045 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
4046 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
4047 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004048 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02004049 } else {
4050 num_rx := num_rx+1;
4051 }
4052 repeat;
4053 }
4054 [] L1CTL.receive { repeat; }
4055 [] T.timeout { }
4056 }
4057 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
4058 log("AGCH test: " & res_str);
4059 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02004061 }
4062 rx_ratio := int2float(num_rx) / int2float(num_tx);
4063 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004064 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 +02004065 } else {
4066 setverdict(pass);
4067 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004069}
4070
Harald Weltee8d750e2018-06-10 21:41:35 +02004071/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
4072testcase TC_imm_ass_1000_20ms() runs on test_CT {
4073 f_TC_imm_ass(1000, 0.02, 0.25);
4074}
4075
4076/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
4077testcase TC_imm_ass_200_0ms() runs on test_CT {
4078 f_TC_imm_ass(200, 0.0, 0.05);
4079}
4080
4081/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
4082testcase TC_imm_ass_200_76ms() runs on test_CT {
4083 f_TC_imm_ass(150, 0.076, 1.00);
4084}
4085
4086
4087
Harald Welte48494ca2018-02-25 16:59:50 +01004088/***********************************************************************
4089 * BCCH
4090 ***********************************************************************/
4091
4092/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004093private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01004094 GsmFrameNumber frame_number,
4095 SystemInformation si
4096}
4097
4098/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004099private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01004100
4101/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004102private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01004103
4104/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004105private function f_si_vecslot_contains(SystemInformationVector arr,
4106 RrMessageType key,
4107 boolean bcch_ext := false)
4108return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004109 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4110 var integer fn_mod51 := arr[i].frame_number mod 51;
4111 if (not bcch_ext and fn_mod51 == 2 or
4112 bcch_ext and fn_mod51 == 6) {
4113 if (arr[i].si.header.message_type == key) {
4114 return true;
4115 }
4116 }
4117 }
4118 return false;
4119}
4120
4121/* 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 +07004122private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
4123 integer tc, RrMessageType key,
4124 boolean ext_bcch := false)
4125{
Harald Welte48494ca2018-02-25 16:59:50 +01004126 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004127 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004128 }
4129}
4130
4131/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004132private function f_si_vec_contains(SystemInformationVectorPerTc arr,
4133 RrMessageType key)
4134return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004135 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
4136 if (f_si_vecslot_contains(arr[tc], key) or
4137 f_si_vecslot_contains(arr[tc], key, true)) {
4138 return true;
4139 }
4140 }
4141 return false;
4142}
4143
4144/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004145private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
4146 RrMessageType key,
4147 boolean bcch_ext := false,
4148 integer n := 1, integer m := 4)
4149return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004150 var integer count := 0;
4151 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02004152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
4153 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01004154 }
4155 for (var integer i:= 0; i < m; i := i + 1) {
4156 var integer fn_mod51 := arr[i].frame_number mod 51;
4157 if (not bcch_ext and fn_mod51 == 2 or
4158 bcch_ext and fn_mod51 == 6) {
4159 if (arr[i].si.header.message_type == key) {
4160 count := count + 1;
4161 }
4162 }
4163 }
4164 if (count >= n) {
4165 return true;
4166 } else {
4167 return false;
4168 }
4169}
4170
4171/* 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 +07004172private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
4173 integer tc, RrMessageType key,
4174 boolean ext_bcch := false,
4175 integer n, integer m)
4176{
Harald Welte48494ca2018-02-25 16:59:50 +01004177 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004178 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004179 }
4180}
4181
4182/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004183private function f_si_vecslot_contains_only(SystemInformationVector arr,
4184 RrMessageType key,
4185 boolean bcch_ext := false)
4186return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01004187 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
4188 var integer fn_mod51 := arr[i].frame_number mod 51;
4189 if (not bcch_ext and fn_mod51 == 2 or
4190 bcch_ext and fn_mod51 == 6) {
4191 if (arr[i].si.header.message_type != key) {
4192 return false;
4193 }
4194 }
4195 }
4196 return true;
4197}
4198
4199/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004200private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
4201 integer tc, RrMessageType key,
4202 boolean ext_bcch := false)
4203{
Harald Welte48494ca2018-02-25 16:59:50 +01004204 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01004206 }
4207}
4208
4209/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004210private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01004211 boolean bcch_extended,
4212 boolean si1_present,
4213 boolean si2bis_present,
4214 boolean si2ter_present,
4215 boolean si2quater_present,
4216 boolean si7_present,
4217 boolean si8_present,
4218 boolean si9_present,
4219 boolean si13_present,
4220 boolean si13alt_present,
4221 boolean si15_present,
4222 boolean si16_present,
4223 boolean si17_present,
4224 boolean si2n_present,
4225 boolean si21_present,
4226 boolean si22_present
4227}
4228
4229/* 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 +07004230private function f_validate_si_scheduling(SystemInformationConfig cfg,
4231 SystemInformationVectorPerTc si_per_tc)
4232{
Harald Welte48494ca2018-02-25 16:59:50 +01004233 var integer i;
4234 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4235 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004237 }
4238 }
4239 if (cfg.si1_present) {
4240 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4241 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4242 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4243 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4244 /* make sure *ALL* contain SI1 */
4245 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4246 }
4247 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4248 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4249 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4250 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4251 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4252 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4253
4254 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4255 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4256 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4257 * consecutive occurrences of TC = 4. */
4258 if (cfg.si2bis_present and not cfg.si2ter_present) {
4259 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4260 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4261 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4262 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4263 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4264 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4265 }
4266
4267 if (cfg.si7_present or cfg.si8_present) {
4268 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4269 * if System Information type 4 does not contain all information needed for cell
4270 * selection and reselection. */
4271 if (not cfg.bcch_extended) {
4272 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4273 }
4274 if (cfg.si7_present) {
4275 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4276 }
4277 if (cfg.si8_present) {
4278 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4279 }
4280 }
4281
4282 if (cfg.si2quater_present) {
4283 /* iii) System information type 2 quater is sent if needed, as determined by the system
4284 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4285 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4286 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4287 * within any of 4 consecutive occurrences of TC = 5. */
4288 if (not (cfg.bcch_extended)) {
4289 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4290 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4291 } else {
4292 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4293 }
4294 } else {
4295 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4296 }
4297 }
4298 if (cfg.si9_present) {
4299 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4300 * in system information type 3 as defined in 3GPP TS 44.018. */
4301 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4302 }
4303 if (cfg.si13_present) {
4304 /* vii) System Information type 13 is only related to the GPRS service. System Information
4305 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4306 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4307 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4308 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4309 * within any of 4 consecutive occurrences of TC=4. */
4310 if (not cfg.bcch_extended) {
4311 log("not-bccch-extended");
4312 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4313 } else {
4314 log("bccch-extended");
4315 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4316 }
4317 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004319 }
4320 }
4321 if (cfg.si16_present or cfg.si17_present) {
4322 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4323 * should not be sent in a cell where network sharing is used (see rule xv). */
4324 if (cfg.si22_present) {
4325 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4326 }
4327 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004329 }
4330 if (not cfg.bcch_extended) {
4331 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4332 }
4333 if (cfg.si16_present) {
4334 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4335 }
4336 if (cfg.si17_present) {
4337 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4338 }
4339 }
4340
4341 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4342 * broadcast information. The frequency with which they are sent is determined by the
4343 * system operator. System Information type 9 identifies the scheduling of System
4344 * Information type 18 and 20 messages. */
4345
4346 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4347 * Information Type 19 is present, then its scheduling shall be indicated in System
4348 * Information Type 9. */
4349
4350 if (cfg.si15_present) {
4351 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4352 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4353 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4354 * 4 consecutive occurrences of TC = 1. */
4355 if (not cfg.bcch_extended) {
4356 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4357 } else {
4358 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4359 }
4360 }
4361 if (cfg.si13alt_present) {
4362 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4363 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4364 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4365 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4366 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4367 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4368 * of TC = 4. */
4369 if (cfg.si13_present) {
4370 testcase.stop("Error: Cannot have SI13alt and SI13");
4371 }
4372 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004373 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004374 }
4375 if (not cfg.bcch_extended) {
4376 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4377 } else {
4378 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4379 }
4380 }
4381 if (cfg.si2n_present) {
4382 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4383 * as determined by the system operator. In the case that the message is sent on the
4384 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4385 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4386 * consecutive occurrences of TC = 4. */
4387 if (not cfg.bcch_extended) {
4388 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4389 } else {
4390 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4391 }
4392 }
4393 if (cfg.si21_present) {
4394 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4395 * determined by the system operator. If Extended Access Barring is in use in the cell
4396 * then this message is sent at least once within any of 4 consecutive occurrences of
4397 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4398 * cell then this message shall only be sent on BCCH Ext. */
4399 if (not cfg.bcch_extended) {
4400 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4401 } else {
4402 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4403 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004404 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004405 }
4406 }
4407 }
4408 if (cfg.si22_present) {
4409 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4410 * should not be sent in a cell where SoLSA is used (see rule viii). System
4411 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4412 * =2 and TC=6. */
4413 if (cfg.si16_present or cfg.si17_present) {
4414 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4415 }
4416 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4417 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004419 }
4420 if (not cfg.bcch_extended) {
4421 testcase.stop("Error: SI22 requires BCCH Extd!");
4422 } else {
4423 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4424 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4425 }
4426 }
4427}
4428
4429/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004430private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4431return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004432 timer T := duration;
4433 var SystemInformationVectorPerTc si_per_tc;
4434 var L1ctlDlMessage l1_dl;
4435
4436 /* initialize all per-TC vectors empty */
4437 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4438 si_per_tc[i] := {};
4439 }
4440
4441 /* flush all previous L1 queued msgs */
4442 pt.clear;
4443
4444 T.start;
4445 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004446 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004447 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4448 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4449 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004450 repeat;
4451 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004452
Harald Welte48494ca2018-02-25 16:59:50 +01004453 var integer tc := f_gsm_compute_tc(sig.frame_number);
4454 log("SI received at TC=", tc, ": ", sig.si);
4455 /* append to the per-TC bucket */
4456 si_per_tc[tc] := si_per_tc[tc] & { sig };
4457 repeat;
4458 }
4459 [] pt.receive { repeat; }
4460 [] T.timeout { }
4461 }
4462
4463 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4464 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4465 }
4466 log("si_per_tc=", si_per_tc);
4467 return si_per_tc;
4468}
4469
4470/* helper function: Set given SI via RSL + validate scheduling.
4471 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004472private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004473 var SystemInformationVectorPerTc si_per_tc;
4474 f_init_l1ctl();
4475 f_l1_tune(L1CTL);
4476
4477 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004478 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004479 f_validate_si_scheduling(si_cfg, si_per_tc);
4480
4481 setverdict(pass);
4482}
4483
4484testcase TC_si_sched_default() runs on test_CT {
4485 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004486 /* 2+3+4 are mandatory and set in f_init() */
4487 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004488 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004489}
4490
4491testcase TC_si_sched_1() runs on test_CT {
4492 f_init();
4493 si_cfg.si1_present := true;
4494 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004495 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004496 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004497}
4498
4499testcase TC_si_sched_2bis() runs on test_CT {
4500 f_init();
4501 si_cfg.si2bis_present := true;
4502 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4503 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004505}
4506
4507testcase TC_si_sched_2ter() runs on test_CT {
4508 f_init();
4509 si_cfg.si2ter_present := true;
4510 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4511 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004513}
4514
4515testcase TC_si_sched_2ter_2bis() runs on test_CT {
4516 f_init();
4517 si_cfg.si2bis_present := true;
4518 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4519 si_cfg.si2ter_present := true;
4520 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4521 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004523}
4524
4525testcase TC_si_sched_2quater() runs on test_CT {
4526 f_init();
4527 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004528 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004529 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004530 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004531}
4532
4533testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004534 /* NOTE: PCUIF connection is not used in this test case, but
4535 * without it the IUT would not broadcast SI13 (see OS#3075). */
4536 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004537 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004538 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004539 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004541}
4542
4543testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004544 /* NOTE: PCUIF connection is not used in this test case, but
4545 * without it the IUT would not broadcast SI13 (see OS#3075). */
4546 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004547 si_cfg.si2bis_present := true;
4548 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4549 si_cfg.si2ter_present := true;
4550 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4551 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004552 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004553 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004554 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004555 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004556 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004557}
4558
4559
Harald Welte68e495b2018-02-25 00:05:57 +01004560testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004561 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004562 /* FIXME: enable / disable individual BCCH info */
4563 //ts_RSL_BCCH_INFO(si_type, info);
4564 /* expect no ERROR REPORT after either of them *
4565 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004567}
4568
Harald Welte93640c62018-02-25 16:59:33 +01004569/***********************************************************************
4570 * Low-Level Protocol Errors / ERROR REPORT
4571 ***********************************************************************/
4572
Harald Welte01d982c2018-02-25 01:31:40 +01004573private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4574 timer T := 5.0;
4575 T.start;
4576 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004577 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004578 setverdict(pass);
4579 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004580 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004582 }
4583 [] RSL_CCHAN.receive {
4584 repeat;
4585 }
4586 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004587 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004588 }
4589 }
4590}
4591
4592/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4593testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004594 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004595 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4596 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004597 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004598
4599 f_exp_err_rep(RSL_ERR_PROTO);
4600}
4601
4602/* Provoke a mandatory IE error and match on ERROR REPORT */
4603testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004604 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004605
4606 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4607 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004608 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004609
4610 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4611}
4612
4613/* Provoke an IE content error and match on ERROR REPORT */
4614testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004615 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004616 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4617 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004618 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004619
4620 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4621}
4622
Harald Welteee25aae2019-05-19 14:32:37 +02004623/* attempt to activate channel with wrong RSL Message Discriminator IE */
4624function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4625 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4626 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4627 RSL.send(rsl);
4628 f_rslem_unregister(0, g_chan_nr);
4629}
4630testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4631 var ConnHdlr vc_conn;
4632 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4633
Harald Welte10474062019-05-30 16:48:17 +02004634 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004635
4636 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4637 vc_conn.done;
4638 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4639
4640 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4641}
4642
4643/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004644private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004645 var template (value) RSL_Message rsl_tx;
4646 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4647 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4648 RSL.send(rsl_tx);
4649 f_rslem_unregister(0, g_chan_nr);
4650}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004651private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004652 var template (value) RSL_Message rsl_tx;
4653 /* we first have to activate the dedicated channel */
4654 f_rsl_chan_act(g_pars.chan_mode);
4655 /* ... to then send an invalid RLL message */
4656 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4657 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4658 RSL.send(rsl_tx);
4659 f_rslem_unregister(0, g_chan_nr);
4660}
4661testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4662 var ConnHdlr vc_conn;
4663 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4664 var template (value) RSL_Message rsl_tx;
4665
Harald Welte10474062019-05-30 16:48:17 +02004666 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004667
4668 /* Common Channel with wrong message type */
4669 RSL_CCHAN.clear;
4670 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4671 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004672 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004673 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4674
4675 /* TRX Management */
4676 RSL_CCHAN.clear;
4677 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4678 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004679 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004680 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4681
4682 /* Dedicated Channel */
4683 RSL_CCHAN.clear;
4684 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4685 vc_conn.done;
4686 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4687
4688 /* RLL */
4689 RSL_CCHAN.clear;
4690 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4691 vc_conn.done;
4692 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4693}
4694
4695/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004696private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004697 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4698 f_rslem_unregister(0, g_chan_nr);
4699}
4700testcase TC_err_rep_wrong_sequence() runs on test_CT {
4701 var ConnHdlr vc_conn;
4702 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4703
Harald Welte10474062019-05-30 16:48:17 +02004704 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004705
4706 RSL_CCHAN.clear;
4707 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4708 vc_conn.done;
4709 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4710}
4711
Harald Welte93640c62018-02-25 16:59:33 +01004712/***********************************************************************
4713 * IPA CRCX/MDCX/DLCS media stream handling
4714 ***********************************************************************/
4715
Harald Weltea871a382018-02-25 02:03:14 +01004716/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004717private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004718 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4719 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004720}
4721testcase TC_ipa_dlcx_not_active() runs on test_CT {
4722 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004723 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004724 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4725 vc_conn.done;
4726}
Harald Welte68e495b2018-02-25 00:05:57 +01004727
Harald Weltea3f1df92018-02-25 12:49:55 +01004728/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004729private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004730 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4731 "IPA CRCX ACK");
4732 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4733 "IPA CRCX NACK");
4734}
4735testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4736 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004737 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004738 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4739 vc_conn.done;
4740}
4741
4742/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004743private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004744 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4745 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004746 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Weltea3f1df92018-02-25 12:49:55 +01004747 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4748 var uint7_t rtp_pt2 := f_rnd_int(127);
4749 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4750 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4751 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4752 "IPA MDCX ACK");
4753 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4754 "IPA DLCX ACK");
4755}
4756testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4757 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004758 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004759 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4760 vc_conn.done;
4761}
4762
Harald Welte3ae11da2018-02-25 13:36:06 +01004763/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004764private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004765 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4766 "IPA CRCX ACK");
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004767 var OCT4 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004768 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4769 var uint7_t rtp_pt2 := f_rnd_int(127);
4770 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4771 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4772 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4773 "IPA MDCX ACK");
4774 /* Second MDCX */
Vadim Yanitskiyfc631642021-07-03 02:42:45 +02004775 remote_ip := f_rnd_octstring(4);
Harald Welte3ae11da2018-02-25 13:36:06 +01004776 remote_port := f_rnd_int(c_UINT16_MAX);
4777 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4778 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4779 "IPA MDCX ACK");
4780 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4781 "IPA DLCX ACK");
4782}
4783testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4784 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004785 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004786 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4787 vc_conn.done;
4788}
4789
Harald Welte9912eb52018-02-25 13:30:15 +01004790/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004791private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004792 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4793 "IPA CRCX NACK");
4794}
4795testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4796 var ConnHdlrPars pars;
4797 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004798 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004799
4800 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4801 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4802 vc_conn.done;
4803
4804 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4805 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4806 vc_conn.done;
4807}
4808
Harald Weltea3f1df92018-02-25 12:49:55 +01004809
Harald Welte883340c2018-02-28 18:59:29 +01004810/***********************************************************************
4811 * PCU Socket related tests
4812 ***********************************************************************/
4813
Harald Welte07bd2d22019-05-25 11:03:30 +02004814/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004815friend 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 +01004816runs on test_CT {
4817 timer T := 3.0;
4818
4819 /* we don't expect any RTS.req before PDCH are active */
4820 T.start;
4821 alt {
4822 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004824 }
4825 [] PCU.receive { repeat; }
4826 [] T.timeout { }
4827 }
4828
4829 /* Send PDCH activate request for known PDCH timeslot */
4830 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4831
4832 /* we now expect RTS.req for this timeslot (only) */
4833 T.start;
4834 alt {
4835 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4836 setverdict(pass);
4837 }
4838 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4839 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004840 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004841 }
4842 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004844 }
4845 [] PCU.receive { repeat; }
4846 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004848 }
4849 [not exp_success] T.timeout {
4850 setverdict(pass);
4851 }
4852 }
4853}
4854
Harald Welte07bd2d22019-05-25 11:03:30 +02004855/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004856friend 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 +01004857runs on test_CT {
4858 timer T := 3.0;
4859
4860 /* Send PDCH activate request for known PDCH timeslot */
4861 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 +02004862 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4863 * when it will actually have been executed in the BTS */
4864 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004865 PCU.clear;
4866 /* we now expect no RTS.req for this timeslot */
4867 T.start;
4868 alt {
4869 [] 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 +02004870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004871 }
4872 [] PCU.receive { repeat; }
4873 [] T.timeout {
4874 setverdict(pass);
4875 }
4876 }
4877}
4878
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004879friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004880 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004881 map(self:PCU, system:PCU);
4882 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01004883 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4884}
4885
Harald Welte883340c2018-02-28 18:59:29 +01004886/* PDCH activation via PCU socket; check for presence of RTS.req */
4887testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004888 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004889
Harald Welte883340c2018-02-28 18:59:29 +01004890 f_TC_pcu_act_req(0, 0, 7, true);
4891}
4892
4893/* PDCH activation via PCU socket on non-PDCU timeslot */
4894testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004895 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004896
Harald Welte883340c2018-02-28 18:59:29 +01004897 f_TC_pcu_act_req(0, 0, 1, false);
4898}
4899
4900/* PDCH activation via PCU socket on wrong BTS */
4901testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004902 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004903
Harald Welte883340c2018-02-28 18:59:29 +01004904 f_TC_pcu_act_req(23, 0, 7, false);
4905}
4906
4907/* PDCH activation via PCU socket on wrong TRX */
4908testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004909 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004910
Harald Welte883340c2018-02-28 18:59:29 +01004911 f_TC_pcu_act_req(0, 23, 7, false);
4912}
4913
4914/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4915testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004916 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004917
Harald Welte883340c2018-02-28 18:59:29 +01004918 /* Activate PDCH */
4919 f_TC_pcu_act_req(0, 0, 7, true);
4920 f_sleep(1.0);
4921 /* and De-Activate again */
4922 f_TC_pcu_deact_req(0, 0, 7);
4923}
4924
4925/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4926testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004927 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004928
Harald Welte883340c2018-02-28 18:59:29 +01004929 f_TC_pcu_deact_req(0, 0, 1);
4930}
4931
4932/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01004933function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01004934 var PCUIF_send_data sd;
4935 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004936 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01004937
4938 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01004939 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01004940
Harald Welte883340c2018-02-28 18:59:29 +01004941 T.start;
4942 alt {
4943 [] 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 +01004944 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01004945 setverdict(pass);
4946 } else {
4947 repeat;
4948 }
4949 }
4950 [] PCU.receive { repeat; }
4951 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01004952 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01004953 }
4954 }
4955}
4956
Philipp Maier94c08482021-02-01 17:36:05 +01004957/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
4958testcase TC_pcu_ver_si1() runs on test_CT {
4959 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
4960 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
4961}
4962
4963/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
4964testcase TC_pcu_ver_si3() runs on test_CT {
4965 const octetstring si3 := '49012223242526272929AABBCC'O;
4966 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
4967}
4968
4969/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4970testcase TC_pcu_ver_si13() runs on test_CT {
4971 const octetstring si13 := '01010203040506070909'O;
4972 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
4973}
4974
Harald Welte883340c2018-02-28 18:59:29 +01004975private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4976
4977/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004978friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004979 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4980runs on test_CT
4981{
4982 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4983 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4984}
4985
4986/* 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 +02004987friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4988 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004989runs on test_CT
4990{
4991 var PCUIF_send_data sd;
4992
4993 timer T := 3.0;
4994 T.start;
4995 alt {
4996 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4997 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4998 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4999 sd.data.u.rts_req.fn, sapi, data);
5000 }
5001 [] PCU.receive { repeat; }
5002 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005003 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01005004 }
5005 }
5006}
5007
5008/* Send DATA.req on invalid BTS */
5009testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005010 var TfiUsfArr tua := f_TfiUsfArrInit();
5011 var octetstring data := '0000'O & f_rnd_octstring(21);
5012
5013 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005014
Harald Welte883340c2018-02-28 18:59:29 +01005015 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005016 f_TfiUsfArrSet(tua, 7, 0);
5017 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5018 f_sleep(1.0);
5019
5020 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005021}
5022
5023/* Send DATA.req on invalid TRX */
5024testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005025 var TfiUsfArr tua := f_TfiUsfArrInit();
5026 var octetstring data := '0000'O & f_rnd_octstring(21);
5027
5028 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005029
Harald Welte883340c2018-02-28 18:59:29 +01005030 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005031 f_TfiUsfArrSet(tua, 7, 0);
5032 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5033 f_sleep(1.0);
5034
5035 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005036}
5037
5038/* Send DATA.req on invalid timeslot */
5039testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005040 var TfiUsfArr tua := f_TfiUsfArrInit();
5041 var octetstring data := '0000'O & f_rnd_octstring(21);
5042
5043 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005044
Harald Welte883340c2018-02-28 18:59:29 +01005045 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02005046 f_TfiUsfArrSet(tua, 7, 0);
5047 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5048 f_sleep(1.0);
5049
5050 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005051}
5052
5053/* Send DATA.req on timeslot that hasn't been activated */
5054testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02005055 var TfiUsfArr tua := f_TfiUsfArrInit();
5056 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01005057
Harald Welte7162a612019-05-26 12:56:09 +02005058 f_virtphy_common();
5059
5060 f_TfiUsfArrSet(tua, 7, 0);
5061 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5062 f_sleep(1.0);
5063
5064 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01005065}
5066
Harald Weltead033dc2019-05-25 17:28:16 +02005067private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02005068 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
5069 boolean wait_rts := true)
5070runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005071 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02005072 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02005073
5074 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02005075 if (wait_rts) {
5076 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
5077 } else {
5078 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
5079 }
Harald Weltead033dc2019-05-25 17:28:16 +02005080
5081 T.start;
5082 alt {
Harald Welte7162a612019-05-26 12:56:09 +02005083 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02005084 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
5085 setverdict(pass);
5086 }
Harald Welte7162a612019-05-26 12:56:09 +02005087 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
5088 setverdict(fail, "Received unexpected ", rx_dl);
5089 }
Harald Weltead033dc2019-05-25 17:28:16 +02005090 [] L1CTL.receive {
5091 repeat;
5092 }
Harald Welte7162a612019-05-26 12:56:09 +02005093 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02005094 setverdict(fail, "Timeout waiting for ", data);
5095 }
Harald Welte7162a612019-05-26 12:56:09 +02005096 [not expect_data] T.timeout {
5097 setverdict(pass);
5098 }
Harald Weltead033dc2019-05-25 17:28:16 +02005099 }
5100}
5101
5102private function f_disable_dynamic_ts() runs on test_CT
5103{
5104 f_init_vty_bsc();
5105 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
5106 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
5107 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
5108 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005109 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02005110}
5111
5112private function f_virtphy_common() runs on test_CT {
5113 f_disable_dynamic_ts();
5114 f_init_l1ctl();
5115 f_l1_tune(L1CTL);
5116}
5117
5118testcase TC_pcu_data_req_pdtch() runs on test_CT {
5119 var TfiUsfArr tua := f_TfiUsfArrInit();
5120 var octetstring data := '0000'O & f_rnd_octstring(21);
5121
5122 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005123
Harald Welte883340c2018-02-28 18:59:29 +01005124 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005125 f_TfiUsfArrSet(tua, 7, 0);
5126 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5127 f_sleep(1.0);
5128
5129 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01005130}
5131
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005132/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01005133testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02005134 var TfiUsfArr tua := f_TfiUsfArrInit();
5135 var octetstring data := '0000'O & f_rnd_octstring(21);
5136
5137 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01005138
Harald Welte883340c2018-02-28 18:59:29 +01005139 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02005140 f_TfiUsfArrSet(tua, 7, 0);
5141 f_L1CTL_TBF_CFG(L1CTL, false, tua);
5142 f_sleep(1.0);
5143
5144 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01005145}
5146
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005147private function f_TC_pcu_ptcch_ul(uint16_t ra)
5148runs on test_CT {
5149 var template PCUIF_Message pcu_rach_ind;
5150 var PCUIF_send_data sd;
5151 var GsmFrameNumber fn;
5152 timer T;
5153
5154 /* Send an Access Burst on PTCCH/U over the Um-interface */
5155 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
5156 chan_nr := ts_RslChanNr_PDCH(7),
5157 link_id := ts_RslLinkID_OSMO_PTCCH(0));
5158
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005159 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
5160 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005161
5162 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
5163 T.start(52.0 * 4.615 / 1000.0);
5164 alt {
5165 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
5166 log("Rx an Access Burst on the PCU interface: ", sd.data);
5167 setverdict(pass);
5168 T.stop;
5169 }
5170 [] PCU.receive { repeat; }
5171 [] T.timeout {
5172 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
5173 /* Keep going, that's not the end of the world */
5174 }
5175 }
5176}
5177
5178testcase TC_pcu_ptcch() runs on test_CT {
5179 var L1ctlDlMessage dl;
5180 var octetstring data;
5181 timer T;
5182
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005183 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005184 f_init_l1ctl();
5185 f_l1_tune(L1CTL);
5186
5187 /* Activate PDCH channel on TS7 */
5188 f_TC_pcu_act_req(0, 0, 7, true);
5189
5190 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005191 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005192 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005193 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005194 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07005195
5196 /* Verify PTCCH/U: send several access bursts, make sure they're received */
5197 for (var integer i := 0; i < 16; i := i + 1) {
5198 log("Sending an Access Burst towards the L1CTL interface");
5199 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
5200 }
5201
5202 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
5203 data := f_rnd_octstring(23);
5204
5205 /* Verify PTCCH/D: send a random data block, make sure it's received */
5206 log("Sending a PTCCH/D block towards the PCU interface: ", data);
5207 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
5208
5209 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
5210 * let's give it more time in case if we miss the beginning. */
5211 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
5212 alt {
5213 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
5214 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
5215 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5216 frame := data)) -> value dl {
5217 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
5218 setverdict(pass);
5219 T.stop;
5220 }
5221 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
5222 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5223 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5224 l2_data := data)) -> value dl {
5225 log("Rx PTCCH/D data block on L1CTL: ", dl);
5226 setverdict(pass);
5227 T.stop;
5228 }
5229 [] L1CTL.receive { repeat; }
5230 [] T.timeout {
5231 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5232 }
5233 }
5234}
5235
Harald Welte883340c2018-02-28 18:59:29 +01005236/* Send AGCH from PCU; check it appears on Um side */
5237testcase TC_pcu_data_req_agch() runs on test_CT {
5238 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005239 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005240 f_init_l1ctl();
5241 f_l1_tune(L1CTL);
5242
5243 f_TC_pcu_act_req(0, 0, 7, true);
5244 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5245
5246 T.start;
5247 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005248 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005249 setverdict(pass);
5250 }
5251 [] L1CTL.receive { repeat; }
5252 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005254 }
5255 }
5256}
5257
Harald Welte928622b2019-05-26 13:22:59 +02005258/* Send AGCH from PCU; check it appears on Um side */
5259testcase TC_pcu_data_req_pch() runs on test_CT {
5260 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005261 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005262 f_init_l1ctl();
5263 f_l1_tune(L1CTL);
5264
5265 f_TC_pcu_act_req(0, 0, 7, true);
5266 /* three characters prefix: last 3 digits of IMSI as ASCII */
5267 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5268
5269 T.start;
5270 alt {
5271 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5272 setverdict(pass);
5273 }
5274 [] L1CTL.receive { repeat; }
5275 [] T.timeout {
5276 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5277 }
5278 }
5279}
5280
Harald Welte883340c2018-02-28 18:59:29 +01005281/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5282testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5283 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005284 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005285 f_init_l1ctl();
5286 f_l1_tune(L1CTL);
5287
5288 /* append 3 last imsi digits so BTS can compute pagng group */
5289 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5290
5291 timer T := 0.5;
5292 T.start;
5293 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005294 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005295 /* TODO: verify paging group */
5296 setverdict(pass);
5297 }
5298 [] L1CTL.receive { repeat; }
5299 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005300 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005301 }
5302 }
5303}
5304
5305/* Send RACH from Um side, expect it to show up on PCU socket */
5306testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005307 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005308 f_init_l1ctl();
5309 f_l1_tune(L1CTL);
5310
5311 var GsmFrameNumber fn_last := 0;
5312 for (var integer i := 0; i < 1000; i := i+1) {
5313 var OCT1 ra := f_rnd_ra_ps();
5314 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5315 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005317 }
5318 fn_last := fn;
5319
5320 timer T := 2.0;
5321 T.start;
5322 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005323 [] 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 +01005324 T.stop;
5325 }
5326 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005327 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005328 }
5329 [] PCU.receive { repeat; }
5330 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005331 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005332 }
5333 }
5334 }
5335 setverdict(pass);
5336}
5337
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005338/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5339 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5340testcase TC_pcu_ext_rach_content() runs on test_CT {
5341 var template PCUIF_Message pcu_rach_ind;
5342 var GsmFrameNumber fn_last := 0;
5343 var L1ctlRachSynchSeq synch_seq;
5344 var PCUIF_BurstType pcu_bt;
5345 var GsmFrameNumber fn;
5346 var BIT11 ra11;
5347
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005348 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005349 f_init_l1ctl();
5350 f_l1_tune(L1CTL);
5351
5352 for (var integer i := 0; i < 1000; i := i+1) {
5353 /* We need to test both TS1 & TS2 */
5354 if (i rem 2 == 0) {
5355 synch_seq := RACH_SYNCH_SEQ_TS1;
5356 pcu_bt := BURST_TYPE_1;
5357 } else {
5358 synch_seq := RACH_SYNCH_SEQ_TS2;
5359 pcu_bt := BURST_TYPE_2;
5360 }
5361
5362 ra11 := f_rnd_ra11_ps();
5363 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5364 if (fn == fn_last) {
5365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5366 "Two RACH in same FN?!?");
5367 }
5368 fn_last := fn;
5369
5370 /* Compose the expected message */
5371 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005372 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005373 ra := bit2int(ra11),
5374 is_11bit := 1,
5375 burst_type := pcu_bt,
5376 fn := fn);
5377
5378 timer T := 2.0;
5379 T.start;
5380 alt {
5381 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5382 T.stop;
5383 }
5384 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5386 }
5387 [] PCU.receive { repeat; }
5388 [] T.timeout {
5389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5390 }
5391 }
5392 }
5393 setverdict(pass);
5394}
5395
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005396private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5397runs on test_CT {
5398 var template PCUIF_send_data sdt;
5399 var PCUIF_send_data sd;
5400 var int16_t lqual_cb;
5401 timer T := 1.0;
5402
5403 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5404 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5405
5406 /* Send a random PDTCH frame over Um */
5407 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5408 '0000'O & f_rnd_octstring(21)));
5409
5410 T.start;
5411 alt {
5412 /* If expected link quality is above the threshold */
5413 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5414 lqual_cb := sd.data.u.data_ind.lqual_cb;
5415 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5416
5417 /* Make sure the actual link quality matches the expected value */
5418 if (not match(lqual_cb, lqual_cb_exp)) {
5419 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5420 "expected value ", lqual_cb_exp));
5421 } else {
5422 setverdict(pass);
5423 }
5424 }
5425 /* If expected link quality is below the threshold */
5426 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5428 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5429 }
5430 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5431 [] PCU.receive { repeat; }
5432 [lqual_cb_exp < thresh] T.timeout {
5433 log("Rx nothing, as expected");
5434 setverdict(pass);
5435 }
5436 [lqual_cb_exp >= thresh] T.timeout {
5437 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5438 "Timeout waiting for PCUIF_DATA.ind");
5439 }
5440 }
5441}
5442
5443/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5444testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005445 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005446 PCU.clear;
5447
5448 f_init_l1ctl();
5449 f_l1_tune(L1CTL);
5450
5451 /* Activate a PDCH channel on TS7 */
5452 f_TC_pcu_act_req(0, 0, 7, true);
5453
5454 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005455 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005456 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005457 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005458 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005459
5460 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5461 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5462 var TrxcMessage ret;
5463
Vadim Yanitskiy418066a2021-10-03 14:04:17 +06005464 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, ts_TRXC_FAKE_CI(i));
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005465
5466 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5467 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5468 }
5469}
5470
Harald Welte883340c2018-02-28 18:59:29 +01005471/* Send PAGING via RSL, expect it to shw up on PCU socket */
5472testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005473 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005474
5475 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005476 var MobileIdentityLV mi_lv;
5477 var octetstring mi_lv_enc;
5478 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005479 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005480
Harald Welte883340c2018-02-28 18:59:29 +01005481 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005482 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005483 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005484 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005485 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005486
5487 /* Fancy encoding for PCUIF */
5488 mi_lv := valueof(ts_MI_LV(mi));
5489 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5490 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005491
5492 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005493 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005494 T.start;
5495 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005496 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005497 }
5498 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005499 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005500 }
5501 [] PCU.receive { repeat; }
5502 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005503 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005504 }
5505 }
5506 }
5507 setverdict(pass);
5508}
5509
Harald Welted66c9b82019-05-25 09:03:15 +02005510/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5511testcase TC_pcu_time_ind() runs on test_CT {
5512 var PCUIF_send_data pcu_sd;
5513 var integer num_time_ind := 0;
5514 var integer first_fn, last_fn;
5515 var float test_duration := 5.0;
5516 timer T;
5517
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005518 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005519 f_TC_pcu_act_req(0, 0, 7, true);
5520
5521 PCU.clear;
5522 T.start(test_duration);
5523 alt {
5524 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5525 num_time_ind := num_time_ind + 1;
5526 if (not isbound(first_fn)) {
5527 first_fn := pcu_sd.data.u.time_ind.fn;
5528 }
5529 last_fn := pcu_sd.data.u.time_ind.fn;
5530 repeat;
5531 }
5532 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5533 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5534 repeat;
5535 }
5536 [] PCU.receive {
5537 repeat;
5538 }
5539 [] T.timeout {}
5540 }
5541 var integer fn_expired := last_fn - first_fn;
5542 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5543
5544 /* verify the number of frames expired matches our expectation */
5545 const float c_GSM_FN_DURATION_MS := 4.61538;
5546 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005547 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005548 if (not match(fn_expired, t_fn_expected)) {
5549 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5550 }
5551
5552 /* There are three TIME.ind in every fn MOD 13 */
5553 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5554 /* Add some tolerance */
5555 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5556 if (not match(num_time_ind, t_time_ind_exp)) {
5557 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5558 }
5559
5560 setverdict(pass);
5561}
5562
Harald Welte4832c862019-05-25 14:57:18 +02005563/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5564testcase TC_pcu_rts_req() runs on test_CT {
5565 var PCUIF_send_data pcu_sd;
5566 var integer first_fn, last_fn;
5567 var integer num_rts_pdtch := 0;
5568 var integer num_rts_ptcch := 0;
5569 var float test_duration := 5.0;
5570 timer T;
5571
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005572 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005573 f_TC_pcu_act_req(0, 0, 7, true);
5574
5575 PCU.clear;
5576 T.start(test_duration);
5577 alt {
5578 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5579 -> value pcu_sd {
5580 num_rts_pdtch := num_rts_pdtch + 1;
5581 if (not isbound(first_fn)) {
5582 first_fn := pcu_sd.data.u.rts_req.fn;
5583 }
5584 last_fn := pcu_sd.data.u.rts_req.fn;
5585 repeat;
5586 }
5587 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5588 -> value pcu_sd {
5589 num_rts_ptcch := num_rts_ptcch + 1;
5590 if (not isbound(first_fn)) {
5591 first_fn := pcu_sd.data.u.rts_req.fn;
5592 }
5593 last_fn := pcu_sd.data.u.rts_req.fn;
5594 repeat;
5595 }
5596 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5597 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5598 repeat;
5599 }
5600 [] PCU.receive {
5601 repeat;
5602 }
5603 [] T.timeout {}
5604 }
5605 var integer fn_expired := last_fn - first_fn;
5606 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5607 ", num_rts_ptcch=", num_rts_ptcch);
5608
5609 /* verify the number of frames expired matches our expectation */
5610 const float c_GSM_FN_DURATION_MS := 4.61538;
5611 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005612 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005613 if (not match(fn_expired, t_fn_expected)) {
5614 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5615 }
5616
5617 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5618 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5619 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5620 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5621 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5622 t_ptcch_exp);
5623 }
5624
5625 /* We have 12 PDTCH blocks every 52-multiframe */
5626 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5627 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5628 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5629 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5630 t_pdtch_exp);
5631 }
5632
5633 setverdict(pass);
5634}
5635
Harald Welte07bd2d22019-05-25 11:03:30 +02005636/* test for generating Abis side OML ALERT from the PCU */
5637testcase TC_pcu_oml_alert() runs on test_CT {
5638 var PCUIF_send_data pcu_sd;
5639 var integer num_time_ind := 0;
5640 var integer first_fn, last_fn;
5641 var float test_duration := 5.0;
5642 timer T;
5643
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005644 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005645 f_TC_pcu_act_req(0, 0, 7, true);
5646
5647 /* re-connect CTRL port from BTS to BSC */
5648 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005649 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005650
5651 /* Send that OML Alert */
5652 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5653
5654 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5655 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5656 setverdict(pass);
5657}
5658
Harald Welteeaa9a862019-05-26 23:01:08 +02005659/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5660private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5661 var PCUIF_Message first_info;
5662 var integer pcu_conn_id := -1;
5663 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5664 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5665 var OCT4 tlli := '01020304'O;
5666 var OCT1 cause := '23'O;
5667 timer T := 5.0;
5668
5669 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5670
5671 f_l1_tune(L1CTL);
5672 RSL.clear;
5673
5674 f_est_dchan();
5675 L1CTL.clear;
5676
5677 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5678
5679 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5680 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5681 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5682
5683 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5684 T.start;
5685 alt {
5686 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5687 setverdict(pass);
5688 }
5689 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5690 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5691 }
5692 [] PCU.receive {
5693 repeat;
5694 }
5695 [] T.timeout {
5696 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5697 }
5698 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005699
5700 /* release the channel */
5701 f_rsl_chan_deact();
5702 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5703 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005704}
5705testcase TC_pcu_rr_suspend() runs on test_CT {
5706 var ConnHdlrPars pars;
5707 var ConnHdlr vc_conn;
5708
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005709 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005710
5711 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5712 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5713 vc_conn.done;
5714}
Harald Welte07bd2d22019-05-25 11:03:30 +02005715
Harald Weltea2e0e942019-05-27 18:12:53 +02005716/* Ensure that PCUIF socket can accept only a single connection */
5717testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005718 var boolean connected := false;
5719 var UD_connect_result cr;
5720 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005721 timer T := 5.0;
5722
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005723 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5724 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5725
Harald Weltea2e0e942019-05-27 18:12:53 +02005726 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005727 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005728
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005729 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005730 PCU.send(UD_connect:{mp_pcu_socket, -1});
5731 T.start;
5732 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005733 /* the IUT will first accept() the new connection, and close() it immediately */
5734 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5735 log("BTS has accept()ed connection");
5736 connected := true;
5737 cid := cr.id;
5738 repeat;
5739 }
5740 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5741 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005742 setverdict(pass);
5743 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005744 /* ignore other messages related to the first connection */
5745 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005746 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005747 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005748 }
5749 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005750
Harald Weltea2e0e942019-05-27 18:12:53 +02005751 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5752}
5753
Harald Weltec8effb72019-05-27 18:23:04 +02005754/* Ensure that PCUIF socket can disconnect + reconnect */
5755testcase TC_pcu_socket_reconnect() runs on test_CT {
5756 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005757 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005758
5759 f_sleep(1.0);
5760
5761 f_pcuif_close(PCU, g_pcu_conn_id);
5762 g_pcu_conn_id := -1;
5763
5764 f_sleep(1.0);
5765
5766 /* re-connect */
5767 PCU.clear;
5768 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5769 setverdict(pass);
5770
5771 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5772}
5773
Harald Weltebe030482019-05-27 22:29:35 +02005774/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005775private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5776runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005777 var L1ctlDlMessage l1_dl;
5778 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005779 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005780 timer T := 5.0;
5781 T.start;
5782 alt {
5783 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005784 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5785 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005786 repeat;
5787 }
5788 }
5789 [] pt.receive {
5790 repeat;
5791 }
5792 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005793 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5794 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005795 }
5796 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005797 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005798}
5799
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005800/* Check if GPRS Indicator is present in RR System Information of a given type */
5801private function f_si_has_gprs_indicator(RrMessageType si_type)
5802runs on test_CT return boolean {
5803 var SystemInformation si := f_get_si(L1CTL, si_type);
5804
5805 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005806 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005807 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005808 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005809 }
5810
5811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5812 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005813}
5814
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005815/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5816private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5817runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005818 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02005819 f_init_l1ctl();
5820 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005821 f_sleep(2.0);
5822 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005823
5824 if (f_si_has_gprs_indicator(si_type)) {
5825 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005826 } else {
5827 setverdict(pass);
5828 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005829
Harald Weltebe030482019-05-27 22:29:35 +02005830 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5831}
5832
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005833testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5834 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5835}
Harald Weltebe030482019-05-27 22:29:35 +02005836
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005837testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5838 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5839}
5840
5841/* Ensure that GPRS capability is advertised after PCU socket connect */
5842private function f_TC_pcu_socket_connect(RrMessageType si_type)
5843runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005844 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005845 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005846 f_init_l1ctl();
5847 f_l1_tune(L1CTL);
5848
5849 f_sleep(2.0);
5850 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005851
5852 if (not f_si_has_gprs_indicator(si_type)) {
5853 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005854 } else {
5855 setverdict(pass);
5856 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005857
Harald Weltebe030482019-05-27 22:29:35 +02005858 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5859}
5860
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005861testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5862 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5863}
Harald Weltebe030482019-05-27 22:29:35 +02005864
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005865testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5866 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5867}
5868
5869/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5870private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5871runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005872 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005873 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005874 f_init_l1ctl();
5875 f_l1_tune(L1CTL);
5876
5877 f_pcuif_close(PCU, g_pcu_conn_id);
5878 g_pcu_conn_id := -1;
5879
5880 f_sleep(1.0);
5881
5882 /* re-connect */
5883 PCU.clear;
5884 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5885
5886 f_sleep(2.0);
5887 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005888
5889 if (f_si_has_gprs_indicator(si_type)) {
5890 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005891 } else {
5892 setverdict(pass);
5893 }
5894
5895 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5896}
5897
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005898testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5899 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5900}
5901
5902testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5903 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5904}
5905
Oliver Smithf5239c72019-08-28 10:01:25 +02005906/* 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) */
5907testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5908 var SystemInformation si3 := valueof(ts_SI3_default);
5909
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005910 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02005911
Harald Welte76220222020-10-11 20:32:44 +02005912 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5913 * information */
5914 timer T := 2.0;
5915 T.start;
5916 alt {
5917 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5918 [] T.timeout {}
5919 }
5920
Oliver Smithf5239c72019-08-28 10:01:25 +02005921 /* Verify cell_id */
5922 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5923 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5924 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005925 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5926 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5927 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005928 }
5929
5930 /* Verify LAC */
5931 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5932 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5933 if (lac_si3 != lac_pcu) {
5934 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5935 }
5936
5937 setverdict(pass);
5938}
Harald Welted66c9b82019-05-25 09:03:15 +02005939
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005940/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5941testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5942 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005943 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005944
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005945 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005946
5947 info_ind := g_pcu_last_info.u.info_ind;
5948
5949 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5950 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005951 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005952 /* Skip inactive timeslots */
5953 continue;
5954 }
5955
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005956 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005957 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005958 else
5959 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005960
5961 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005962 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005963 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005964 hsn := fhp.maio_hsn.hsn,
5965 maio := fhp.maio_hsn.maio,
5966 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005967 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005968 } else {
5969 tr_ts := tr_PCUIF_InfoTrxTsH0;
5970 }
5971
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005972 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005973 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5974 if (not match(ts, tr_ts)) {
5975 setverdict(fail, "Hopping parameters do not match: ",
5976 "received ", ts, " vs expected ", tr_ts);
5977 } else {
5978 setverdict(pass);
5979 }
5980 }
5981 }
5982}
5983
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005984/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02005985testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5986 f_init_vty_bsc();
5987 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5988 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5989
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005990 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02005991
5992 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005993 var template PCUIF_RemoteAddr tr_remote_addr := {
5994 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01005995 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005996 };
Alexander Couzens5283f552020-07-28 15:39:04 +02005997
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005998 if (not match(remote_addr, tr_remote_addr)) {
5999 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006000 }
6001
6002 setverdict(pass);
6003}
6004
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006005/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02006006testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
6007 f_init_vty_bsc();
6008 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
6009
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01006010 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02006011
6012 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006013 var template PCUIF_RemoteAddr tr_remote_addr := {
6014 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
6015 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
6016 };
Alexander Couzens5283f552020-07-28 15:39:04 +02006017
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006018 if (not match(remote_addr, tr_remote_addr)) {
6019 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02006020 }
6021
6022 setverdict(pass);
6023}
6024
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006025/* Verify coding of two NSVCs in the INFO.ind message */
6026testcase TC_pcu_socket_two_nsvc() runs on test_CT {
6027 f_init_vty_bsc();
6028
6029 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
6030 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
6031 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
6032 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
6033
6034 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
6035 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
6036 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
6037 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
6038
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01006039 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006040
6041 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
6042 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
6043 var template PCUIF_RemoteAddr tr_remote_addr := {
6044 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01006045 addr := {
6046 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
6047 f_inet6_addr("fd00::ca:ff:ee")
6048 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01006049 };
6050
6051 if (not match(info_ind.nsvci, { 1234, 5678 }))
6052 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
6053 if (not match(remote_addr, tr_remote_addr))
6054 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
6055 if (not match(info_ind.local_port, { 1234, 5678 }))
6056 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
6057 if (not match(info_ind.remote_port, { 1234, 5678 }))
6058 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
6059
6060 setverdict(pass);
6061}
6062
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02006063/* Verify periodic interference reports on PDCH */
6064testcase TC_pcu_interf_ind() runs on test_CT {
6065 var template PCUIF_Message tr_interf_ind;
6066 var template PCUIF_interf ts_interf;
6067 var integer interf_ind_num := 0;
6068 var PCUIF_send_data sd;
6069 timer T;
6070
6071 f_init_with_pcuif();
6072 f_TC_pcu_act_req(0, 0, 7, true);
6073
6074 /* We need trxcon for NOPE indications */
6075 f_init_l1ctl();
6076 f_l1_tune(L1CTL);
6077
6078 /* Expect -120 .. -90 dBm on TS7 of BTS0/TRX0 */
6079 ts_interf := { 0, 0, 0, 0, 0, 0, 0, (90..120) };
6080 tr_interf_ind := tr_PCUIF_INTERF_IND(
6081 bts_nr := 0,
6082 trx_nr := 0,
6083 fn := ?,
6084 interf := ts_interf
6085 );
6086
6087 /* 4 SACCH periods => 4 reports (plus some guard time) */
6088 var float Tval := int2float(4 * 480) / 1000.0 + 0.5;
6089
6090 /* Let it some time to stabilize */
6091 f_sleep(0.5);
6092 PCU.clear;
6093
6094 T.start(Tval);
6095 alt {
6096 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_interf_ind)) -> value sd {
6097 /* Check TDMA frame number period */
6098 if (sd.data.u.interf_ind.fn mod 104 != 0) {
6099 setverdict(fail, "Odd TDMA frame number := ",
6100 sd.data.u.interf_ind.fn);
6101 }
6102 interf_ind_num := interf_ind_num + 1;
6103 if (interf_ind_num < 4)
6104 { repeat; }
6105 }
6106 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_INTERF_IND(0, 0))) -> value sd {
6107 setverdict(fail, "Received unexpected interference report: ", sd.data);
6108 }
6109 [] PCU.receive { repeat; }
6110 [] T.timeout {
6111 setverdict(fail, "Timeout waiting for interference reports");
6112 }
6113 }
6114
6115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6116}
6117
Harald Welte3d04ae62018-04-04 20:29:05 +02006118/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02006119 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02006120 ***********************************************************************/
6121
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006122private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
6123 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02006124runs on ConnHdlr {
6125 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006126
6127 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01006128 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006129 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
6130 repeat;
6131 }
6132 }
6133}
6134
6135private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6136runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006137 /* Expect BTS to immediately acknowledge activation as PDCH */
6138 PCU.clear;
6139 f_rsl_chan_act(g_pars.chan_mode);
6140 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006141 timer T_wait := 2.0;
6142 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006143 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006144 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006145 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006146 [] T_wait.timeout {
6147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6148 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6149 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006150 }
6151 /* try to activate this PDCH from the PCU point of view */
6152 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6153 /* FIXME: is there a response? */
6154}
6155
6156private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6157runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006158 /* Send RSL CHAN REL (deactivate) */
6159 PCU.clear;
6160 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6161 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006162 timer T_wait := 2.0;
6163 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02006164 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006165 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02006166 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02006167 [] T_wait.timeout {
6168 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6169 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6170 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006171 }
6172 /* Emulate PCU asking BTS to deactivate PDCH */
6173 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6174 alt {
6175 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
6176 setverdict(pass);
6177 }
6178 [] RSL.receive { repeat; }
6179 }
6180}
6181
6182/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006183private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006184 var PCUIF_Message first_info;
6185 var integer ts_nr := g_chan_nr.tn;
6186 var integer trx_nr := 0;
6187 var integer bts_nr := 0;
6188 var integer pcu_conn_id := -1;
6189
6190 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6191
6192 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6193 f_sleep(3.0);
6194 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6195 setverdict(pass);
6196}
6197testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
6198 var ConnHdlrPars pars;
6199 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006200 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006201
6202 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6203 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
6204 vc_conn.done;
6205}
6206
6207/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006208private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006209 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02006210 var integer pcu_conn_id := -1;
6211
6212 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6213
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02006214 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
6215 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
6216 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02006217 setverdict(pass);
6218}
6219testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
6220 var ConnHdlrPars pars;
6221 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006222 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006223
6224 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6225 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
6226 vc_conn.done;
6227}
6228
6229/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006230private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006231 var PCUIF_Message first_info;
6232 var integer ts_nr := g_chan_nr.tn;
6233 var integer trx_nr := 0;
6234 var integer bts_nr := 0;
6235 var integer pcu_conn_id := -1;
6236
6237 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6238
6239 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02006240 /* Send a second Chan Activ and expect it to be NACKed */
6241 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6242 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02006243 setverdict(pass);
6244}
6245testcase TC_dyn_osmo_pdch_double_act() 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_double_act), pars, true);
6252 vc_conn.done;
6253}
6254
6255/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006256private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006257 var PCUIF_Message first_info;
6258 var integer ts_nr := g_chan_nr.tn;
6259 var integer trx_nr := 0;
6260 var integer bts_nr := 0;
6261 var integer pcu_conn_id := -1;
6262 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
6263
6264 /* register for the TCH/F channel number */
6265 f_rslem_register(0, chan_nr);
6266
6267 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6268
6269 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
6270 "RSL CHAN ACT");
6271 setverdict(pass);
6272}
6273testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
6274 var ConnHdlrPars pars;
6275 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006276 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006277
6278 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6279 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6280 vc_conn.done;
6281}
6282
6283/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006284private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006285 var PCUIF_Message first_info;
6286 var integer ts_nr := g_chan_nr.tn;
6287 var integer trx_nr := 0;
6288 var integer bts_nr := 0;
6289 var integer pcu_conn_id := -1;
6290 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6291 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6292
6293 /* register for the TCH/H channel numbers */
6294 f_rslem_register(0, chan_nr[0]);
6295 f_rslem_register(0, chan_nr[1]);
6296
6297 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6298
6299 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6300 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6301 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6302 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6303 setverdict(pass);
6304}
6305testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6306 var ConnHdlrPars pars;
6307 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006308 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006309
6310 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6311 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6312 vc_conn.done;
6313}
6314
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02006315/* try to RSL CHAN ACT the SDCCH8 on an osmocom-style PDCH */
6316private function f_TC_dyn_osmo_pdch_sdcch8_act(charstring id) runs on ConnHdlr {
6317 var PCUIF_Message first_info;
6318 var integer ts_nr := g_chan_nr.tn;
6319 var integer trx_nr := 0;
6320 var integer bts_nr := 0;
6321 var integer pcu_conn_id := -1;
6322 var RslChannelNr chan_nr[8] := { valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 0)),
6323 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 1)),
6324 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 2)),
6325 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 3)),
6326 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 4)),
6327 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 5)),
6328 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 6)),
6329 valueof(t_RslChanNr_SDCCH8(g_chan_nr.tn, 7)) };
6330
6331 /* register for the TCH/H channel numbers */
6332 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6333 f_rslem_register(0, chan_nr[i]);
6334 }
6335
6336 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6337
6338 for (var integer i := 0; i < lengthof(chan_nr); i := i + 1) {
6339 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[i], g_pars.chan_mode),
6340 tr_RSL_CHAN_ACT_ACK(chan_nr[i]), "RSL CHAN ACT [" & int2str(i) & "]");
6341 }
6342 setverdict(pass);
6343}
6344testcase TC_dyn_osmo_pdch_sdcch8_act() runs on test_CT {
6345 var ConnHdlrPars pars;
6346 var ConnHdlr vc_conn;
6347 f_init();
6348
6349 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6350 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_sdcch8_act), pars, true);
6351 vc_conn.done;
6352}
6353
Vadim Yanitskiy64043d82021-10-03 15:00:20 +06006354/* Reproduce a race condition described in OS#5245 */
6355private function f_rsl_chan_act_deact(charstring id) runs on ConnHdlr {
6356 f_rsl_chan_act(g_pars.chan_mode);
6357 f_sleep(1.0);
6358 f_rsl_chan_deact();
6359 setverdict(pass);
6360}
6361testcase TC_dyn_osmo_pdch_tchh_race_act() runs on test_CT {
6362 var ConnHdlrPars pars[2];
6363 var ConnHdlr vc_conn[2];
6364 var TrxcMessage rsp;
6365
6366 f_init();
6367
6368 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6369 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6370 ts_TRXC_FAKE_TRXC_DELAY(200));
6371
6372 /* Activate all sub-channels of TCH/H on TS4 immediately in hope that the second
6373 * CHANnel ACTIVation message will be handled before the PHY responds to 'SETSLOT' */
6374 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6375 /* TS4 is an Osmocom style dynamic timeslot, we want it to be TCH/H */
6376 pars[i] := valueof(t_Pars(t_RslChanNr_Lm(4, i), ts_RSL_ChanMode_SIGN));
6377 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6378 pars[i], l1ctl := false);
6379 }
6380
6381 /* Wait for all components to finish */
6382 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6383 vc_conn[i].done;
6384 }
6385
6386 /* Disable the artificial delay for TRXC RSP messages */
6387 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6388 ts_TRXC_FAKE_TRXC_DELAY(0));
6389}
6390testcase TC_dyn_osmo_pdch_sdcch8_race_act() runs on test_CT {
6391 var ConnHdlrPars pars[8];
6392 var ConnHdlr vc_conn[8];
6393 var TrxcMessage rsp;
6394
6395 f_init();
6396
6397 /* Configure an artificial delay of 200 ms for TRXC RSP messages */
6398 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6399 ts_TRXC_FAKE_TRXC_DELAY(200));
6400
6401 /* Activate all sub-channels of SDCCH/8 on TS4 immediately in hope that subsequent
6402 * CHANnel ACTIVation messages will be handled before the PHY responds to 'SETSLOT' */
6403 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6404 /* TS4 is an Osmocom style dynamic timeslot, we want it to be SDCCH/8 */
6405 pars[i] := valueof(t_Pars(t_RslChanNr_SDCCH8(4, i), ts_RSL_ChanMode_SIGN));
6406 vc_conn[i] := f_start_handler(refers(f_rsl_chan_act_deact),
6407 pars[i], l1ctl := false);
6408 }
6409
6410 /* Wait for all components to finish */
6411 for (var integer i := 0; i < sizeof(pars); i := i + 1) {
6412 vc_conn[i].done;
6413 }
6414
6415 /* Disable the artificial delay for TRXC RSP messages */
6416 rsp := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
6417 ts_TRXC_FAKE_TRXC_DELAY(0));
6418}
6419
Harald Welte9bbbfb52018-04-05 09:33:19 +02006420/***********************************************************************
6421 * IPA Style Dynamic Timeslot Support
6422 ***********************************************************************/
6423
6424private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6425runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006426 /* Expect BTS to immediately acknowledge activation as PDCH */
6427 PCU.clear;
6428 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6429 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006430 timer T_wait := 2.0;
6431 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006432 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006433 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006434 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006435 [] T_wait.timeout {
6436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6437 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6438 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006439 }
6440 /* try to activate this PDCH from the PCU point of view */
6441 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6442 /* FIXME: is there a response? */
6443
6444 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6445}
6446
6447private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6448runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006449 /* Send RSL CHAN REL (deactivate) */
6450 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6451 PCU.clear;
6452 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006453 timer T_wait := 2.0;
6454 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006455 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006456 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006457 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006458 [] T_wait.timeout {
6459 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6460 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6461 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006462 }
6463 /* Emulate PCU asking BTS to deactivate PDCH */
6464 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6465 alt {
6466 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6467 setverdict(pass);
6468 }
6469 [] RSL.receive { repeat; }
6470 }
6471}
6472
6473/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006474private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006475 var PCUIF_Message first_info;
6476 var integer ts_nr := g_chan_nr.tn;
6477 var integer trx_nr := 0;
6478 var integer bts_nr := 0;
6479 var integer pcu_conn_id := -1;
6480
6481 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6482
6483 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6484 f_sleep(3.0);
6485 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6486
6487 setverdict(pass);
6488
6489}
6490testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6491 var ConnHdlrPars pars;
6492 var ConnHdlr vc_conn;
6493 f_init();
6494
6495 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6496 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6497 vc_conn.done;
6498}
6499
6500/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006501private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006502 var PCUIF_Message first_info;
6503 var integer ts_nr := g_chan_nr.tn;
6504 var integer trx_nr := 0;
6505 var integer bts_nr := 0;
6506 var integer pcu_conn_id := -1;
6507
6508 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6509
6510 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6511 "RSL CHAN ACT");
6512 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6513 "RF CHAN REL", true);
6514 setverdict(pass);
6515}
6516testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6517 var ConnHdlrPars pars;
6518 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006519 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006520
6521 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6522 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6523 vc_conn.done;
6524}
6525
6526/* 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 +07006527private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006528 var PCUIF_Message first_info;
6529 var integer ts_nr := g_chan_nr.tn;
6530 var integer trx_nr := 0;
6531 var integer bts_nr := 0;
6532 var integer pcu_conn_id := -1;
6533
6534 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6535
6536 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6537 "RSL CHAN ACT");
6538
6539 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6540 alt {
6541 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6542 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006544 }
6545 [] RSL.receive { repeat; }
6546 }
6547
6548 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6549 "RF CHAN REL", true);
6550 setverdict(pass);
6551}
6552testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6553 var ConnHdlrPars pars;
6554 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006555 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006556
6557 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6558 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6559 vc_conn.done;
6560}
6561
6562/* 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 +07006563private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006564 var PCUIF_Message first_info;
6565 var integer ts_nr := g_chan_nr.tn;
6566 var integer trx_nr := 0;
6567 var integer bts_nr := 0;
6568 var integer pcu_conn_id := -1;
6569
6570 /* register for the TCH/F channel number */
6571 f_rslem_register(0, g_chan_nr);
6572
6573 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6574
6575 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6576
6577 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6578 "RSL CHAN ACT");
6579
6580 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6581
6582 setverdict(pass);
6583}
6584testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6585 var ConnHdlrPars pars;
6586 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006587 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006588
6589 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6590 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6591 vc_conn.done;
6592}
6593
6594
Harald Welte0472ab42018-03-12 15:02:26 +01006595/***********************************************************************
6596 * LAPDm / RLL related
6597 ***********************************************************************/
6598
6599private function f_tx_lapdm(template (value) LapdmFrame l,
6600 template (value) RslLinkId link_id) runs on ConnHdlr {
6601 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006602 var template (value) SacchL1Header l1h;
6603
6604 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006605 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006606 /* Compose dummy L1 header */
6607 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6608 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 +02006609 } else {
6610 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006611 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 +01006612 }
Harald Welte0472ab42018-03-12 15:02:26 +01006613}
6614
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006615friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006616 uint3_t sapi,
6617 RslLinkId link_id,
6618 octetstring l3,
6619 boolean exp
6620}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006621friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006622friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6623 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006624 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006625 sapi := sapi,
6626 link_id := id,
6627 l3 := l3,
6628 exp := exp
6629}
6630
6631/* execute the same callback function with a set of different parameters (tcs) on a
6632 * variety of logical channels */
6633private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6634 var ConnHdlrPars pars;
6635 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006636 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006637
6638 /* test on each of the channels we have */
6639 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6640 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6641
6642 /* test each of the test cases on the current channel */
6643 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6644 pars.spec.rll := tcs[j];
6645 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6646 vc_conn := f_start_handler(fn, pars);
6647 vc_conn.done;
6648 }
6649 }
6650
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006651 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006652}
6653
6654/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6655private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6656 var RllTestCase tc := g_pars.spec.rll;
6657 timer T := 3.0;
6658
6659 f_l1_tune(L1CTL);
6660 RSL.clear;
6661
6662 /* activate the logical channel */
6663 f_est_dchan();
6664 L1CTL.clear;
6665
6666 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6667 T.start;
6668 alt {
6669 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6670 if (tc.exp) {
6671 setverdict(pass);
6672 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006674 }
6675 }
6676 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6677 if (tc.exp) {
6678 setverdict(pass);
6679 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006681 }
6682 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006683 /* We also expect to receive the measurements */
6684 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006685 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006687 }
6688 [not tc.exp] T.timeout {
6689 setverdict(pass);
6690 }
6691 }
6692
6693 f_rsl_chan_deact();
6694 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6695 f_rslem_unregister(0, g_chan_nr);
6696}
6697testcase TC_rll_est_ind() runs on test_CT {
6698 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006699 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006700 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006701 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006702 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006703 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006704 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6705 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006706 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006707 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006708 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006709 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006710 };
6711 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6712}
6713
6714/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6715private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6716 var RllTestCase tc := g_pars.spec.rll;
6717 var L1ctlDlMessage dl;
6718 timer T := 3.0;
6719
6720 f_l1_tune(L1CTL);
6721 RSL.clear;
6722
6723 /* activate the logical channel */
6724 f_est_dchan();
6725 L1CTL.clear;
6726
6727 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6728 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6729 T.start;
6730 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006731 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006732 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006733 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006734 }
6735 }
6736
6737 f_rsl_chan_deact();
6738 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6739 f_rslem_unregister(0, g_chan_nr);
6740}
6741testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6742 var RllTestCases tcs := {
6743 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006744 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006745 };
6746 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6747}
6748testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6749 var RllTestCases tcs := {
6750 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006751 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006752 }
6753 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6754}
6755
6756/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006757friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006758 var L1ctlDlMessage dl;
6759 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6760 var LapdmFrame lapdm;
6761 var octetstring l2 := dl.payload.data_ind.payload;
6762 if (dl.dl_info.link_id.c == SACCH) {
6763 /* remove L1 header */
6764 l2 := substr(l2, 2, lengthof(l2)-2);
6765 }
6766 if (ischosen(exp.ab)) {
6767 lapdm.ab := dec_LapdmFrameAB(l2);
6768 } else if (ischosen(exp.b4)) {
6769 lapdm.b4 := dec_LapdmFrameB4(l2);
6770 } else if (ischosen(exp.bbis)) {
6771 lapdm.bbis := dec_LapdmFrameBbis(l2);
6772 }
6773 log("Rx LAPDm ", lapdm);
6774 if (match(lapdm, exp)) {
6775 setverdict(pass);
6776 } else {
6777 repeat;
6778 }
6779 }
6780 [] L1CTL.receive { repeat; }
6781}
6782private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6783 timer T := t;
6784 T.start;
6785 alt {
6786 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006787 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006788 }
6789 [] as_l1_exp_lapdm(exp);
6790 }
6791}
6792
6793/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6794private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6795 /* send SABM from MS -> BTS */
6796 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6797 /* expect RLL EST IND on Abis */
6798 alt {
6799 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6800 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6801 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006802 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006803 }
6804 [] RSL.receive { repeat; }
6805 }
6806 /* expect UA from BTS -> MS */
6807 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6808}
6809
6810/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6811private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6812 var RllTestCase tc := g_pars.spec.rll;
6813
6814 f_l1_tune(L1CTL);
6815 RSL.clear;
6816
6817 /* activate the logical channel */
6818 f_est_dchan();
6819 L1CTL.clear;
6820
6821 /* first establish the link-layer */
6822 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6823
6824 /* then send the DISC */
6825 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6826 /* ... and expect the REL IND on the RSL side */
6827 alt {
6828 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6829 setverdict(pass);
6830 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006831 /* We also expect to receive the measurements */
6832 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006833 }
6834
6835 /* release the channel */
6836 f_rsl_chan_deact();
6837 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6838 f_rslem_unregister(0, g_chan_nr);
6839}
6840testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6841 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006842 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006843 };
6844 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6845}
6846
6847testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6848 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006849 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006850 };
6851 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6852}
6853testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6854 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006855 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006856 };
6857 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6858}
6859testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6860 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006861 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006862 };
6863 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6864}
6865
6866/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6867private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6868 var RllTestCase tc := g_pars.spec.rll;
6869 f_l1_tune(L1CTL);
6870 RSL.clear;
6871
6872 /* activate the logical channel */
6873 f_est_dchan();
6874 L1CTL.clear;
6875
6876 /* first establish the link-layer */
6877 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6878
6879 /* then send the REL REQ via RSL */
6880 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6881 /* ... and expect the DISC on the Um side */
6882 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006883 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006884 /* FIXME: send a UA in resposne to the DISC */
6885 }
6886 }
6887
6888 /* release the channel */
6889 f_rsl_chan_deact();
6890 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6891 f_rslem_unregister(0, g_chan_nr);
6892}
6893testcase TC_rll_rel_req() runs on test_CT {
6894 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006895 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
6896 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
6897 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
6898 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006899 };
6900 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6901}
6902
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006903/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006904testcase TC_rll_data_req() runs on test_CT {
6905}
6906
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006907/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006908testcase TC_rll_data_ind() runs on test_CT {
6909}
6910
6911/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6912private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6913 var RllTestCase tc := g_pars.spec.rll;
6914
6915 f_l1_tune(L1CTL);
6916 RSL.clear;
6917
6918 f_est_dchan();
6919 L1CTL.clear;
6920
6921 /* Send UNITDATA REQ on RSL side */
6922 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6923 /* Expect it to arrive on the other side */
6924 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006925 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006926 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006927 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006928 }
6929
6930 /* release the channel */
6931 f_rsl_chan_deact();
6932 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6933 f_rslem_unregister(0, g_chan_nr);
6934}
6935testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6936 var octetstring l3 := f_rnd_octstring(15);
6937 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006938 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6939 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006940 };
6941 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6942}
6943testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6944 var octetstring l3 := f_rnd_octstring(19);
6945 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006946 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6947 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006948 };
6949 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6950}
6951
6952/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6953private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6954 var RllTestCase tc := g_pars.spec.rll;
6955
6956 f_l1_tune(L1CTL);
6957 RSL.clear;
6958
6959 f_est_dchan();
6960 L1CTL.clear;
6961
6962 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006963 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006964 /* Expdct RLL UNITDATA IND on RSL side */
6965 alt {
6966 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6967 setverdict(pass);
6968 }
6969 [] RSL.receive { repeat; }
6970 }
6971
6972 /* release the channel */
6973 f_rsl_chan_deact();
6974 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6975 f_rslem_unregister(0, g_chan_nr);
6976}
6977testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006978 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006979 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006980 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6981 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006982 };
6983 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6984}
6985testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6986 var octetstring l3 := f_rnd_octstring(18);
6987 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006988 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6989 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006990 };
6991 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6992}
6993
Harald Weltee613f962018-04-18 22:38:16 +02006994/***********************************************************************
6995 * Encryption Related
6996 ***********************************************************************/
6997
6998/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006999private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007000 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
7001 if (link_id.c == SACCH) {
7002 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
7003 } else {
7004 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
7005 }
7006}
7007
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007008/* Expect (or not expect) other kinds of messages */
7009private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
7010 [exp_any] RSL.receive { repeat; }
7011 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007013 }
7014}
7015
Harald Weltee613f962018-04-18 22:38:16 +02007016/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07007017private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007018 RslLinkId link_id,
7019 octetstring l3,
7020 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007021 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07007022) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007023 timer T := 3.0;
7024 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
7025 T.start;
7026 /* Expect RLL UNITDATA IND on RSL side */
7027 alt {
7028 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
7029 setverdict(pass);
7030 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007031 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07007032 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02007033 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02007035 }
Harald Weltee613f962018-04-18 22:38:16 +02007036 }
7037}
7038
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007039/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
7040private function f_data_mo(
7041 RslLinkId link_id,
7042 boolean p, uint3_t nr, uint3_t ns,
7043 octetstring l3,
7044 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07007045 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007046) runs on ConnHdlr {
7047 timer T := 3.0;
7048 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
7049 T.start;
7050 /* Expect RLL DATA IND on RSL side */
7051 alt {
7052 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
7053 setverdict(pass);
7054 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07007055 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007056 [] as_rsl_any_ind(exp_any);
7057 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007058 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007059 }
7060 }
7061}
7062
Harald Weltee613f962018-04-18 22:38:16 +02007063/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007064private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007065 f_l1_tune(L1CTL);
7066 f_est_dchan(true);
7067
7068 /* now we actually need to transmit some data both ways to check if the encryption works */
7069 var L1ctlDlMessage dl;
7070
Stefan Sperling603d98e2018-07-25 16:47:28 +02007071 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02007072 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7073
7074 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7075 f_unitdata_mt(link_id, l3);
7076
7077 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7078 f_unitdata_mo(link_id, l3);
7079
7080 /* release the channel */
7081 f_rsl_chan_deact();
7082 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7083 f_rslem_unregister(0, g_chan_nr);
7084}
7085testcase TC_chan_act_a51() runs on test_CT {
7086 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7087 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7088 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7089}
7090testcase TC_chan_act_a52() runs on test_CT {
7091 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7092 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7093 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7094}
7095testcase TC_chan_act_a53() runs on test_CT {
7096 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7097 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7098 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7099}
Eric Wildb9260392021-05-15 19:48:22 +02007100testcase TC_chan_act_a54() runs on test_CT {
7101 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7102 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7103 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
7104}
Harald Weltee613f962018-04-18 22:38:16 +02007105
Eric Wildf1827a72019-05-28 17:37:35 +02007106/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
7107 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 +07007108private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02007109 f_l1_tune(L1CTL);
7110 f_est_dchan(true);
7111
7112 /* now we actually need to transmit some data both ways to check if the encryption works */
7113 var L1ctlDlMessage dl;
7114
7115 var octetstring l3 := f_rnd_octstring(20);
7116 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7117
7118 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
7119 f_unitdata_mt(link_id, l3);
7120
7121 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
7122 f_unitdata_mo(link_id, l3);
7123
7124 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007125 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02007126
7127 /* modify key to break proper encryption */
7128 g_pars.encr.key := f_rnd_octstring(8);
7129 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
7130 rsl.ies := rsl.ies & { ei };
7131 RSL.send(rsl);
7132
7133 timer T0 := 1.0;
7134 T0.start;
7135 /* Expect RSL MODIFY ACK */
7136 alt {
7137 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
7138 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
7139 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
7140 }
7141 [] T0.timeout {
7142 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
7143 }
7144 }
7145
7146 var octetstring l3msg := f_rnd_octstring(15);
7147 timer T1 := 3.0;
7148 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
7149 due to broken encryption */
7150 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
7151 T1.start;
7152 alt {
7153 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
7154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
7155 }
7156 [] T1.timeout {
7157 setverdict(pass);
7158 }
7159 }
7160
7161 /* release the channel */
7162 f_rsl_chan_deact();
7163 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7164 f_rslem_unregister(0, g_chan_nr);
7165}
7166testcase TC_rsl_modify_encr() runs on test_CT {
7167 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7168 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7169 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
7170}
Harald Weltee613f962018-04-18 22:38:16 +02007171
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007172/* Verify RF RESource INDication messages (periodically sent over the RSL) */
7173private function f_TC_rsl_rf_resource_ind(template RSL_ResourceInfo info)
7174runs on test_CT {
7175 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
7176 var ASP_RSL_Unitdata ud;
7177 timer T;
7178
7179 /* Intave is 6 SACCH periods by default */
7180 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
7181
7182 T.start(Tval);
7183 alt {
7184 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
7185 setverdict(pass);
7186 }
7187 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
7188 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
7189 }
7190 [] RSL_CCHAN.receive { repeat; }
7191 [] T.timeout {
7192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
7193 "Timeout waiting for RF RESource INDication");
7194 }
7195 }
7196}
7197testcase TC_rsl_rf_resource_ind() runs on test_CT {
7198 var RSL_ResourceInfo info := { };
7199
7200 f_init(trx_nr := 0);
7201
7202 f_init_l1ctl();
7203 f_l1_tune(L1CTL);
7204
7205 /* g_AllChannels contains all logical channels */
7206 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
7207 var RslChannelNr chan_nr := g_AllChannels[i];
7208
7209 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
7210 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
7211 { continue; }
7212
7213 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
7214 }
7215
7216 /* Align to the first interference report */
7217 f_TC_rsl_rf_resource_ind(?);
7218
7219 /* Test 4 consecutive messages */
7220 for (var integer i := 0; i < 4; i := i + 1) {
7221 f_TC_rsl_rf_resource_ind(info);
7222 }
7223
7224 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7225}
7226
Harald Weltee613f962018-04-18 22:38:16 +02007227/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007228private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02007229 /* L3 payload doesn't matter, as it is passed transparently */
7230 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
7231 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
7232 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
7233
7234 f_l1_tune(L1CTL);
7235
7236 /* first establish a dedicated channel in the clear */
7237 f_est_dchan(false);
7238
7239 /* Establish ABM */
7240 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
7241
7242 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
7243 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
7244 /* expect the L3 to arrive still unencrypted on the MS side */
7245 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
7246
7247 /* configure L1 to apply ciphering */
7248 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
7249 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
7250
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07007251 /* send first ciphered I-frame in response and expect it on RSL */
7252 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02007253
7254 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
7255 * and hence enable encryption also on the downlink */
7256
7257 /* expect bi-directional communication work in encrypted mode */
7258 f_unitdata_mo(link_id, f_rnd_octstring(15));
7259 f_unitdata_mt(link_id, f_rnd_octstring(15));
7260
7261 /* release the channel */
7262 f_rsl_chan_deact();
7263 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7264 f_rslem_unregister(0, g_chan_nr);
7265}
7266testcase TC_encr_cmd_a51() runs on test_CT {
7267 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7268 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
7269 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7270}
7271testcase TC_encr_cmd_a52() runs on test_CT {
7272 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7273 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
7274 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7275}
7276testcase TC_encr_cmd_a53() runs on test_CT {
7277 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7278 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
7279 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7280}
Eric Wildb9260392021-05-15 19:48:22 +02007281testcase TC_encr_cmd_a54() runs on test_CT {
7282 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7283 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
7284 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
7285}
Harald Weltee613f962018-04-18 22:38:16 +02007286
7287private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
7288 var LapdmFrame lf;
7289 var octetstring reenc;
7290
7291 /* decode the LAPDm frame */
7292 if (ischosen(exp_match.ab)) {
7293 lf.ab := dec_LapdmFrameAB(enc);
7294 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007295 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02007296 }
7297
7298 /* check if decoder result matches expectation */
7299 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007300 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007301 } else {
7302 log(name, ": matched");
7303 setverdict(pass);
7304 }
7305
7306 /* test if re-encoded frame equals original input */
7307 reenc := enc_LapdmFrame(lf);
7308 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007309 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02007310 } else {
7311 setverdict(pass);
7312 }
7313}
7314
7315testcase TC_lapdm_selftest() runs on test_CT {
7316 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
7317 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
7318 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
7319 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
7320 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
7321 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
7322 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
7323}
7324
Stefan Sperling4880be42018-08-07 18:12:59 +02007325/***********************************************************************
7326 * DTX Related (see GSM 05.08, section 8.3)
7327 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007328private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02007329 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02007330 var GsmFrameNumber first_fn;
7331 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007332 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007333 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02007334 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
7335 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007336 const integer frame_dtx_tchf_mod := 104;
7337 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
7338 * which operates in terms of blocks rather than frames. */
7339 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
7340 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02007341 timer T := 5.0;
7342
7343 f_l1_tune(L1CTL);
7344 RSL.clear;
7345 L1CTL.clear;
7346
7347 /* activate TCHF signalling channel */
7348 f_est_dchan(false);
7349
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007350 /* A template for matching dummy LAPDm func=UA frames */
7351 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
7352 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
7353 l2_data := f_pad_oct('030301'O, 23, '2B'O));
7354
Stefan Sperling4880be42018-08-07 18:12:59 +02007355 T.start;
7356 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007357 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02007358 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02007359
7360 if (is_first_frame) {
7361 is_first_frame := false;
7362 first_fn := dl.dl_info.frame_nr;
7363 }
7364
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007365 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007366 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007367 T.stop;
7368 f_rsl_chan_deact();
7369 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007370
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007371 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
7372 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007373
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007374 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007375 setverdict(fail, "Not enough fill frames received: ",
7376 nfill_frames, " out of ", expected_fill_frames);
7377 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007378 } else {
7379 setverdict(pass);
7380 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007381 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007382 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7383 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7384 * we should only see the subset of frames numbers which correspond to a block boundary.
7385 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7386 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7387 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007388 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007389 repeat;
7390 }
7391 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007392 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7393 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7394 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007395 f_rsl_chan_deact();
7396 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007397 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007398 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007399 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007400 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007401 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007402
7403 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007404 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7405 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007406 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7407 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7408 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007409 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7410 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007411 case else {
7412 /* This shall not happen, just to be sure */
7413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7414 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007415 }
7416
7417 f_rsl_chan_deact();
7418 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007419
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007420 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007421 setverdict(pass);
7422 } else {
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 }
7427 } else {
7428 repeat;
7429 }
7430 }
7431 }
7432 [] L1CTL.receive { repeat; }
7433 [] T.timeout {
7434 f_rsl_chan_deact();
7435 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007437 }
7438 }
7439}
7440
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007441private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007442 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007443 var ConnHdlr vc_conn;
7444 var ConnHdlrPars pars;
7445 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007446 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007447 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007448 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007449 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007450 if (dtxd) {
7451 if (i >= 4) { /* DTX is only allowed on TCH/F */
7452 break;
7453 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007454 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007455 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007456 vc_conn.done;
7457 }
7458}
7459
7460/* Verify that L2 fill frames are sent on TCH in signaling mode if
7461 * there is nothing to transmit while DTX is disabled on downlink. */
7462testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7463 f_tch_sign_l2_fill_frame(false);
7464}
7465
7466/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7467 * there is nothing to transmit while DTX is enabled on downlink. */
7468testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7469 f_tch_sign_l2_fill_frame(true);
7470}
Harald Welte0472ab42018-03-12 15:02:26 +01007471
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007472testcase TC_chopped_ipa_ping() runs on test_CT {
7473 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7474}
7475
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007476testcase TC_chopped_ipa_payload() runs on test_CT {
7477 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7478}
7479
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007480
7481/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7482 * Return value: Measurement Report to be sent (encoded octetstring). */
7483type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7484 runs on ConnHdlr return octetstring;
7485
7486private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7487runs on ConnHdlr {
7488 var L1ctlDlMessage l1_dl;
7489 var SacchL1Header l1h;
7490 var octetstring l2;
7491
7492 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7493 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7494 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7495 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7496
7497 /* Pass it to the user specified call-back function */
7498 l2 := cb.apply(l1h, num_blocks);
7499 /* Send a Measurement Report generated by the call-back */
7500 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7501 l1_dl.dl_info.link_id,
7502 l1h, l2));
7503
7504 /* Shall we keep going? */
7505 num_blocks := num_blocks - 1;
7506 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7507 if (num_blocks > 0) { repeat; }
7508 }
7509 [] L1CTL.receive { repeat; }
7510}
7511
7512private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7513runs on ConnHdlr return octetstring {
7514 /* Command the L1 to apply received parameters */
7515 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7516
7517 /* Dummy measurement report (the results are invalid) */
7518 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7519}
7520
7521private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7522runs on ConnHdlr return octetstring {
7523 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7524 setverdict(fail, "Unexpected MS Power level change: ",
7525 g_pars.l1_pars.ms_power_level, " -> ",
7526 l1h.ms_power_lvl);
7527 }
7528
7529 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7530}
7531
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007532private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7533runs on ConnHdlr return octetstring {
7534 /* UL RSSI oscillation driven by SACCH block number */
7535 if (num_blocks rem 2 == 0) {
7536 f_trxc_fake_rssi(-100);
7537 } else {
7538 f_trxc_fake_rssi(-50);
7539 }
7540
7541 /* Make sure that MS power level remains constant */
7542 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7543}
7544
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007545/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7546private function f_TC_ms_pwr_ctrl_constant(charstring id)
7547runs on ConnHdlr {
7548 var integer num_blocks := 8;
7549 timer T := int2float(num_blocks);
7550
7551 f_l1_tune(L1CTL);
7552 RSL.clear;
7553
7554 /* These IEs are needed for autonomous MS power control */
7555 var template (value) RSL_IE_List ies := {
7556 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7557 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7558 }),
7559 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7560 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7561 })
7562 };
7563
7564 /* Ensure that 'rx-current' equals 'rx-target' */
7565 f_trxc_fake_rssi(mp_uplink_power_target);
7566
7567 /* Establish a dedicated channel */
7568 f_est_dchan(more_ies := valueof(ies));
7569
7570 L1CTL.clear;
7571 T.start;
7572 alt {
7573 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7574 [] T.timeout {
7575 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7576 num_blocks, " were not handled");
7577 }
7578 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007579
7580 /* Release the channel */
7581 f_rsl_chan_deact();
7582 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007583}
7584testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7585 var ConnHdlr vc_conn;
7586 var ConnHdlrPars pars;
7587
7588 f_init();
7589
7590 /* Explicitly configure the Uplink power target (in dBm) */
7591 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7592
7593 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7594 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7595 log(testcasename(), ": starting on ", pars.chan_nr);
7596
7597 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7598 pars, trxc_comp := true);
7599 vc_conn.done;
7600 }
7601
7602 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7604}
7605
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007606/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7607private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7608runs on ConnHdlr {
7609 var integer num_blocks := 16;
7610 timer T := int2float(num_blocks);
7611
7612 f_l1_tune(L1CTL);
7613 RSL.clear;
7614
7615 /* These IEs are needed for autonomous MS power control */
7616 var template (value) RSL_IE_List ies := {
7617 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7618 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7619 }),
7620 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7621 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7622 })
7623 };
7624
7625 /* Ensure that 'rx-current' equals 'rx-target' */
7626 f_trxc_fake_rssi(mp_uplink_power_target);
7627
7628 /* Establish a dedicated channel */
7629 f_est_dchan(more_ies := valueof(ies));
7630
7631 L1CTL.clear;
7632 T.start;
7633 alt {
7634 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7635 [] T.timeout {
7636 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7637 num_blocks, " were not handled");
7638 }
7639 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007640
7641 /* Release the channel */
7642 f_rsl_chan_deact();
7643 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007644}
7645testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7646 var ConnHdlr vc_conn;
7647 var ConnHdlrPars pars;
7648
7649 f_init();
7650
7651 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7652 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7653 /* Explicitly configure the Uplink power range (target and delte) */
7654 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7655 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7656
7657 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7658 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7659 log(testcasename(), ": starting on ", pars.chan_nr);
7660
7661 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7662 pars, trxc_comp := true);
7663 vc_conn.done;
7664 }
7665
7666 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7668}
7669
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007670private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7671 var template L1ctlDlMessage tr_bad_frame;
7672 var L1ctlDlMessage l1_dl;
7673 timer T := 8.0;
7674
7675 f_l1_tune(L1CTL);
7676 RSL.clear;
7677
7678 f_est_dchan();
7679
7680 /* There may be a few errors right after the channel activation */
7681 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7682 L1CTL.clear;
7683
7684 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7685 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7686 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7687 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7688 tr_bad_frame.payload := ?;
7689
7690 T.start;
7691 alt {
7692 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7693 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7694 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7695 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7696 }
7697 [] as_l1_sacch();
7698 [] L1CTL.receive { repeat; }
7699 [] T.timeout {
7700 /* We're done, break the loop */
7701 setverdict(pass);
7702 }
7703 }
7704
7705 f_rsl_chan_deact();
7706 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7707}
7708testcase TC_speech_no_rtp_tchf() runs on test_CT {
7709 var ConnHdlr vc_conn;
7710 var ConnHdlrPars pars;
7711
7712 f_init();
7713
7714 /* TS1, TCH/F, V1 (FR codec) */
7715 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7716 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7717 vc_conn.done;
7718}
7719testcase TC_speech_no_rtp_tchh() runs on test_CT {
7720 var ConnHdlr vc_conn;
7721 var ConnHdlrPars pars;
7722
7723 f_init();
7724
7725 /* TS5, TCH/H, V1 (HR codec) */
7726 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7727 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7728 vc_conn.done;
7729}
7730
Vadim Yanitskiy18684882021-07-04 04:15:58 +02007731/* Verify handling of Downlink and Uplink speech frames */
7732private function f_TC_speech_rtp(charstring id) runs on ConnHdlr {
7733 var L1ctlDlMessage l1_dl;
7734 var PDU_RTP rtp_pdu;
7735 var octetstring pl;
7736 timer Td, Tu;
7737
7738 f_l1_tune(L1CTL);
7739 f_est_dchan();
7740
7741 /* Activate the RTP emulation */
7742 pl := f_rnd_octstring(6);
7743 f_rtpem_activate(pl);
7744
7745 /* Give the scheduler some time to fill up the buffers */
7746 f_sleep(2.0);
7747 L1CTL.clear;
7748 RSL.clear;
7749
7750 /* Make sure that Downlink frames are received at the UE */
7751 Td.start(2.0);
7752 alt {
7753 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := pl)) -> value l1_dl {
7754 log("TCH received: ", l1_dl.payload.traffic_ind.data);
7755 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
7756 l1_dl.payload.traffic_ind.data));
7757 setverdict(pass);
7758 }
7759 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr, frame := ?)) -> value l1_dl {
7760 setverdict(fail, "Rx unexpected Downlink speech frame ",
7761 "(", l1_dl.payload.traffic_ind.data, ") ",
7762 "expected (", pl, ")");
7763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7764 }
7765 [] as_l1_sacch();
7766 [] L1CTL.receive { repeat; }
7767 [] Td.timeout {
7768 setverdict(fail, "Timeout waiting for Downlink speech frames");
7769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7770 }
7771 }
7772
7773 /* Make sure that Uplink frames are received at the BTS */
7774 RTPEM_DATA.clear;
7775 Tu.start(2.0);
7776 alt {
7777 [] RTPEM_DATA.receive(PDU_RTP:?) -> value rtp_pdu {
7778 if (rtp_pdu.data != pl)
7779 { repeat; }
7780 }
7781 [] RTPEM_DATA.receive { repeat; }
7782 [] Tu.timeout {
7783 setverdict(fail, "Timeout waiting for Uplink speech frames");
7784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7785 }
7786 }
7787
7788 f_rtpem_mode(RTPEM_CTRL, RTPEM_MODE_NONE);
7789 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7790 f_rsl_chan_deact();
7791 f_rslem_unregister(0, g_chan_nr);
7792}
7793testcase TC_speech_rtp_tchf() runs on test_CT {
7794 var ConnHdlr vc_conn;
7795 var ConnHdlrPars pars;
7796
7797 f_init();
7798
7799 /* TS1, TCH/F, V1 (FR codec) */
7800 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7801 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7802 vc_conn.done;
7803
7804 /* TS1, TCH/F, V2 (EFR codec) */
7805 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2)));
7806 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7807 vc_conn.done;
7808
7809 /* TODO: also test V3 (AMR codec) */
7810
7811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7812}
7813testcase TC_speech_rtp_tchh() runs on test_CT {
7814 var ConnHdlr vc_conn;
7815 var ConnHdlrPars pars;
7816
7817 f_init();
7818
7819 /* TS5, TCH/H0, V1 (HR codec) */
7820 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7821 vc_conn := f_start_handler(refers(f_TC_speech_rtp), pars);
7822 vc_conn.done;
7823
7824 /* TODO: also test V3 (AMR codec) */
7825
7826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7827}
7828
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02007829private function f_TC_early_immediate_assignment(charstring id) runs on ConnHdlr {
7830 var GsmFrameNumber fn;
7831 var ChannelDescription ch_desc;
7832 var integer ra := 23;
7833
7834 f_l1_tune(L1CTL);
7835 RSL.clear;
7836
7837 /* Send RACH request and wait for ChanReq */
7838 fn := f_rach_req_wait_chan_rqd(ra);
7839
7840 /* The BSC already sends the Immediate Assignment, before the channel is active.
7841 * (Also before the Channel Activation, even. I tried to write this test so that we first send the Chan Act and then the IMM
7842 * ASS, but osmo-bts-trx responds so fast that the Chan Activ ACK comes back even before titan dispatches the
7843 * IMM ASS. So move the IMM ASS even before the Chan Activ.) */
7844 if (g_pars.fhp.enabled) {
7845 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
7846 } else {
7847 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
7848 }
7849 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
7850 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
7851
7852 /* Do not expect the Immediate Assignment to show up on MS side yet. Even give it one second before the BSC
7853 * requests Chan Activ, to make sure the RR IMM ASS is held back. */
7854 var L1ctlDlMessage dl;
7855 var GsmRrMessage rr;
7856
7857 var template GsmRrMessage rr_imm_ass := tr_IMM_ASS(ra, fn);
7858 rr_imm_ass.payload.imm_ass.ded_or_tbf := ?;
7859 rr_imm_ass.payload.imm_ass.pkt_chan_desc := *;
7860 rr_imm_ass.payload.imm_ass.chan_desc := *;
7861
7862 timer T := 1.0;
7863 T.start;
7864 alt {
7865 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
7866 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
7867 if (match(rr, rr_imm_ass)) {
7868 setverdict(fail, "Expected IMM ASS to be delayed until Chan Act ACK, but it was passed to the MS immediately");
7869 mtc.stop;
7870 } else {
7871 repeat;
7872 }
7873 }
7874 [] L1CTL.receive { repeat; }
7875 [] T.timeout;
7876 }
7877 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode, t_RSL_IE_ActType_IA));
7878 RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr));
7879
7880 /* Now expect the IMM ASS on Um */
7881 f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
7882 setverdict(pass);
7883
7884 /* Release the channel */
7885 f_rsl_chan_deact();
7886 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7887}
7888
7889testcase TC_early_immediate_assignment() runs on test_CT {
7890 var ConnHdlr vc_conn;
7891 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
7892 f_init();
7893 vc_conn := f_start_handler(refers(f_TC_early_immediate_assignment), pars);
7894 vc_conn.done;
7895 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7896}
7897
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06007898private function f_TC_est_dchan(charstring id) runs on ConnHdlr {
7899 var integer ra := oct2int(f_rnd_ra_cs());
7900 var ChannelDescription ch_desc;
7901
7902 /* Tune the MS to BCCH */
7903 f_l1_tune(L1CTL);
7904
7905 /* Send RACH request and wait for ChanReq */
7906 var GsmFrameNumber fn := f_rach_req_wait_chan_rqd(ra);
7907
7908 /* Activate channel on the BTS side */
7909 f_rsl_chan_act(g_pars.chan_mode);
7910
7911 /* Craft channel description (with or without frequency hopping parameters) */
7912 if (g_pars.fhp.enabled) {
7913 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
7914 } else {
7915 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
7916 }
7917
7918 /* Send IMM.ASS via CCHAN */
7919 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
7920 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
7921
7922 /* Receive IMM.ASS on the MS side */
7923 var ImmediateAssignment imm_ass := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
7924
7925 /* Match the Channel Description IE in received IMM.ASS */
7926 if (not match(imm_ass.chan_desc, ch_desc)) {
7927 setverdict(fail, "Channel Description IE does not match");
7928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7929 }
7930
7931 /* Tune the MS to a dedicated channel indicated in the IMM.ASS */
7932 f_L1CTL_DM_EST_REQ_IA(L1CTL, imm_ass, g_pars.fhp.ma);
7933
7934 /* Expect SACCH frames on Downlink */
7935 L1CTL.clear;
7936 f_exp_sacch(true);
7937
7938 /* We're done, deactivate and release */
7939 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7940 f_rsl_chan_deact();
7941}
7942testcase TC_est_dchan() runs on test_CT {
7943 var ConnHdlr vc_conn;
7944 var ConnHdlrPars pars;
7945
7946 f_init();
7947
7948 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
7949 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
7950 vc_conn := f_start_handler(refers(f_TC_est_dchan), pars);
7951 vc_conn.done;
7952 }
7953
7954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7955}
7956
Harald Welte0472ab42018-03-12 15:02:26 +01007957/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7958/* protocol error as per 44.006 */
7959/* link layer failure (repetition of I-frame N200 times without ACK */
7960/* repetition of SABM or DISC N200 times without ACK */
7961/* receptiom of SABM in multi-frame established state */
7962
7963
Harald Welte68e495b2018-02-25 00:05:57 +01007964/* TODO Areas:
7965
7966* channel activation
7967** with BS_Power / MS_Power, bypassing power control loop
7968** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007969** with timing advance from initial activation on
7970* mode modify
7971** encryption
7972** multirate
7973* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007974** unsupported algorithm
7975* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007976* BS Power Control
7977* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007978* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007979* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007980** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007981* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007982** DATA_IND from BTS->PCU
7983** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007984
7985*/
Harald Welte70767382018-02-21 12:16:40 +01007986
7987control {
Vadim Yanitskiyd0eb6592021-10-08 01:19:29 +06007988 execute( TC_est_dchan() );
Harald Welte70767382018-02-21 12:16:40 +01007989 execute( TC_chan_act_stress() );
7990 execute( TC_chan_act_react() );
7991 execute( TC_chan_deact_not_active() );
7992 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007993 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007994 execute( TC_sacch_filling() );
7995 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007996 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007997 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007998 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007999 execute( TC_sacch_chan_act_ho_async() );
8000 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008001 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02008002 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01008003 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01008004 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07008005 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02008006 execute( TC_rach_load_idle_thresh0() );
8007 execute( TC_rach_load_idle_below_thresh() );
8008 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008009 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02008010 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07008011 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02008012 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07008013 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01008014 execute( TC_meas_res_sign_tchf() );
8015 execute( TC_meas_res_sign_tchh() );
8016 execute( TC_meas_res_sign_sdcch4() );
8017 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01008018 execute( TC_meas_res_sign_tchh_toa256() );
Vadim Yanitskiy8f6eae02021-10-26 02:49:21 +03008019 execute( TC_meas_res_speech_tchf_sapi3() );
8020 execute( TC_meas_res_speech_tchh_sapi3() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02008021 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02008022 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02008023 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02008024 execute( TC_rsl_bs_pwr_static_ass() );
8025 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01008026 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02008027 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02008028 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02008029 execute( TC_rsl_ms_pwr_dyn_up() );
8030 execute( TC_rsl_ms_pwr_dyn_down() );
8031 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
8032 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02008033 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02008034 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02008035 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02008036 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01008037 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01008038 execute( TC_paging_imsi_80percent() );
8039 execute( TC_paging_tmsi_80percent() );
8040 execute( TC_paging_imsi_200percent() );
8041 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01008042 execute( TC_rsl_protocol_error() );
8043 execute( TC_rsl_mand_ie_error() );
8044 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01008045 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01008046 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01008047 execute( TC_si_sched_2bis() );
8048 execute( TC_si_sched_2ter() );
8049 execute( TC_si_sched_2ter_2bis() );
8050 execute( TC_si_sched_2quater() );
8051 execute( TC_si_sched_13() );
8052 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01008053 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01008054 execute( TC_ipa_crcx_twice_not_active() );
8055 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01008056 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01008057 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01008058
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008059 if (mp_pcu_socket != "") {
Philipp Maierca058272021-06-23 10:35:23 +02008060 execute( TC_paging_imsi_200percent_with_ps() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008061 execute( TC_pcu_act_req() );
8062 execute( TC_pcu_act_req_wrong_ts() );
8063 execute( TC_pcu_act_req_wrong_bts() );
8064 execute( TC_pcu_act_req_wrong_trx() );
8065 execute( TC_pcu_deact_req() );
8066 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01008067 execute( TC_pcu_ver_si1() );
8068 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008069 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02008070 if (mp_l1_supports_gprs) {
8071 execute( TC_pcu_data_req_pdtch() );
8072 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02008073 execute( TC_pcu_data_req_wrong_bts() );
8074 execute( TC_pcu_data_req_wrong_trx() );
8075 execute( TC_pcu_data_req_wrong_ts() );
8076 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02008077 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07008078 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008079 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02008080 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008081 execute( TC_pcu_data_req_imm_ass_pch() );
8082 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07008083 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07008084 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008085 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02008086 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02008087 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02008088 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02008089 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02008090 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02008091 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02008092 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008093 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008094 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008095 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02008096 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07008097 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02008098 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01008099 execute( TC_dyn_osmo_pdch_act_deact() );
8100 execute( TC_dyn_osmo_pdch_double_act() );
8101 execute( TC_dyn_ipa_pdch_act_deact() );
8102 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01008103 execute( TC_pcu_info_ind_fh_params() );
8104 execute( TC_pcu_socket_nsvc_ipv4() );
8105 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01008106 execute( TC_pcu_socket_two_nsvc() );
Vadim Yanitskiy83852c12021-06-18 16:18:29 +02008107 execute( TC_pcu_interf_ind() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01008108 } else {
8109 log("PCU socket path not available, skipping PCU tests");
8110 }
Harald Welte3d04ae62018-04-04 20:29:05 +02008111
Harald Welte3d04ae62018-04-04 20:29:05 +02008112 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02008113 execute( TC_dyn_osmo_pdch_tchf_act() );
8114 execute( TC_dyn_osmo_pdch_tchh_act() );
Pau Espin Pedrol8e57ac12021-06-29 17:04:24 +02008115 execute( TC_dyn_osmo_pdch_sdcch8_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02008116 execute( TC_dyn_ipa_pdch_tchf_act() );
8117 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01008118
8119 execute( TC_rll_est_ind() );
8120 execute( TC_rll_est_req_DCCH_3() );
8121 execute( TC_rll_est_req_ACCH_3() );
8122 execute( TC_rll_rel_ind_DCCH_0() );
8123 execute( TC_rll_rel_ind_DCCH_3() );
8124 execute( TC_rll_rel_ind_ACCH_0() );
8125 execute( TC_rll_rel_ind_ACCH_3() );
8126 execute( TC_rll_rel_req() );
8127 execute( TC_rll_unit_data_req_DCCH() );
8128 execute( TC_rll_unit_data_req_ACCH() );
8129 execute( TC_rll_unit_data_ind_DCCH() );
8130 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02008131
8132 execute( TC_chan_act_a51() );
8133 execute( TC_chan_act_a52() );
8134 execute( TC_chan_act_a53() );
8135 execute( TC_encr_cmd_a51() );
8136 execute( TC_encr_cmd_a52() );
8137 execute( TC_encr_cmd_a53() );
8138
Harald Welteee25aae2019-05-19 14:32:37 +02008139 execute( TC_err_rep_wrong_mdisc() );
8140 execute( TC_err_rep_wrong_msg_type() );
8141 execute( TC_err_rep_wrong_sequence() );
8142
Harald Weltee613f962018-04-18 22:38:16 +02008143 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02008144
8145 execute( TC_tch_sign_l2_fill_frame() );
8146 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02008147
8148 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008149 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07008150
8151 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07008152 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07008153
8154 execute( TC_speech_no_rtp_tchf() );
8155 execute( TC_speech_no_rtp_tchh() );
Vadim Yanitskiy18684882021-07-04 04:15:58 +02008156 execute( TC_speech_rtp_tchf() );
8157 execute( TC_speech_rtp_tchh() );
Neels Hofmeyraf9d6ae2021-08-15 23:18:47 +02008158
8159 execute( TC_early_immediate_assignment() );
Vadim Yanitskiy46f19922021-10-06 02:36:22 +06008160
8161 /* BEWARE: these test cases can potentially break the IUT or cause
8162 * weird/unexpected behavior. Ensure that they are executed last. */
8163 execute( TC_dyn_osmo_pdch_tchh_race_act() );
8164 execute( TC_dyn_osmo_pdch_sdcch8_race_act() );
Harald Welte70767382018-02-21 12:16:40 +01008165}
8166
8167
8168}