blob: 8b10d0e56ace2a9bc97ff1fbb1168dfce0cd984f [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;
Harald Welte7484fc42018-02-24 14:09:45 +010043import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010044import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020045import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010046import from RSL_Emulation all;
47
48import from IPL4asp_Types all;
49import from TRXC_Types all;
50import from TRXC_CodecPort all;
51import from TRXC_CodecPort_CtrlFunct all;
52
Harald Welte883340c2018-02-28 18:59:29 +010053import from PCUIF_Types all;
54import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020055import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010056
Harald Welte7484fc42018-02-24 14:09:45 +010057import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010058import from MobileL3_RRM_Types all;
59import from MobileL3_Types all;
60import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020061import from L3_Common all;
62import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010063
Harald Welte8da48242018-02-27 20:41:32 +010064import from Osmocom_VTY_Functions all;
65import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020066import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010067
Harald Welte505cf9b2018-09-15 17:47:23 +030068friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020069friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020070friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010071friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030072
Harald Welte70767382018-02-21 12:16:40 +010073/* The tests assume a BTS with the following timeslot configuration:
74 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020075 * TS1 : TCH/F
76 * TS2 : TCH/F
77 * TS3 : TCH/F_PDCH (IPA Style)
78 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010079 * TS5 : TCH/H
80 * TS6 : SDCCH/8
81 * TS7 : PDCH
82 */
83
84modulepar {
85 charstring mp_rsl_ip := "127.0.0.2";
86 integer mp_rsl_port := 3003;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070087 charstring mp_bts_trxc_ip := "127.0.0.1";
88 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010089 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020090 charstring mp_ctrl_ip := "127.0.0.1";
91 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020092 charstring mp_bsc_ctrl_ip := "127.0.0.1";
93 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020094 integer mp_tolerance_rxqual := 1;
95 integer mp_tolerance_rxlev := 3;
96 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020097 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020098 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020099 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200100 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
101 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 +0200102 integer mp_ms_actual_ta_exp := 0;
103 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700104 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700105 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100106 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200107 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200108 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200109 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
110 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700111 /* how many transceivers do we expect to connect */
112 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700113 /* frequency hopping status */
114 boolean mp_freq_hop_enabled := false;
115 /* frequency hopping parameters */
116 FreqHopConfig mp_fh_config;
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700117 /* configuration for each individual transceiver */
118 TrxPars mp_trx_pars; /* see BTS_Tests.default */
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700119 /* default Training Sequence Code */
120 GsmTsc mp_tsc_def := 7;
Harald Welte70767382018-02-21 12:16:40 +0100121}
122
Harald Welte629cc6b2018-03-11 17:19:05 +0100123type record of RslChannelNr ChannelNrs;
124
Harald Welte70767382018-02-21 12:16:40 +0100125type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100126 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100127 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100128 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100129 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100130 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100131 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100132
133 /* L1CTL port (for classic tests) */
134 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100135
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700136 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700137 port TRXC_CODEC_PT BTS_TRXC;
138 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100139
Harald Weltef50e3ae2018-09-10 10:27:56 +0200140 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100141 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200142 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100143
Harald Welte883340c2018-02-28 18:59:29 +0100144 /* PCU Interface of BTS */
145 port PCUIF_CODEC_PT PCU;
146 var integer g_pcu_conn_id;
147 /* Last PCU INFO IND we received */
148 var PCUIF_Message g_pcu_last_info;
149
Harald Welte48494ca2018-02-25 16:59:50 +0100150 /* SI configuration */
151 var SystemInformationConfig si_cfg := {
152 bcch_extended := false,
153 si1_present := false,
154 si2bis_present := false,
155 si2ter_present := false,
156 si2quater_present := false,
157 si7_present := false,
158 si8_present := false,
159 si9_present := false,
160 si13_present := false,
161 si13alt_present := false,
162 si15_present := false,
163 si16_present := false,
164 si17_present := false,
165 si2n_present := false,
166 si21_present := false,
167 si22_present := false
168 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100169
170 /* all logical channels available on the BTS */
171 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100172 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100173}
174
175/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200176type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100177 port L1CTL_PT L1CTL;
178
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700179 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700180 port TRXC_CODEC_PT BTS_TRXC;
181 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100182
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200183 /* port to be initialized optionally to access BSC VTY */
184 port TELNETasp_PT BSCVTY;
185
Harald Welte70767382018-02-21 12:16:40 +0100186 timer g_Tguard;
187 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
188
189 var ConnHdlrPars g_pars;
190 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100191 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200192
193 /* PCU Interface of BTS */
194 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100195}
196
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700197private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700198 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200199 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700200 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200201 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700202 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200203 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700204 timer T;
205
Harald Welte70767382018-02-21 12:16:40 +0100206 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
207 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
208
209 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
210 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
211 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
212
213 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
214 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700215
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700216 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700217 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700218 T.start(mp_ipa_up_timeout);
219 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700220 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700221 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
222 /* Make sure that all transceivers use unique stream ID */
223 if (trx_mask[enum2int(ev.sid)] == '1'B) {
224 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
225 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
226 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700227
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700228 trx_mask[enum2int(ev.sid)] := '1'B;
229 trx_count := trx_count + 1;
230
231 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200232 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700233 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200234 /* This message (RF RESource INDication) is sent by the IUT itself */
235 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
236 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
238 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
239 }
240 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
242 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
243 }
244
245 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
246 rfind_count := rfind_count + 1;
247 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
248 if (rfind_count < mp_transceiver_num) { repeat; }
249 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700250 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
251 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
252 [] T.timeout {
253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
254 "Timeout waiting for RSL bring up");
255 }
256 }
Harald Welte70767382018-02-21 12:16:40 +0100257}
258
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700259friend type record length(1 .. 256) of TrxParsItem TrxPars;
260friend type record TrxParsItem {
261 GsmArfcn arfcn,
262 TrxTsPars ts
263};
264
265friend type record length(8) of TrxTsParsItem TrxTsPars;
266friend type record TrxTsParsItem {
267 PchanConfig config
268};
269
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700270friend type record FreqHopPars {
271 /* Whether frequency hopping is in use */
272 boolean enabled,
273 /* Mobile Allocation Index Offset / Hopping Sequence Number */
274 MaioHsn maio_hsn,
275 /* MA bitmap to be indicated in RR Immediate Assignment */
276 MobileAllocationLV ma_map,
277 /* The actual Mobile Allocation (ARFCN list) to be used */
278 L1ctlMA ma
279};
280
Harald Welte70767382018-02-21 12:16:40 +0100281type record ConnHdlrPars {
282 RslChannelNr chan_nr,
283 RSL_IE_ChannelMode chan_mode,
284 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100285 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200286 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200287 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700288 BtsBand bts0_band optional,
289
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700290 /* Training Sequence Code */
291 GsmTsc tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700292 /* Frequency hopping parameters */
293 FreqHopPars fhp
294};
Harald Welte0472ab42018-03-12 15:02:26 +0100295
296/* Test-specific parameters */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +0200297friend type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100298 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100299}
300
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700301private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100302 max_retrans := RACH_MAX_RETRANS_7,
303 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100304 cell_barr_access := false,
305 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100306 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100307};
308
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700309private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100310 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200311 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100312 acs := '0'B,
313 neci := true,
314 rxlev_access_min := 0
315}
316
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700317private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100318 mcc_mnc := '262F42'H,
319 lac := 42
320}
321
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700322private template (value) GPRSIndicator ts_GPRSIndicator_def := {
323 ra_colour := 0,
324 si13_pos := '0'B
325}
326
327private template (value) SI3RestOctets ts_SI3RestOctets_def
328modifies ts_SI3RestOctets := {
329 gprs_ind := {
330 presence := CSN1_H,
331 ind := ts_GPRSIndicator_def
332 }
333}
334
335private template (value) SI4RestOctets ts_SI4RestOctets_def
336modifies ts_SI4RestOctets := {
337 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700338 presence := CSN1_H,
339 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700340 }
341}
342
Harald Welte7484fc42018-02-24 14:09:45 +0100343/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700344private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100345 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100346 payload := {
347 si3 := {
348 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100349 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100350 ctrl_chan_desc := {
351 msc_r99 := true,
352 att := true,
353 bs_ag_blks_res := 1,
354 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100355 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100356 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
357 spare := '00'B,
358 bs_pa_mfrms := 0, /* 2 multiframes */
359 t3212 := 1 /* 6 minutes */
360 },
Harald Welte82ccef72018-02-25 16:17:33 +0100361 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100362 dn_ind := false,
363 pwrc := false,
364 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100365 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100366 },
Harald Weltef10153f2018-02-25 16:34:05 +0100367 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100368 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200369 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100370 }
371 }
372}
Harald Welte70767382018-02-21 12:16:40 +0100373
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700374private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100375 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100376 payload := {
377 si2 := {
378 bcch_freq_list := '00000000000000000000000000000000'O,
379 ncc_permitted := '11111111'B,
380 rach_control := ts_RachCtrl_default
381 }
382 }
383}
384
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700385private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100386 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100387 payload := {
388 si4 := {
389 lai := ts_LAI_default,
390 cell_sel_par := ts_CellSelPar_default,
391 rach_control := ts_RachCtrl_default,
392 cbch_chan_desc := omit,
393 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200394 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100395 }
396 }
397}
398
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700399private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100400runs on test_CT {
401 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700402 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100403}
404
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700405private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100406runs on test_CT {
407 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
408 log("Setting ", rsl_si_type, ": ", si_dec);
409 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
410}
411
Harald Welte505cf9b2018-09-15 17:47:23 +0300412friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100413 map(self:BTSVTY, system:BTSVTY);
414 f_vty_set_prompts(BTSVTY);
415 f_vty_transceive(BTSVTY, "enable");
416}
417
Harald Welte505cf9b2018-09-15 17:47:23 +0300418friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200419 map(self:BSCVTY, system:BSCVTY);
420 f_vty_set_prompts(BSCVTY, "OsmoBSC");
421 f_vty_transceive(BSCVTY, "enable");
422}
423
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200424friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
425 map(self:BSCVTY, system:BSCVTY);
426 f_vty_set_prompts(BSCVTY, "OsmoBSC");
427 f_vty_transceive(BSCVTY, "enable");
428}
429
Harald Welte883340c2018-02-28 18:59:29 +0100430/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200431private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
432 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100433 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200434 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
435 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100436 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200437 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100439 }
440}
441
Harald Weltef26de0b2018-04-04 20:28:05 +0200442private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
443 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100444 timer T := 2.0;
445 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100446 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200447 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100448 return;
449 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200450 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100451
452 T.start;
453 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200454 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100455 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200456 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100457 }
458 }
459}
460
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700461private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
462 out integer trxc_conn_id) {
463 var Result res;
464
465 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
466 "", -1, -1, { udp := {} }, {});
467 if (not ispresent(res.connId)) {
468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
469 "Could not connect to the control (TRXC) interface " &
470 "of FakeTRX, check your configuration");
471 }
472 trxc_conn_id := res.connId;
473}
474
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100475/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700476friend function f_init(uint8_t trx_nr := 0)
477runs on test_CT
478{
479 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200480 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100481
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700482 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
483 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700484 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200485 g_AllChanTypes := {
486 /* TS 1..4: TCH/F */
487 valueof(ts_RslChanNr_Bm(1)),
488 /* TS 5: TCH/H */
489 valueof(ts_RslChanNr_Lm(5,1)),
490 /* TS 0: SDCCH/4 */
491 valueof(ts_RslChanNr_SDCCH4(0,2)),
492 /* TS 6: SDCCH/8 */
493 valueof(ts_RslChanNr_SDCCH8(6,4))
494 };
495 } else {
496 g_AllChanTypes := {
497 /* TS 1..4: TCH/F */
498 valueof(ts_RslChanNr_Bm(1)),
499 /* TS 0: SDCCH/4 */
500 valueof(ts_RslChanNr_SDCCH4(0,2)),
501 /* TS 6: SDCCH/8 */
502 valueof(ts_RslChanNr_SDCCH8(6,4))
503 };
504 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700505
506 g_AllChannels := { };
507
508 /* Generate list of all logical channels from module parameters */
509 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
510 select (trx_pars.ts[tn].config) {
511 case (GSM_PCHAN_CCCH_SDCCH4) {
512 g_AllChannels := g_AllChannels &
513 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
514 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
515 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
516 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
517 }
518 case (GSM_PCHAN_SDCCH8) {
519 g_AllChannels := g_AllChannels &
520 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
521 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
522 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
523 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
524 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
525 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
526 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
527 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
528 }
529 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
530 g_AllChannels := g_AllChannels &
531 { valueof(ts_RslChanNr_Lm(tn, 0)),
532 valueof(ts_RslChanNr_Lm(tn, 1)),
533 valueof(ts_RslChanNr_Bm(tn)) };
534 }
535 case (GSM_PCHAN_TCHH) {
536 g_AllChannels := g_AllChannels &
537 { valueof(ts_RslChanNr_Lm(tn, 0)),
538 valueof(ts_RslChanNr_Lm(tn, 1)) };
539 }
540 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
541 g_AllChannels := g_AllChannels &
542 { valueof(ts_RslChanNr_Bm(tn)) };
543 }
544 }
545 }
546
Harald Welte70767382018-02-21 12:16:40 +0100547 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100548 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100549 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100550 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100551
552 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100553 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
554 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
555 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
556 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100557
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700558 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100559 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700560
561 /* Init TRXC interface to FakeTRX */
562 map(self:BTS_TRXC, system:BTS_TRXC);
563 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
564
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700565 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700566 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700567 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700568 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
569 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100570 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200571
572 /* Wait some extra time to make sure the BTS emits a stable carrier.
573 * (this is only relevant when running the tests with a physical BTS.) */
574 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100575}
576
Harald Welte68e495b2018-02-25 00:05:57 +0100577/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700578friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100579 map(self:L1CTL, system:L1CTL);
580 f_connect_reset(L1CTL);
581}
582
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700583private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100584
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700585private type record length(8) of FreqHopGroups FreqHopConfig;
586
587private type record of FreqHopGroup FreqHopGroups;
588private type record FreqHopGroup {
589 uint6_t hsn,
590 FreqHopGroupItems trx_maio
591};
592
593private type record of FreqHopGroupItem FreqHopGroupItems;
594private type record FreqHopGroupItem {
595 uint8_t trx_nr,
596 uint6_t maio
597};
598
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700599friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
600 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700601{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700602 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700603 var integer i, j;
604
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700605 fhp.enabled := false;
606
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700607 for (i := 0; i < lengthof(groups); i := i + 1) {
608 var FreqHopGroup g := groups[i];
609 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
610 var FreqHopGroupItem gi := g.trx_maio[j];
611 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700612 fhp.maio_hsn.maio := gi.maio;
613 fhp.maio_hsn.hsn := g.hsn;
614 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700615 break;
616 }
617 }
618
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700619 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700620 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700621 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
622 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
623 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700624
625 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700626 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
627 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700628 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700629 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700630 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700631 }
632
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700633 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700634 break; /* We're done */
635 }
636 }
637}
638
Harald Welte70767382018-02-21 12:16:40 +0100639/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700640friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
641 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200642 boolean trxc_comp := false,
643 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100644runs on test_CT return ConnHdlr {
645 var charstring id := testcasename();
646 var ConnHdlr vc_conn;
647
648 vc_conn := ConnHdlr.create(id);
649 /* connect to RSL Emulation main component */
650 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
651 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700652
653 /* The ConnHdlr component may want to talk to some ports directly,
654 * so we disconnect it from the test_CT and connect it to the component.
655 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200656 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200657 unmap(self:PCU, system:PCU);
658 map(vc_conn:PCU, system:PCU);
659 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700660 if (trxc_comp) {
661 unmap(self:BTS_TRXC, system:BTS_TRXC);
662 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
663 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200664 if (l1ctl) {
665 map(vc_conn:L1CTL, system:L1CTL);
666 }
Harald Welte70767382018-02-21 12:16:40 +0100667
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700668 /* Obtain frequency hopping parameters for a given timeslot */
669 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700670 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700671 }
672
Harald Welte70767382018-02-21 12:16:40 +0100673 vc_conn.start(f_handler_init(fn, id, pars));
674 return vc_conn;
675}
676
Harald Welte70767382018-02-21 12:16:40 +0100677private altstep as_Tguard() runs on ConnHdlr {
678 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200679 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100680 }
681}
682
Harald Welte990a3612019-05-27 14:02:13 +0200683friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700684 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700685 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100686}
687
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700688private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100689 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700690 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100691}
692
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700693private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100694 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700695 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100696}
697
698/* first function started in ConnHdlr component */
699private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
700runs on ConnHdlr {
701 g_pars := pars;
702 g_chan_nr := pars.chan_nr;
703
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200704 if (L1CTL.checkstate("Mapped")) {
705 f_connect_reset(L1CTL);
706 }
Harald Welte70767382018-02-21 12:16:40 +0100707
Harald Welted48c0c72019-06-05 10:01:15 +0200708 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700709 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100710 }
Harald Welte70767382018-02-21 12:16:40 +0100711
712 g_Tguard.start(pars.t_guard);
713 activate(as_Tguard());
714
715 f_rslem_register(0, pars.chan_nr);
716
717 /* call the user-supplied test case function */
718 fn.apply(id);
719}
720
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700721private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
722 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200723runs on ConnHdlr return RSL_Message {
724 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100725 timer T := 3.0;
726 RSL.send(tx);
727 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100728 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200729 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100730 T.stop;
731 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100732 }
Harald Welte1eba3742018-02-25 12:48:14 +0100733 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200734 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100735 }
Harald Welte21240e62018-03-11 21:43:35 +0100736 [not ignore_other] as_l1_sacch();
737 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700738 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700739 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100740 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200741 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100742 }
Harald Welte21240e62018-03-11 21:43:35 +0100743 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100744 }
Harald Welteb1726c92018-03-30 11:56:38 +0200745 return rx;
746}
747
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700748friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
749 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200750runs on ConnHdlr {
751 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100752}
753
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700754friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
755 boolean encr_enable := false,
756 RSL_IE_List more_ies := {},
757 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
758runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200759 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200760 if (encr_enable) {
761 /* append encryption related IEs, if requested */
762 var RSL_IE_EncryptionInfo encr_info;
763 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
764 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
765encr_info})) };
766 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200767 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200768 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100769}
770
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700771friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100772 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 +0100773 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100774}
775
Harald Welte2f2b2b72019-05-31 22:24:57 +0200776friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200777 template RSL_IE_ChannelMode chan_mode,
778 template (omit) TestSpecUnion spec := omit,
779 float t_guard := 20.0) := {
Harald Welte70767382018-02-21 12:16:40 +0100780 chan_nr := valueof(chan_nr),
781 chan_mode := valueof(chan_mode),
782 t_guard := t_guard,
783 l1_pars := {
784 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100785 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100786 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100787 meas_ul := {
788 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200789 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100790 rxqual := 0
791 },
792 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200793 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100794 rxqual := 0
795 }
796 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200797 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100798 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200799 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200800 ms_actual_ta := mp_ms_actual_ta_exp,
801 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100802 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200803 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200804 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700805 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700806 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700807 fhp := {
808 enabled := false,
809 maio_hsn := ts_HsnMaio(0, 0),
810 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700811 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700812 }
Harald Welte70767382018-02-21 12:16:40 +0100813}
814
Harald Welte93640c62018-02-25 16:59:33 +0100815/***********************************************************************
816 * Channel Activation / Deactivation
817 ***********************************************************************/
818
Harald Welte70767382018-02-21 12:16:40 +0100819/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700820private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100821 for (var integer i := 0; i < 500; i := i+1) {
822 f_rsl_chan_act(g_pars.chan_mode);
823 f_rsl_chan_deact();
824 }
825 setverdict(pass);
826}
827testcase TC_chan_act_stress() runs on test_CT {
828 var ConnHdlr vc_conn;
829 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200830 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100831 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
832 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100834}
835
836/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700837private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100838 f_rsl_chan_act(g_pars.chan_mode);
839 /* attempt to activate the same lchan again -> expect reject */
840 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
841 alt {
842 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100844 }
845 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
846 setverdict(pass);
847 }
848 }
849 f_rsl_chan_deact();
850}
851testcase TC_chan_act_react() runs on test_CT {
852 var ConnHdlr vc_conn;
853 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100854 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100855 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
856 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100858}
859
860/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700861private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100862 timer T := 3.0;
863 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
864 T.start;
865 alt {
866 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
867 setverdict(pass);
868 }
869 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100871 }
872 }
873}
874testcase TC_chan_deact_not_active() runs on test_CT {
875 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100876 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100877 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
878 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200879 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100880}
881
882/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700883private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100884 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
885 alt {
886 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200887 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100888 }
889 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
890 setverdict(pass);
891 }
892 }
893}
894private type record WrongChanNrCase {
895 RslChannelNr chan_nr,
896 charstring description
897}
898private type record of WrongChanNrCase WrongChanNrCases;
899private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
900 chan_nr := chan_nr,
901 description := desc
902}
903
904testcase TC_chan_act_wrong_nr() runs on test_CT {
905 var ConnHdlr vc_conn;
906 var ConnHdlrPars pars;
907
Harald Welte294b0a22018-03-10 23:26:48 +0100908 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100909
910 var WrongChanNrCases wrong := {
911 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
912 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
913 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
914 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
915 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
916 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
917 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
918 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
919 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
920 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
921 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
922 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
923 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
924 };
925
926 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
927 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
928 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
929 vc_conn.done;
930 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200931 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100932}
933
Harald Weltee613f962018-04-18 22:38:16 +0200934/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200935friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200936 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200937 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200938
939 /* test on each of the channels we have */
940 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
941 pars.chan_nr := valueof(g_AllChanTypes[i]);
942
943 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
944 vc_conn := f_start_handler(fn, pars);
945 vc_conn.done;
946 }
947
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200949}
950
Harald Welte93640c62018-02-25 16:59:33 +0100951/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100952 * SACCH handling
953 ***********************************************************************/
954
955private function f_exp_sacch(boolean exp) runs on ConnHdlr {
956 timer T_sacch := 3.0;
957 T_sacch.start;
958 alt {
959 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100961 }
962 [not exp] T_sacch.timeout {
963 setverdict(pass);
964 }
965 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
966 setverdict(pass);
967 }
968 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200969 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100970 }
971 [] L1CTL.receive { repeat; }
972 [] RSL.receive { repeat; }
973 }
974}
975
976/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
977private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
978 f_l1_tune(L1CTL);
979 RSL.clear;
980
981 /* activate the logical channel */
982 f_est_dchan();
983 L1CTL.clear;
984
985 /* check that SACCH actually are received as expected */
986 f_exp_sacch(true);
987
988 /* deactivate SACCH on the logical channel */
989 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
990 f_sleep(1.0);
991 L1CTL.clear;
992
993 /* check that no SACCH are received anymore */
994 f_exp_sacch(false);
995
996 /* release the channel */
997 f_rsl_chan_deact();
998 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
999}
1000testcase TC_deact_sacch() runs on test_CT {
1001 var ConnHdlr vc_conn;
1002 var ConnHdlrPars pars;
1003 f_init();
1004 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1005 //for (var integer i := 0; i < 1; i := i+1) {
1006 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1007 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1008 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1009 vc_conn.done;
1010 }
1011 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001013}
1014
Harald Welte55700662018-03-12 13:15:43 +01001015/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +01001016private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
1017 var L1ctlDlMessage dl;
1018 /* check that the specified SI5 value is actually sent */
1019 timer T_sacch := 3.0;
1020 L1CTL.clear;
1021 T_sacch.start;
1022 alt {
1023 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1024 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1025 if (match(l3, l3_exp)) {
1026 setverdict(pass);
1027 } else {
1028 repeat;
1029 }
1030 }
1031 [] L1CTL.receive { repeat; }
1032 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001033 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +01001034 }
1035 }
1036}
1037
Harald Welte55700662018-03-12 13:15:43 +01001038/* verify that given SACCH payload is not present */
1039private function f_sacch_missing(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)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001049 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001050 } else {
1051 repeat;
1052 }
1053 }
1054 [] L1CTL.receive { repeat; }
1055 [] T_sacch.timeout {
1056 setverdict(pass);
1057 }
1058 }
1059}
1060
Harald Welte629cc6b2018-03-11 17:19:05 +01001061/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001062private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1063 /* Set a known default SACCH filling for SI5 */
1064 var octetstring si5 := f_rnd_octstring(19);
1065 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1066
1067 f_l1_tune(L1CTL);
1068 RSL.clear;
1069
1070 /* activate the logical channel */
1071 f_est_dchan();
1072
1073 /* check that the specified SI5 value is actually sent */
1074 f_sacch_present(si5);
1075
1076 /* release the channel */
1077 RSL.clear;
1078 f_rsl_chan_deact();
1079 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1080}
1081testcase TC_sacch_filling() runs on test_CT {
1082 var ConnHdlr vc_conn;
1083 var ConnHdlrPars pars;
1084 f_init();
1085 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1086 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1087 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1088 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1089 vc_conn.done;
1090 }
1091 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001093}
1094
Harald Welte629cc6b2018-03-11 17:19:05 +01001095/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001096private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1097 /* Set a known default SACCH filling for SI5 */
1098 var octetstring si5 := f_rnd_octstring(19);
1099 var octetstring si5_diff := f_rnd_octstring(19);
1100 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1101
1102 f_l1_tune(L1CTL);
1103 RSL.clear;
1104
1105 log("Activating channel, expecting standard SI5");
1106 /* activate the logical channel */
1107 f_est_dchan();
1108 /* check that the specified SI5 value is actually sent */
1109 f_sacch_present(si5);
1110
1111 /* set channel-specific different SI5 */
1112 log("Setting channel specific SACCH INFO, expecting it");
1113 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1114 /* check that the specified lchan-specific value is now used */
1115 f_sacch_present(si5_diff);
1116
1117 /* deactivate the channel and re-activate it, this should result in default SI5 */
1118 log("De-activating and re-activating channel, expecting standard SI5");
1119 f_rsl_chan_deact();
1120 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1121 /* Verify that the TRX-wide default SACCH filling is present again */
1122 f_sacch_present(si5);
1123
1124 /* release the channel */
1125 RSL.clear;
1126 f_rsl_chan_deact();
1127 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1128}
1129testcase TC_sacch_info_mod() runs on test_CT {
1130 var ConnHdlr vc_conn;
1131 var ConnHdlrPars pars;
1132 f_init();
1133 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1134 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1135 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1136 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1137 vc_conn.done;
1138 }
1139 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001140 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001141}
1142
Harald Welte075d84c2018-03-12 13:07:24 +01001143/* Test SACCH scheduling of multiple different SI message types */
1144private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1145 var octetstring si5 := f_rnd_octstring(19);
1146 var octetstring si5bis := f_rnd_octstring(19);
1147 var octetstring si5ter := f_rnd_octstring(19);
1148 var octetstring si6 := f_rnd_octstring(19);
1149
1150 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1151 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1152 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1153 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1154
1155 f_l1_tune(L1CTL);
1156 RSL.clear;
1157
1158 /* activate the logical channel */
1159 f_est_dchan();
1160 L1CTL.clear;
1161
1162 /* check that SACCH actually are received as expected */
1163 f_sacch_present(si5);
1164 f_sacch_present(si5bis);
1165 f_sacch_present(si5ter);
1166 f_sacch_present(si6);
1167
1168 /* release the channel */
1169 f_rsl_chan_deact();
1170 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1171}
1172testcase TC_sacch_multi() runs on test_CT {
1173 var ConnHdlr vc_conn;
1174 var ConnHdlrPars pars;
1175 f_init();
1176 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1177 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1178 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1179 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1180 vc_conn.done;
1181 }
1182 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001183 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001184}
1185
Harald Welte55700662018-03-12 13:15:43 +01001186/* Test if SACH information is modified as expected */
1187private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1188 var octetstring si5 := f_rnd_octstring(19);
1189 var octetstring si6 := f_rnd_octstring(19);
1190
1191 /* First, configure both SI5 and SI6 to be transmitted */
1192 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1193 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1194
1195 f_l1_tune(L1CTL);
1196 RSL.clear;
1197
1198 /* activate the logical channel */
1199 f_est_dchan();
1200 L1CTL.clear;
1201
1202 /* check that SACCH actually are received as expected */
1203 f_sacch_present(si5);
1204 f_sacch_present(si6);
1205
1206 /* disable SI6 */
1207 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1208
1209 /* check that SI5 is still transmitted */
1210 f_sacch_present(si5);
1211 /* check if SI6 is now gone */
1212 f_sacch_missing(si6);
1213
1214 /* release the channel */
1215 f_rsl_chan_deact();
1216 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1217}
1218testcase TC_sacch_multi_chg() runs on test_CT {
1219 var ConnHdlr vc_conn;
1220 var ConnHdlrPars pars;
1221 f_init();
1222 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1223 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1224 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1225 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1226 vc_conn.done;
1227 }
1228 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001229 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001230}
1231
Harald Weltec8d363c2019-05-19 20:36:48 +02001232/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1233private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1234 var octetstring si5 := f_rnd_octstring(19);
1235 var octetstring si6 := f_rnd_octstring(19);
1236 var octetstring si5_specific := f_rnd_octstring(19);
1237 var octetstring si6_specific := f_rnd_octstring(19);
1238
1239 /* First, configure both SI5 and SI6 to be transmitted */
1240 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1241 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1242
1243 f_l1_tune(L1CTL);
1244 RSL.clear;
1245
1246 /* activate channel with different SACCH filling */
1247 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1248 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1249 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1250 }));
1251 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1252 RSL_IE_Body:{sacch_info := sacch_info})) };
1253 f_est_dchan(more_ies := addl_ies);
1254
1255 /* check that SACCH actually are received as expected */
1256 f_sacch_present(si5_specific);
1257 f_sacch_present(si6_specific);
1258
1259 /* release the channel */
1260 f_rsl_chan_deact();
1261 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1262}
1263testcase TC_sacch_chan_act() runs on test_CT {
1264 var ConnHdlr vc_conn;
1265 var ConnHdlrPars pars;
1266 f_init();
1267
1268 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1269 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1270 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1271 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1272 vc_conn.done;
1273 }
1274 /* TODO: do the above in parallel, rather than sequentially? */
1275 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1276}
1277
Harald Welte8b01c792019-05-19 22:51:25 +02001278/* verify that SACCH DL transmission is started only if MS power IE present
1279 * see section 4.1.3 of 3GPP TS 48.058 */
1280private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1281 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001282 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001283
1284 f_l1_tune(L1CTL);
1285 RSL.clear;
1286
1287 /* Step 1: Activate ASYNC HO channel without MS power IE */
1288
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001289 var integer ho_ref := oct2int(f_rnd_octstring(1));
1290 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1291 RSL_IE_Body:{ handover_ref := ho_ref }));
1292 var RSL_IE_List addl_ies := {
1293 ho_ref_ie
1294 };
1295
Harald Welte8b01c792019-05-19 22:51:25 +02001296 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001297 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 +02001298 /* don't perform immediate assignment here, as we're testing non-IA case */
1299 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001300 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001301
1302 /* Verify that no DL SACCH is being received */
1303 f_sacch_missing(?);
1304
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001305 /* Send handover Access Burst and expect SACCH to start */
1306 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1307
1308 f_sacch_present(si5);
1309
Harald Welte8b01c792019-05-19 22:51:25 +02001310 f_rsl_chan_deact();
1311 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1312
1313
1314 /* Step 2: Activate ASYNC HO channel with MS power IE */
1315
1316 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001317 addl_ies := {
1318 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001319 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1320 };
1321 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1322 /* don't perform immediate assignment here, as we're testing non-IA case */
1323 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001324 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001325
1326 /* Verify that DL SACCH is being received */
1327 f_sacch_present(si5);
1328
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001329 /* Send handover Access Burst and expect SACCH to remain present */
1330 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1331
1332 f_sacch_present(si5);
1333
Harald Welte8b01c792019-05-19 22:51:25 +02001334 f_rsl_chan_deact();
1335 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1336}
1337testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1338 var ConnHdlr vc_conn;
1339 var ConnHdlrPars pars;
1340 f_init();
1341
1342 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1343 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1344 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1345 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1346 vc_conn.done;
1347 }
1348 /* TODO: do the above in parallel, rather than sequentially? */
1349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1350}
1351
1352/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1353 * see section 4.1.4 of 3GPP TS 48.058 */
1354private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1355 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001356 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1357
Harald Welte8b01c792019-05-19 22:51:25 +02001358 var RSL_IE_List addl_ies;
1359
1360 f_l1_tune(L1CTL);
1361 RSL.clear;
1362
1363 /* Step 1: Activate SYNC HO channel without MS power IE */
1364
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001365 var integer ho_ref := oct2int(f_rnd_octstring(1));
1366 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1367 RSL_IE_Body:{ handover_ref := ho_ref }));
1368 addl_ies := {
1369 ho_ref_ie
1370 };
1371
Harald Welte8b01c792019-05-19 22:51:25 +02001372 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001373 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 +02001374 /* don't perform immediate assignment here, as we're testing non-IA case */
1375 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001376 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001377
1378 /* Verify that no DL SACCH is being received */
1379 f_sacch_missing(?);
1380
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001381 /* Send handover Access Burst and expect SACCH to start */
1382 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1383
1384 f_sacch_present(si5);
1385
Harald Welte8b01c792019-05-19 22:51:25 +02001386 f_rsl_chan_deact();
1387 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1388
1389
1390 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1391
1392 /* Activate channel on BTS side */
1393 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001394 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001395 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1396 };
1397 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1398 /* don't perform immediate assignment here, as we're testing non-IA case */
1399 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001400 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001401
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001402 /* Verify that DL SACCH is being received, because MS Power IE was sent */
1403 f_sacch_present(si5);
Harald Welte8b01c792019-05-19 22:51:25 +02001404
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001405 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001406 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1407
1408 f_sacch_present(si5);
1409
Harald Welte8b01c792019-05-19 22:51:25 +02001410 f_rsl_chan_deact();
1411 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1412
1413
1414 /* Step 2b: Activate SYNC HO channel with TA IE */
1415
1416 /* Activate channel on BTS side */
1417 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001418 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001419 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1420 };
1421 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1422 /* don't perform immediate assignment here, as we're testing non-IA case */
1423 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001424 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001425
1426 /* Verify that no DL SACCH is being received */
1427 f_sacch_missing(?);
1428
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001429 /* Send handover Access Burst and expect SACCH to start */
1430 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1431
1432 f_sacch_present(si5);
1433
Harald Welte8b01c792019-05-19 22:51:25 +02001434 f_rsl_chan_deact();
1435 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1436
1437
1438 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1439
1440 /* Activate channel on BTS side */
1441 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001442 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001443 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1444 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1445 };
1446 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1447 /* don't perform immediate assignment here, as we're testing non-IA case */
1448 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001449 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001450
1451 /* Verify that DL SACCH is being received */
1452 f_sacch_present(si5);
1453
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001454 /* Send handover Access Burst and expect SACCH to remain present */
1455 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1456
1457 f_sacch_present(si5);
1458
Harald Welte8b01c792019-05-19 22:51:25 +02001459 f_rsl_chan_deact();
1460 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1461}
1462testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1463 var ConnHdlr vc_conn;
1464 var ConnHdlrPars pars;
1465 f_init();
1466
1467 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1468 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1469 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1470 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1471 vc_conn.done;
1472 }
1473 /* TODO: do the above in parallel, rather than sequentially? */
1474 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1475}
Harald Welte629cc6b2018-03-11 17:19:05 +01001476
1477
1478/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001479 * RACH Handling
1480 ***********************************************************************/
1481
Harald Welte8c24c2b2018-02-26 08:31:31 +01001482/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001483private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001484 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001485 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001486 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001487
Harald Welte8c24c2b2018-02-26 08:31:31 +01001488 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001489 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001490 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001491 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001492 if (emerg == true) {
1493 ra := f_rnd_ra_emerg();
1494 } else {
1495 ra := f_rnd_ra_cs();
1496 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001497 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1498 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001499 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001500 }
1501 fn_last := fn;
1502
1503 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001504 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001505 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001506 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001507 T.stop;
1508 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001509 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001510 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001511 }
1512 [] RSL_CCHAN.receive { repeat; }
1513 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001514 test_failed := true;
1515 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001516 }
1517 }
1518 }
Maxba06feb2019-03-05 10:52:46 +01001519 if (test_failed) {
1520 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001521 }
Maxba06feb2019-03-05 10:52:46 +01001522 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001523 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001524}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001525
Philipp Maier16ade782020-07-08 21:36:00 +02001526/* Normal variant */
1527testcase TC_rach_content() runs on test_CT {
1528 f_TC_rach_content(emerg := false);
1529}
1530
1531/* Emergency call variant */
1532testcase TC_rach_content_emerg() runs on test_CT {
1533 f_TC_rach_content(emerg := true);
1534}
1535
Harald Welte8c24c2b2018-02-26 08:31:31 +01001536/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1537testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001538 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001539 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001540 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001541 f_l1_tune(L1CTL);
1542
1543 var GsmFrameNumber fn_last := 0;
1544 for (var integer i := 0; i < 1000; i := i+1) {
1545 var OCT1 ra := f_rnd_ra_cs();
1546 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1547 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001548 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001549 }
1550 fn_last := fn;
1551 }
1552 var integer rsl_chrqd := 0;
1553 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001554 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001555 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001556 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001557 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001558 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001559 repeat;
1560 }
1561 [] RSL_CCHAN.receive { repeat; }
1562 [] T.timeout { }
1563 }
1564 if (rsl_chrqd == 1000) {
1565 setverdict(pass);
1566 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001567 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001568 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001570}
1571
Harald Welte3453ab42019-05-24 21:19:58 +02001572private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1573 var charstring bts_str := "bts " & int2str(bts_nr);
1574 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1575}
1576
1577/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1578private template integer tr_rach_slots_per_interval := (90 .. 130);
1579
1580/* Expect 0 RACH load on an idle BTS that has just started up */
1581testcase TC_rach_load_idle_thresh0() runs on test_CT {
1582 var ASP_RSL_Unitdata rx_ud;
1583
1584 f_init_vty_bsc();
1585 /* send load indications even at 0% load */
1586 f_vty_load_ind_thresh(0);
1587 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1588 f_sleep(2.0);
1589
1590 f_init();
1591
Harald Weltee37f9a52020-10-11 20:45:23 +02001592 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1593 alt {
1594 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1595 [] RSL_CCHAN.receive { repeat }
1596 }
1597
Harald Welte3453ab42019-05-24 21:19:58 +02001598 timer T := 5.0;
1599 T.start;
1600 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001601 [] 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 +02001602 setverdict(pass);
1603 repeat;
1604 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001605 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001606 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1607 repeat;
1608 }
1609 [] RSL_CCHAN.receive {
1610 repeat;
1611 }
1612 [] T.timeout { }
1613 }
1614
1615 f_vty_load_ind_thresh(10);
1616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1617}
1618
1619/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1620testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1621 var ASP_RSL_Unitdata rx_ud;
1622
1623 f_init_vty_bsc();
1624 f_init();
1625
1626 timer T := 5.0;
1627 T.start;
1628 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001629 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001630 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1631 repeat;
1632 }
1633 [] RSL_CCHAN.receive {
1634 repeat;
1635 }
1636 [] T.timeout {
1637 setverdict(pass);
1638 }
1639 }
1640
1641 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1642}
1643
1644/* Expect 0 RACH load on an idle BTS that has just started up */
1645testcase TC_rach_load_count() runs on test_CT {
1646 var ASP_RSL_Unitdata rx_ud;
1647 var integer load_access_count := 0;
1648
1649 f_init_vty_bsc();
1650 /* send load indications even at 0% load */
1651 f_vty_load_ind_thresh(0);
1652 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1653 f_sleep(2.0);
1654 f_init();
1655
1656 f_init_l1ctl();
1657 f_sleep(1.0);
1658 f_l1_tune(L1CTL);
1659
Harald Welte52ae1682020-10-11 20:45:55 +02001660 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1661 alt {
1662 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1663 [] RSL_CCHAN.receive { repeat }
1664 }
1665
Harald Welte3453ab42019-05-24 21:19:58 +02001666 var GsmFrameNumber fn_last := 0;
1667 for (var integer i := 0; i < 1000; i := i+1) {
1668 var OCT1 ra := f_rnd_ra_cs();
1669 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1670 if (fn == fn_last) {
1671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1672 }
1673 fn_last := fn;
1674 }
1675
1676 timer T := 5.0;
1677 T.start;
1678 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001679 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001680 -> value rx_ud {
1681 var RSL_IE_Body ie;
1682 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1683 load_access_count := load_access_count + ie.rach_load.access_count;
1684 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1685 setverdict(fail, "Access count cannot be < Busy count");
1686 }
1687 repeat;
1688 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001689 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001690 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1691 repeat;
1692 }
1693 [] RSL_CCHAN.receive {
1694 repeat;
1695 }
1696 [] T.timeout { }
1697 }
1698 if (load_access_count == 1000) {
1699 setverdict(pass);
1700 } else {
1701 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1702 }
1703
1704 f_vty_load_ind_thresh(10);
1705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1706}
1707
Harald Welte54a2a2d2018-02-26 09:14:05 +01001708private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001709 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001710 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001711 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001712 f_sleep(0.5);
1713
1714 /* Transmit RACH request + wait for confirmation */
1715 var OCT1 ra := f_rnd_ra_cs();
1716 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1717
1718 /* Check for expected result */
1719 timer T := 1.5;
1720 T.start;
1721 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001722 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001723 setverdict(pass);
1724 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001725 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001727 }
1728 [] RSL_CCHAN.receive { repeat; }
1729 [not expect_pass] T.timeout {
1730 setverdict(pass);
1731 }
1732 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001733 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001734 }
1735 }
1736}
1737
1738/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1739testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001740 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001741 f_init_l1ctl();
1742 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001743 f_sleep(1.0);
1744
1745 /* default max-ta is 63 (full range of GSM timing advance */
1746
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001747 /* We allow early arrival up to 2 symbols */
1748 f_rach_toffs(-1*256, true);
1749 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001750 f_rach_toffs(-10*256, false);
1751
1752 /* 0 / 32 / 63 bits is legal / permitted */
1753 f_rach_toffs(0, true);
1754 f_rach_toffs(32*256, true);
1755 f_rach_toffs(63*256, true);
1756
1757 /* more than 63 bits is not legal / permitted */
1758 f_rach_toffs(64*256, false);
1759 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001761}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001762
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001763private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001764 var GsmFrameNumber fn;
1765 var RSL_Message rm;
1766
1767 f_l1_tune(L1CTL);
1768 RSL.clear;
1769
1770 /* Generate a random Handover Reference */
1771 var integer ho_ref := oct2int(f_rnd_octstring(1));
1772
1773 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1774 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1775 RSL_IE_Body:{ handover_ref := ho_ref }));
1776
1777 /* Activate a channel on the BTS side (no encryption) */
1778 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1779 act_type := t_RSL_IE_ActType_HO_SYNC);
1780
1781 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1782 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001783 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001784
1785 /* Send handover Access Burst */
1786 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1787
1788 /* TODO: test mismatching Handover Reference, and missing IE */
1789
1790 /* Wait for handover detection */
1791 timer T := 3.0;
1792 T.start;
1793 alt {
1794 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1795 log("Handover RACH has been detected: ", rm);
1796 setverdict(pass);
1797 }
1798 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1800 log2str("RSL_CHAN_RQD was not expected: ", rm));
1801 }
1802 [] RSL.receive { repeat; }
1803 [] T.timeout {
1804 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1805 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1806 }
1807 }
1808
1809 /* Release the channel */
1810 f_rsl_chan_deact();
1811 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1812}
1813
1814/* Test handover RACH detection */
1815testcase TC_ho_rach() runs on test_CT {
1816 var ConnHdlrPars pars;
1817 var ConnHdlr vc_conn;
1818
1819 f_init();
1820
1821 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1822 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1823 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1824 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1825 vc_conn.done;
1826 }
1827
1828 /* TODO: do the above in parallel, rather than sequentially? */
1829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1830}
1831
Harald Welte93640c62018-02-25 16:59:33 +01001832/***********************************************************************
1833 * Measurement Processing / Reporting
1834 ***********************************************************************/
1835
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001836private template (value) LapdmAddressField
1837ts_LapdmAddr(template (value) LapdmSapi sapi,
1838 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001839 spare := '0'B,
1840 lpd := 0,
1841 sapi := sapi,
1842 c_r := c_r,
1843 ea := true
1844}
1845
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001846private template (value) LapdmFrameAB
1847ts_LAPDm_AB(template (value) LapdmSapi sapi,
1848 template (value) GsmRrL3Message l3,
1849 template (value) boolean c_r := false,
1850 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01001851 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001852 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01001853 len := 0, /* overwritten */
1854 m := false,
1855 el := 1,
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001856 payload := enc_GsmRrL3Message(valueof(l3))
Harald Welte70767382018-02-21 12:16:40 +01001857}
1858
1859/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001860private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001861 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01001862 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001863
Harald Weltef8df4cb2018-03-10 15:15:08 +01001864 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001865 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001866
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001867 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07001868 g_pars.l1_pars.meas_ul.full.rxlev,
1869 g_pars.l1_pars.meas_ul.sub.rxlev,
1870 g_pars.l1_pars.meas_ul.full.rxqual,
1871 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01001872 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001873
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001874 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1875 g_pars.l1_pars.ms_power_level, false,
1876 g_pars.l1_pars.ms_actual_ta);
1877
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01001878 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
1879 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001880
1881 log("Sending Measurement Report: ", l1h, l2);
1882 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001883 repeat;
1884 }
1885}
1886
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07001887/* handle incoming downlink SACCH, decode the L1 header into the given record */
1888private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
1889 boolean do_apply := true)
1890runs on ConnHdlr
1891{
1892 var L1ctlDlMessage l1_dl;
1893
1894 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1895 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
1896 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
1897 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
1898
1899 if (do_apply) {
1900 /* Update TA and MS power to follow what BTS requests */
1901 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
1902 }
1903 }
1904}
1905
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001906private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001907 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001908 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001909 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1910 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001911 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1912 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001913 repeat;
1914 }
1915}
1916
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001917private altstep as_l1_tch_loop() runs on ConnHdlr {
1918 var L1ctlDlMessage l1_dl;
1919 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1920 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001921
1922 /* occasionaly inject FACCH frames into the uplink */
1923 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1924 var octetstring pl := '010301'O;
1925 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1926 f_pad_oct(pl, 23, '2B'O)));
1927 } else {
1928 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1929 l1_dl.payload.traffic_ind.data));
1930 }
1931
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001932 repeat;
1933 }
1934}
1935
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001936private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001937 uint6_t rxlev,
1938 uint3_t rxqual
1939}
1940
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001941private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001942 MeasElem full,
1943 MeasElem sub
1944}
1945
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001946private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001947 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001948 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001949 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01001950 MeasElemFS meas_ul,
1951 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001952 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001953 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02001954 uint8_t ms_actual_ta,
1955 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01001956}
1957
1958/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1959private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1960 return 63 + (toffs256s/256);
1961}
1962
Harald Welted5684392018-03-10 18:22:04 +01001963private function f_max(integer a, integer b) return integer {
1964 if (a > b) {
1965 return a;
1966 } else {
1967 return b;
1968 }
1969}
1970
1971private function f_min(integer a, integer b) return integer {
1972 if (a < b) {
1973 return a;
1974 } else {
1975 return b;
1976 }
1977}
1978
1979/* compute negative tolerance val-tolerance, ensure >= min */
1980private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1981 val := val - tolerance;
1982 return f_max(val, min);
1983}
1984
1985/* compute positive tolerance val+tolerance, ensure <= max */
1986private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1987 val := val + tolerance;
1988 return f_min(val, max);
1989}
1990
1991/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1992private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1993return template integer {
1994 var template integer ret;
1995 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1996 return ret;
1997}
1998
1999
Harald Welte70767382018-02-21 12:16:40 +01002000/* build a template for matching measurement results against */
2001private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2002 var ConnL1Pars l1p := g_pars.l1_pars;
2003 var template RSL_IE_UplinkMeas ul_meas := {
2004 len := 3,
2005 rfu := '0'B,
2006 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002007 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002008 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002009 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002010 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002011 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2012 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002013 supp_meas_info := omit
2014 };
Harald Welte685d5982018-02-27 20:42:05 +01002015 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002016 ul_meas.len := (3+8);
2017 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002018 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002019 toa256_min := ?,
2020 toa256_max := ?,
2021 toa256_std_dev := ?
2022 }
Harald Welte685d5982018-02-27 20:42:05 +01002023 }
Harald Welte70767382018-02-21 12:16:40 +01002024 var template RSL_IE_BS_Power bs_power := {
2025 reserved := 0,
2026 epc := false,
2027 fpc := false,
2028 power_level := l1p.bs_power_level
2029 };
2030 var template RSL_IE_L1Info l1_info := {
2031 ms_power_lvl := l1p.ms_power_level,
2032 fpc := false,
2033 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002034 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002035 };
2036 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002037 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002038 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2039 ?, t_toffs);
2040}
2041
Philipp Maierdd841d32019-12-17 14:44:54 +01002042/* build a template for matching measurement results that do not contain any
2043 * MS related measurement (l1_info, l3_info and ms timing offset). */
2044private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2045 var ConnL1Pars l1p := g_pars.l1_pars;
2046 var template RSL_IE_UplinkMeas ul_meas := {
2047 len := 3,
2048 rfu := '0'B,
2049 dtx_d := l1p.dtx_enabled,
2050 rxlev_f_u := ?,
2051 reserved1 := '00'B,
2052 rxlev_s_u := ?,
2053 reserved2 := '00'B,
2054 rxq_f_u := ?,
2055 rxq_s_u := ?,
2056 supp_meas_info := omit
2057 };
2058 if (l1p.toa256_enabled) {
2059 ul_meas.len := (3+8);
2060 ul_meas.supp_meas_info := {
2061 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2062 toa256_min := ?,
2063 toa256_max := ?,
2064 toa256_std_dev := ?
2065 }
2066 }
2067 var template RSL_IE_BS_Power bs_power := {
2068 reserved := 0,
2069 epc := false,
2070 fpc := false,
2071 power_level := l1p.bs_power_level
2072 };
2073
2074 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2075}
2076
Harald Welte70767382018-02-21 12:16:40 +01002077/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002078private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002079 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002080 var boolean chan_est := false;
2081
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002082 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002083
2084 /* Receive osmocom specific measurement reports. This is the normal
2085 * case. Here we verify that the measurement reports we sent are
2086 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002087 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2088 /* increment counter of next to-be-expected meas rep */
2089 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2090 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002091 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002092
2093 /* The following two cases may only happen in the beginning
2094 * of the channel establishment phase. Once we have received
2095 * the "our" measurement report the first time, the channel
2096 * is established and empty or hardcoded TRXCON reports must
2097 * not occur anymore. */
2098 chan_est := true;
2099
2100 repeat;
2101 }
2102
2103 /* When the BTS has established the channel, the MS might need slightly
2104 * more time to establish the channel and actually start sending. The
2105 * result is then a measurement report that just lacks the measurement
2106 * information of the MS. This is normal and we tolerate this behavior. */
2107 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2108 /* increment counter of next to-be-expected meas rep */
2109 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2110 /* Re-start the timer expecting the next MEAS RES */
2111 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002112 repeat;
2113 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002114
2115 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2116 * measurements if the TTCN3 side does not supply measurement input in
2117 * time. In those cases TRXCON will either use a cached measurement
2118 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2119 * report the templates above will not match. We tolerate this
2120 * behavior, but only once. */
2121 [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 +01002122 /* increment counter of next to-be-expected meas rep */
2123 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2124 if (g_first_meas_res) {
2125 g_first_meas_res := false;
2126 repeat;
2127 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002128 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002129 }
Harald Welte70767382018-02-21 12:16:40 +01002130 }
2131 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002133 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002134 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002136 }
2137}
2138
Harald Weltee613f962018-04-18 22:38:16 +02002139private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2140 select (rsl_alg_id) {
2141 case (RSL_ALG_ID_A5_0) { return 0; }
2142 case (RSL_ALG_ID_A5_1) { return 1; }
2143 case (RSL_ALG_ID_A5_2) { return 2; }
2144 case (RSL_ALG_ID_A5_3) { return 3; }
2145 case (RSL_ALG_ID_A5_4) { return 4; }
2146 case (RSL_ALG_ID_A5_5) { return 5; }
2147 case (RSL_ALG_ID_A5_6) { return 6; }
2148 case (RSL_ALG_ID_A5_7) { return 7; }
2149 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002150 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2151 /* Make compiler happy by calling mtc.stop here. It is already
2152 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002153 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002154 }
2155 }
2156}
2157
2158private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2159 select (rsl_alg_id) {
2160 case (RSL_ALG_ID_A5_1) { return '000'B; }
2161 case (RSL_ALG_ID_A5_2) { return '001'B; }
2162 case (RSL_ALG_ID_A5_3) { return '010'B; }
2163 case (RSL_ALG_ID_A5_4) { return '011'B; }
2164 case (RSL_ALG_ID_A5_5) { return '100'B; }
2165 case (RSL_ALG_ID_A5_6) { return '101'B; }
2166 case (RSL_ALG_ID_A5_7) { return '110'B; }
2167 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002168 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2169 /* Make compiler happy by calling mtc.stop here. It is already
2170 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002171 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002172 }
2173 }
2174}
2175
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002176/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2177private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2178 var GsmFrameNumber fn;
2179 timer T := 8.0;
2180
2181 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2182 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2183
2184 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2185 /* Send the actual RACH */
2186 fn := f_L1CTL_RACH(L1CTL, ra);
2187
2188 T.start;
2189 alt {
2190 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2191 [] T.timeout {
2192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2193 }
2194 }
2195 T.stop
2196 return fn;
2197}
Harald Weltee613f962018-04-18 22:38:16 +02002198
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002199/* Tune to a dedicated channel: L1CTL only */
2200private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002201 if (not pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002202 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07002203 mp_trx_pars[0].arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002204 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002205 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002206 pars.fhp.maio_hsn.hsn,
2207 pars.fhp.maio_hsn.maio,
2208 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002209 }
2210}
2211
Harald Welte70767382018-02-21 12:16:40 +01002212/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002213private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002214 var GsmFrameNumber fn;
2215 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002216 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002217 var integer ra := 23;
2218
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002219 /* Send RACH request and wait for ChanReq */
2220 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002221
2222 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002223 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002224
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002225 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002226 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002227 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002228 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002229 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002230 }
2231
Harald Welte70767382018-02-21 12:16:40 +01002232 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002233 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01002234 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2235
2236 /* receive IMM.ASS on MS side */
2237 var ImmediateAssignment ia_um;
2238 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002239
2240 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2241 if (ch_desc.h != ia_um.chan_desc.h) {
2242 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2243 }
2244
Harald Welte70767382018-02-21 12:16:40 +01002245 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002246 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002247 /* enable encryption, if requested */
2248 if (encr_enable) {
2249 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2250 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2251 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002252
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002253 /* Send TCH Mode Request to the L1 if needed */
2254 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2255 var L1ctlTchMode tch_mode;
2256
2257 select (g_pars.chan_mode.coding_alg_rate) {
2258 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2259 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2260 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2261 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2262 case else {
2263 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2264 " is not supported by the L1, falling back to signalling");
2265 tch_mode := L1CTL_CHAN_MODE_SIGN;
2266 }
2267 }
2268
2269 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2270 }
2271
Harald Weltefa45e9e2018-03-10 18:59:03 +01002272 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002273}
2274
2275/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002276private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002277 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002278 RSL.clear;
2279
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002280 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002281 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002282 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002283 }
Harald Welte70767382018-02-21 12:16:40 +01002284
2285 f_est_dchan();
2286
2287 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2288 * RSL measurement reports on Abis side */
2289 timer T := 8.0;
2290 T.start;
2291 alt {
2292 [] as_l1_sacch();
2293 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002294 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002295 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002296 [] L1CTL.receive { repeat; }
2297 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002298 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002299 * of any earlier errors, so if we reach this timeout, we're good */
2300 setverdict(pass);
2301 }
2302 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002303 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002304 }
2305 }
2306 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002307 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002308}
Harald Welte0472ab42018-03-12 15:02:26 +01002309
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002310/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2311private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002312 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002313 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2314 timer Tup := 10.0;
2315 Tup.start;
2316 alt {
2317 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2318 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2319 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002320
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002321 if (rx_lvl != max_rx_lvl) {
2322 repeat;
2323 }
2324 Tup.stop;
2325 }
2326 [] L1CTL.receive { repeat; }
2327 [] Tup.timeout {
2328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2329 log2str("Didn't reach full power ", max_rx_lvl));
2330 }
2331 }
2332 return max_rx_lvl;
2333}
2334
2335/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2336private function f_verify_ramp_up() runs on ConnHdlr {
2337 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002338 var integer initial_rx_lvl := -1;
2339 var integer last_rx_lvl := -1;
2340 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2341
2342 timer T := 2.0;
2343 alt {
2344 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2345 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2346 log("Received rx_level=", rx_lvl);
2347 if (initial_rx_lvl == -1) {
2348 initial_rx_lvl := rx_lvl;
2349 last_rx_lvl := rx_lvl;
2350
2351 /* Expect a somehow low value during first received messages */
2352 if (initial_rx_lvl >= max_rx_lvl / 2) {
2353 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2354 log2str("Detected high initial tx power during ramp up: ",
2355 initial_rx_lvl , ", full power is", max_rx_lvl));
2356 }
2357 }
2358
2359 /* received Rx level bigger than maximum allowed power by CN */
2360 if (rx_lvl > max_rx_lvl) {
2361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2362 log2str("Detected Tx power higher than full power: ",
2363 rx_lvl , " > ", max_rx_lvl));
2364 }
2365
2366 /* Make sure it never decreases, since we are rumping up */
2367 if (last_rx_lvl > rx_lvl) {
2368 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2369 log2str("Detected Tx power decrease during ramp up: ",
2370 last_rx_lvl , " -> ", rx_lvl));
2371 }
2372
2373 if (rx_lvl == max_rx_lvl and not T.running) {
2374 /* We reached the maximum power, start timer and receive
2375 /* a few more to make sure we don't surpass it */
2376 log("Reached full power, wating a bit more until success");
2377 T.start;
2378 }
2379
2380 last_rx_lvl := rx_lvl;
2381 repeat;
2382 }
2383 [] L1CTL.receive { repeat; }
2384 [] T.timeout { }
2385 }
2386
2387 /* We didn't increase tx power during ramp up */
2388 if (initial_rx_lvl < last_rx_lvl) {
2389 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2390 } else {
2391 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2392 log2str("No Tx power increase during whole ramp up: ",
2393 initial_rx_lvl , " -> ", last_rx_lvl));
2394 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002395}
2396
2397/* verify BTS ramps power down to rx_level 0 */
2398private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2399 var L1ctlDlMessage l1_dl;
2400 var integer last_rx_lvl := max_rx_lvl;
2401
2402 timer Tdown := 5.0;
2403 Tdown.start;
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
2409 /* received Rx level bigger than maximum allowed power by CN */
2410 if (rx_lvl > max_rx_lvl) {
2411 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2412 log2str("Detected Tx power higher than full power: ",
2413 rx_lvl , " > ", max_rx_lvl));
2414 }
2415
2416 /* Make sure it never increases, since we are rumping down */
2417 if (last_rx_lvl < rx_lvl) {
2418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2419 log2str("Detected Tx power increase during ramp up: ",
2420 last_rx_lvl , " -> ", rx_lvl));
2421 }
2422
2423 last_rx_lvl := rx_lvl;
2424 if (last_rx_lvl != 0) {
2425 repeat;
2426 }
2427 /* we reached power level 0, we are done */
2428 Tdown.stop;
2429 }
2430 [] L1CTL.receive { repeat; }
2431 [] Tdown.timeout { }
2432 }
2433
2434 /* We didn't increase tx power during ramp down */
2435 if (max_rx_lvl > last_rx_lvl) {
2436 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2437 } else {
2438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2439 log2str("No Tx power decrease during whole ramp down: ",
2440 max_rx_lvl , " -> ", last_rx_lvl));
2441 }
2442}
2443
2444/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002445private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002446 f_l1_tune(L1CTL);
2447 RSL.clear;
2448
2449 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002450
2451 setverdict(pass);
2452}
2453testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2454 var ConnHdlr vc_conn;
2455 var ConnHdlrPars pars;
2456 f_init();
2457 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2458 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2459 pcu_comp := false, trxc_comp := true);
2460 vc_conn.done;
2461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2462}
2463
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002464/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002465private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002466 f_connhdlr_init_vty_bsc();
2467
2468 f_l1_tune(L1CTL);
2469 RSL.clear;
2470
2471 /* Wait until BTS is started and at full power */
2472 var integer max_rx_lvl := f_wait_ramp_up();
2473 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2474
2475 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2476 f_verify_ramp_down(max_rx_lvl);
2477
2478 setverdict(pass);
2479}
2480testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2481 var ConnHdlr vc_conn;
2482 var ConnHdlrPars pars;
2483 f_init();
2484 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2485 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2486 pcu_comp := false, trxc_comp := true);
2487 vc_conn.done;
2488 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2489}
2490
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002491/* Verify Tx power:
2492 * + ramping down during ADM state UNLOCKED->LOCKED
2493 * + ramping up during ADM state LOCKED->UNLOCKED
2494 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002495private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002496 var L1ctlDlMessage l1_dl;
2497 var integer last_rx_lvl;
2498
2499 f_connhdlr_init_vty_bsc();
2500
2501 f_l1_tune(L1CTL);
2502 RSL.clear;
2503
2504 /* Wait until BTS is started and at full power */
2505 var integer max_rx_lvl := f_wait_ramp_up();
2506 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2507
2508 log("ADM STATE UNLOCKED->LOCKED");
2509 f_vty_enter_cfg_trx(BSCVTY);
2510 f_vty_transceive(BSCVTY, "rf_locked 1");
2511 last_rx_lvl := max_rx_lvl;
2512 f_verify_ramp_down(max_rx_lvl);
2513
2514 /* Let some time after we received 0dBm, then check we don't receive BCCH
2515 * anymore because scheduler has stopped after ramping down */
2516 f_sleep(2.0);
2517 L1CTL.clear;
2518 timer Tlocked := 2.0;
2519 Tlocked.start;
2520 alt {
2521 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2523 log2str("Received data_ind during rf_locked: ", l1_dl));
2524 }
2525 [] L1CTL.receive { repeat; }
2526 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2527 }
2528
2529 log("ADM STATE LOCKED->UNLOCKED");
2530 f_vty_transceive(BSCVTY, "rf_locked 0");
2531 f_verify_ramp_up();
2532 setverdict(pass);
2533}
2534testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2535 var ConnHdlr vc_conn;
2536 var ConnHdlrPars pars;
2537 f_init();
2538 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2539 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2540 pcu_comp := false, trxc_comp := true);
2541 vc_conn.done;
2542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2543}
2544
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002545private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002546 timer T := 8.0;
2547 T.start;
2548 var RSL_Message rsl;
2549 alt {
2550 [] as_l1_sacch();
2551 [] L1CTL.receive { repeat; }
2552 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2553 if (rsl.ies[3].body.bs_power.power_level == level) {
2554 setverdict(pass)
2555 } else {
2556 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2557 }
2558 }
2559 [] T.timeout {
2560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2561 }
2562 }
2563}
2564
2565/* see if the rsl meas res contains our expeced bs power level
2566bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002567private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002568 f_l1_tune(L1CTL);
2569 RSL.clear;
2570
2571 if (mp_bts_trxc_port != -1) {
2572 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2573 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2574 }
2575
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002576 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002577 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2578 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2579
2580 f_est_dchan(more_ies :={valueof(pwr)});
2581
2582 f_check_meas_bs_power_level(pwr_var);
2583
2584 f_rsl_chan_deact();
2585 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2586}
2587
2588/* see if the rsl meas res contains our expeced bs power level
2589bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002590private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002591 f_l1_tune(L1CTL);
2592 RSL.clear;
2593
2594 if (mp_bts_trxc_port != -1) {
2595 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2596 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2597 }
2598
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002599 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002600 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2601
2602 f_est_dchan();
2603
2604 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2605
2606 f_check_meas_bs_power_level(pwr_var);
2607
2608 f_rsl_chan_deact();
2609 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2610}
2611
2612testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2613 var ConnHdlr vc_conn;
2614 var ConnHdlrPars pars;
2615 f_init();
2616 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2617 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2618 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2619 pcu_comp := false, trxc_comp := true);
2620 vc_conn.done;
2621 }
2622 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2623}
2624
2625testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2626 var ConnHdlr vc_conn;
2627 var ConnHdlrPars pars;
2628 f_init();
2629 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2630 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2631 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2632 pcu_comp := false, trxc_comp := true);
2633 vc_conn.done;
2634 }
2635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2636}
2637
Eric Wild61edb7e2019-06-03 12:38:31 +02002638/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2639second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2640These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002641private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002642 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002643 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002644
2645 f_trxc_fake_rssi(rxlev2dbm(10));
2646 f_l1_tune(L1CTL);
2647 RSL.clear;
2648
2649 var RSL_IE_List addl_ies;
2650 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2651
2652 addl_ies := {
2653 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2654 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2655 };
2656
2657 /* establish with power parameters */
2658 f_est_dchan(more_ies := addl_ies);
2659
2660 /* set a high value to ensure L1 power control level increases */
2661 f_trxc_fake_rssi(rxlev2dbm(20));
2662
2663 timer T2 := 6.0;
2664 T2.start;
2665 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002666 [] as_l1_sacch_l1h(l1h) {
2667 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002668 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002669 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002670 T2.stop;
2671 }
2672 [] L1CTL.receive { repeat; }
2673 [] T2.timeout {
2674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2675 "Power Level in L1 header has not increased sufficiently");
2676 }
2677 }
2678
2679 /* set a low value to ensure L1 power control level decreases */
2680 f_trxc_fake_rssi(rxlev2dbm(0));
2681
2682 timer T4 := 6.0;
2683 T4.start;
2684 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002685 [] as_l1_sacch_l1h(l1h) {
2686 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002687 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002688 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002689 T4.stop;
2690 setverdict(pass, "Power level in L1 decreased/increased as expected");
2691 }
2692 [] L1CTL.receive { repeat; }
2693 [] T4.timeout {
2694 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2695 "Power Level in L1 header has not decreased sufficiently");
2696 }
2697 }
2698
2699 f_rsl_chan_deact();
2700 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2701
2702}
2703
2704/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002705private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002706 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002707 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002708
2709 /* set a low value to ensure power increases */
2710 f_trxc_fake_rssi(rxlev2dbm(10));
2711 f_l1_tune(L1CTL);
2712 RSL.clear;
2713
2714 var RSL_IE_List addl_ies;
2715 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2716
2717 addl_ies := {
2718 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2719 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2720 };
2721
2722 /* establish with power parameters */
2723 f_est_dchan(more_ies := addl_ies);
2724
2725 timer T1 := 10.0;
2726 T1.start;
2727 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002728 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002729 [] L1CTL.receive { repeat; }
2730 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002731 if (not isbound(l1h)) {
2732 setverdict(fail, "No SACCH blocks were received");
2733 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002734 setverdict(fail, "Power level in L1 header should not have changed");
2735 }
2736 }
2737 }
2738
2739 f_rsl_chan_deact();
2740 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2741
2742}
2743
2744/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002745private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002746 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002747 var uint5_t pwr_var := 15;
2748 var uint5_t pwr_max_var := f_get_max_power_from_band();
2749
2750 /* set a low value to ensure power increases */
2751 f_trxc_fake_rssi(rxlev2dbm(10));
2752 f_l1_tune(L1CTL);
2753 RSL.clear;
2754
2755 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2756 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2757
2758 /* establish with fixed power level */
2759 f_est_dchan(more_ies :={valueof(pwr)});
2760
2761 /* check our initial power level */
2762 f_wait_for_l1_power_level(pwr_var);
2763
2764 /* update power param to enable power loop
2765 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2766 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2767
2768 /* wait, then check that our power level was reduced */
2769 timer T1 := 10.0;
2770 T1.start;
2771 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002772 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002773 [] L1CTL.receive { repeat; }
2774 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002775 if (not isbound(l1h)) {
2776 setverdict(fail, "No SACCH blocks were received");
2777 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002778 setverdict(pass, "Power level in L1 header reduced as expected");
2779 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002780 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
2781 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02002782 }
2783 }
2784 }
2785
2786 f_rsl_chan_deact();
2787 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2788
2789}
2790
2791/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002792private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002793 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002794
2795 /* set a high value to ensure power decreases */
2796 f_trxc_fake_rssi(rxlev2dbm(50));
2797 f_l1_tune(L1CTL);
2798 RSL.clear;
2799
2800 var uint5_t pwr_var := 5;
2801 var uint5_t pwr_target_val := 15;
2802
2803 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2804 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2805
2806 /* establish with fixed power level */
2807 f_est_dchan(more_ies :={valueof(pwr)});
2808
2809 /* check our initial power level */
2810 f_wait_for_l1_power_level(pwr_var);
2811
2812 /* update power param to enable power loop
2813 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002814 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002815
2816 /* wait, then check that our power level was increased */
2817 timer T1 := 10.0;
2818 T1.start;
2819 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002820 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002821 [] L1CTL.receive { repeat; }
2822 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002823 if (not isbound(l1h)) {
2824 setverdict(fail, "No SACCH blocks were received");
2825 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
2826 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002827 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002828 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002829 }
2830 }
2831 }
2832
2833 f_rsl_chan_deact();
2834 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2835
2836}
2837
Eric Wild095024b2019-06-17 15:08:57 +02002838/* see if we change the power level without receiving power parameters, which should not happen
2839rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002840private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002841 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02002842
2843 /* set a high value to ensure power decreases */
2844 f_trxc_fake_rssi(rxlev2dbm(50));
2845 f_l1_tune(L1CTL);
2846 RSL.clear;
2847
2848 var uint5_t pwr_var := 5;
2849
2850 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2851 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2852
2853 /* establish with fixed power level */
2854 f_est_dchan(more_ies :={valueof(pwr)});
2855
2856 /* check our initial power level */
2857 f_wait_for_l1_power_level(pwr_var);
2858
2859 /* wait, then check that our power level did not change */
2860 timer T1 := 10.0;
2861 T1.start;
2862 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002863 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2864 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02002865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2866 "BS power control should not be active unless we receive a power parameters IE!");
2867 }
2868 repeat;
2869 }
2870 [] L1CTL.receive { repeat; }
2871 [] T1.timeout { setverdict(pass); }
2872 }
2873
2874 f_rsl_chan_deact();
2875 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2876
2877}
2878
Eric Wild095024b2019-06-17 15:08:57 +02002879/* see if we change the power level without receiving power parameters, which should not happen
2880ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002881private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002882 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02002883
2884 /* set a high value to ensure power decreases */
2885 f_trxc_fake_rssi(rxlev2dbm(50));
2886 f_l1_tune(L1CTL);
2887 RSL.clear;
2888
2889 var uint5_t pwr_var := 5;
2890
2891 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2892 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2893
2894 /* establish with fixed power level */
2895 f_est_dchan(more_ies :={valueof(pwr)});
2896
2897 /* check our initial power level */
2898 f_wait_for_l1_power_level(pwr_var);
2899
2900 /* pwr control without power params IE, should NOT activate MS power control*/
2901 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2902
2903 /* wait, then check that our power level did not change */
2904 timer T1 := 10.0;
2905 T1.start;
2906 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002907 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2908 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02002909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2910 "BS power control should not be active unless we receive a power parameters IE!");
2911 }
2912 repeat;
2913 }
2914 [] L1CTL.receive { repeat; }
2915 [] T1.timeout { setverdict(pass); }
2916 }
2917
2918 f_rsl_chan_deact();
2919 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2920
2921}
2922
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002923private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002924 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002925 timer T0 := 10.0;
2926 T0.start;
2927 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002928 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2929 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002930 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2931 "Power level in L1 header != signaled (RSL) power level.");
2932 }
2933 }
2934 [] L1CTL.receive { repeat; }
2935 [] T0.timeout {
2936 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2937 "Timeout waiting for initial power level");
2938 }
2939 }
2940 T0.stop;
2941}
2942
2943private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2944 var IntegerRecord min_dbm_level;
2945 var IntegerRecord max_dbm_level;
2946 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2947
2948 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2949 if (min_dbm_level[i] == level) {
2950 return true;
2951 }
2952 }
2953 return false;
2954}
2955
2956private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2957 var IntegerRecord min_dbm_level;
2958 var IntegerRecord max_dbm_level;
2959 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2960
2961 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2962 if (max_dbm_level[i] == level) {
2963 return true;
2964 }
2965 }
2966 return false;
2967}
2968
2969private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2970 var IntegerRecord min_dbm_level;
2971 var IntegerRecord max_dbm_level;
2972 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2973 return max_dbm_level[0];
2974}
2975
2976type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002977private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002978private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2979 // 45.005 4.1.1
2980 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2981 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2982 2, 1, 0};
2983 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2984 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2985 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2986 var IntegerRecord rv;
2987
2988 select(band){
2989 case (BtsBand_allGSM){
2990 rv := gsm_power;
2991 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2992 max_dbm_level := {2, 1, 0};
2993 }
2994 case("DCS1800"){
2995 rv := dcs_power;
2996 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2997 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2998 }
2999 case("PCS1900"){
3000 rv := pcs_power;
3001 min_dbm_level := {15};
3002 max_dbm_level := {30};
3003 }
Harald Welte194b6912020-10-11 21:01:55 +02003004 case else {
3005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3006 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003007 }
3008
3009 return rv;
3010}
3011
3012private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003013 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 +02003014}
3015
3016testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3017 var ConnHdlr vc_conn;
3018 var ConnHdlrPars pars;
3019 f_init();
3020 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3021 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3022 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3023 pars.bts0_band := f_vty_get_bts0_band();
3024 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3025 vc_conn.done;
3026 }
3027 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3029}
3030
3031testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3032 var ConnHdlr vc_conn;
3033 var ConnHdlrPars pars;
3034 f_init();
3035 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3036 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3037 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3038 pars.bts0_band := f_vty_get_bts0_band();
3039 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3040 vc_conn.done;
3041 }
3042 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3044}
3045
3046testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3047 var ConnHdlr vc_conn;
3048 var ConnHdlrPars pars;
3049 f_init();
3050 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3051 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3052 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3053 pars.bts0_band := f_vty_get_bts0_band();
3054 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3055 vc_conn.done;
3056 }
3057 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3058 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3059}
3060
3061testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3062 var ConnHdlr vc_conn;
3063 var ConnHdlrPars pars;
3064 f_init();
3065 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3066 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3067 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3068 pars.bts0_band := f_vty_get_bts0_band();
3069 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3070 vc_conn.done;
3071 }
3072 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3074}
3075
Eric Wild280ccb82019-06-17 11:11:52 +02003076testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3077 var ConnHdlr vc_conn;
3078 var ConnHdlrPars pars;
3079 f_init();
3080 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3081 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3082 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3083 pars.bts0_band := f_vty_get_bts0_band();
3084 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3085 vc_conn.done;
3086 }
3087 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3088 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3089}
3090
Eric Wild095024b2019-06-17 15:08:57 +02003091testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3092 var ConnHdlr vc_conn;
3093 var ConnHdlrPars pars;
3094 f_init();
3095 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3096 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3097 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3098 pars.bts0_band := f_vty_get_bts0_band();
3099 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3100 vc_conn.done;
3101 }
3102 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3104}
3105
Philipp Maier149c3922020-10-22 17:29:36 +02003106function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003107 var template RSL_IE_ChannelMode ch_mode;
3108 var ConnHdlr vc_conn;
3109 var ConnHdlrPars pars;
3110 f_init();
3111 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3112 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3113 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003114 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003115 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3116 pcu_comp := false, trxc_comp := true);
3117 vc_conn.done;
3118 }
3119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3120}
Philipp Maier149c3922020-10-22 17:29:36 +02003121
3122testcase TC_meas_res_speech_tchf() runs on test_CT {
3123 f_TC_meas_res_speech_tchf(false);
3124}
3125
3126testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3127 f_TC_meas_res_speech_tchf(true);
3128}
3129
3130function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003131 var template RSL_IE_ChannelMode ch_mode;
3132 var ConnHdlr vc_conn;
3133 var ConnHdlrPars pars;
3134 f_init();
3135 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3136 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3137 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003138 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003139 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3140 pcu_comp := false, trxc_comp := true);
3141 vc_conn.done;
3142 }
3143 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3144}
Philipp Maier149c3922020-10-22 17:29:36 +02003145
3146testcase TC_meas_res_speech_tchh() runs on test_CT {
3147 f_TC_meas_res_speech_tchh(false)
3148}
3149
3150testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3151 f_TC_meas_res_speech_tchh(true)
3152}
3153
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003154testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3155 var template RSL_IE_ChannelMode ch_mode;
3156 var ConnHdlr vc_conn;
3157 var ConnHdlrPars pars;
3158 f_init();
3159 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3160 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3161 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3162 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3163 pars.l1_pars.toa256_enabled := true;
3164 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3165 pcu_comp := false, trxc_comp := true);
3166 vc_conn.done;
3167 }
3168 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3169}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003170
Harald Welte70767382018-02-21 12:16:40 +01003171testcase TC_meas_res_sign_tchf() runs on test_CT {
3172 var ConnHdlr vc_conn;
3173 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003174 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003175 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003176 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003177 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3178 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003179 vc_conn.done;
3180 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003182}
3183testcase TC_meas_res_sign_tchh() runs on test_CT {
3184 var ConnHdlr vc_conn;
3185 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003186 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003187 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003188 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003189 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3190 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003191 vc_conn.done;
3192 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003193 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003194}
3195testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3196 var ConnHdlr vc_conn;
3197 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003198 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003199 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3200 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003201 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3202 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003203 vc_conn.done;
3204 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003206}
3207testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3208 var ConnHdlr vc_conn;
3209 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003210 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003211 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3212 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003213 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3214 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003215 vc_conn.done;
3216 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003217 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003218}
Harald Welte685d5982018-02-27 20:42:05 +01003219testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3220 var ConnHdlr vc_conn;
3221 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003222 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003223 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3224 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003225 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003226 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003227 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3228 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003229 vc_conn.done;
3230 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003231 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003232}
3233
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003234/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3235 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003236private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003237 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003238 var RSL_IE_MS_Power ms_power;
3239 var RSL_Message rsl;
3240 var uint5_t power_level := 0;
3241
3242 f_l1_tune(L1CTL);
3243 RSL.clear;
3244
3245 f_est_dchan();
3246
3247 ms_power.reserved := 0;
3248 ms_power.fpc_epc := false;
3249
3250 /* Send the first power control command. This will disable any BTS/TRX
3251 * internal power control and switch the MS (which is not in scope of
3252 * this test) to a constant power level. We start with a power level
3253 * of 0 */
3254 ms_power.power_level := power_level;
3255 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3256 RSL.send(rsl);
3257
3258 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003259 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3260 if (l1h.ms_power_lvl != power_level) {
3261 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3262 "match the signaled (RSL) power level := ", power_level);
3263 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003264 }
3265
3266 /* Signal a new power level via RSL for the next turn. */
3267 if (power_level < 31) {
3268 power_level := power_level + 1;
3269 ms_power.power_level := power_level;
3270 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3271 RSL.send(rsl);
3272 repeat;
3273 }
3274
3275 }
3276
3277 /* Ignore all other blocks */
3278 [] L1CTL.receive { repeat; }
3279
3280 }
3281
3282 f_rsl_chan_deact();
3283 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3284
3285 setverdict(pass);
3286}
3287
3288testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3289 var ConnHdlr vc_conn;
3290 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003291 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003292
3293 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3294 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3295 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3296 vc_conn.done;
3297 }
3298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3299}
Harald Welte70767382018-02-21 12:16:40 +01003300
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003301/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003302TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003303private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003304 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003305 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003306
3307 f_l1_tune(L1CTL);
3308 RSL.clear;
3309
3310 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003311 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003312
3313 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3314
3315
3316 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003317 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3318 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003319 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3320 }
3321
3322 }
3323
3324 /* Ignore all other blocks */
3325 [] L1CTL.receive { repeat; }
3326
3327 }
3328
3329 f_rsl_chan_deact();
3330 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3331
3332 setverdict(pass);
3333}
3334
3335testcase TC_rsl_chan_initial_ta() runs on test_CT {
3336 var ConnHdlr vc_conn;
3337 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003338 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003339 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003340 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3341 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003342 vc_conn.done;
3343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3344}
3345
Eric Wilde57e1a62019-05-28 13:30:55 +02003346/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003347private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003348 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003349 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003350
3351 var RSL_IE_MS_Power ms_power;
3352 ms_power.reserved := 0;
3353 ms_power.fpc_epc := false;
3354 ms_power.power_level := ms_power_level;
3355
3356 f_l1_tune(L1CTL);
3357 RSL.clear;
3358
3359 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3360
3361 timer T := 1.0;
3362 T.start;
3363 alt {
3364 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003365 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3366 if (l1h.ms_power_lvl != ms_power_level) {
3367 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3368 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003369 }
3370 }
3371 /* Ignore all other blocks */
3372 [] L1CTL.receive { repeat; }
3373 [] T.timeout {
3374 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3375 }
3376 }
3377
3378 f_rsl_chan_deact();
3379 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3380 setverdict(pass);
3381}
3382
3383testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3384 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3385 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3386}
3387
Harald Welte0472ab42018-03-12 15:02:26 +01003388/* 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 +01003389private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003390 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003391 RSL.clear;
3392
3393 f_est_dchan();
3394 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003395 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003396
3397 timer T := 40.0;
3398 T.start;
3399 alt {
3400 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3401 setverdict(pass)
3402 }
3403 [] RSL.receive { repeat };
3404 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003406 }
3407 }
3408 f_rsl_chan_deact();
3409}
3410testcase TC_conn_fail_crit() runs on test_CT {
3411 var ConnHdlr vc_conn;
3412 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003413 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003414 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3415 pars.t_guard := 60.0;
3416 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3417 vc_conn.done;
3418}
3419
Harald Welte93640c62018-02-25 16:59:33 +01003420/***********************************************************************
3421 * Paging
3422 ***********************************************************************/
3423
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003424private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003425 if (tmsi == 'FFFFFFFF'O) {
3426 return true;
3427 } else {
3428 return false;
3429 }
3430}
Harald Welte70767382018-02-21 12:16:40 +01003431
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003432private type record allowedFn { integer frame_nr }
3433private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3434private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3435private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3436private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3437private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3438private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3439private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3440private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3441private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003442{
3443 var integer frame_nr_51;
3444 frame_nr_51 := frame_nr mod 51
3445
3446 var allowedFn fn_check;
3447 fn_check.frame_nr := frame_nr_51;
3448
3449 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003451 return;
3452 }
3453
3454 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3455 return;
3456 }
3457 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3458 return;
3459 }
3460 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3461 return;
3462 }
3463 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3464 return;
3465 }
3466 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3467 return;
3468 }
3469 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3470 return;
3471 }
3472 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3473 return;
3474 }
3475 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3476 return;
3477 }
3478
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003480 return;
3481}
3482
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003483private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3484 inout integer num_paging_rcv_ids,
3485 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003486runs on test_CT {
3487 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003488 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003489 repeat;
3490 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003491 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003492 var octetstring without_plen :=
3493 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3494 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003495
3496 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3497
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003498 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3499 /* Ignore empty RR Paging Request (PCH filling) messages.
3500 * TODO: does it make sense to count them? */
3501 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003502 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3503 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003504 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003505 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3506 }
3507 } else if (match(rr, tr_PAGING_REQ2)) {
3508 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3509 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3510 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3511 }
3512 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3513 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3514 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003515 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003516 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3517 }
3518 } else if (match(rr, tr_PAGING_REQ3)) {
3519 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3520 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3521 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3522 }
3523 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3524 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3525 }
3526 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3527 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3528 }
3529 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3530 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3531 }
3532 }
3533 repeat;
3534 }
3535}
3536
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003537private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003538 boolean combined_ccch,
3539 integer bs_ag_blks_res,
3540 float load_factor,
3541 boolean exp_load_ind,
3542 boolean exp_overload,
3543 boolean use_tmsi
3544}
3545
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003546private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003547 integer num_paging_sent,
3548 integer num_paging_rcv_msgs,
3549 integer num_paging_rcv_ids,
3550 integer num_overload
3551}
3552
Harald Welte68e495b2018-02-25 00:05:57 +01003553/* Helper function for paging related testing */
3554private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003555 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003556 f_init_l1ctl();
3557 f_l1_tune(L1CTL);
3558
3559 var PagingTestState st := {
3560 num_paging_sent := 0,
3561 num_paging_rcv_msgs := 0,
3562 num_paging_rcv_ids := 0,
3563 num_overload := 0
3564 };
3565
3566 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3567 var float max_pch_imsi_per_sec;
3568 if (cfg.use_tmsi) {
3569 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3570 } else {
3571 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3572 }
3573 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3574 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003575 var float time_total := 20.0;
3576 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3577 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003578
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003579 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3580 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003581
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003582 timer T_itv := 0.0;
3583 T_itv.start;
3584 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003585 alt {
3586 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003587 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003588 st.num_overload := st.num_overload + 1;
3589 repeat;
3590 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003591 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003593 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003594 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003595 log("Rx LOAD_IND");
3596 /* FIXME: analyze/verify interval + contents */
3597 repeat;
3598 }
3599 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003600 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003601 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003602 [] T_itv.timeout {
3603 /* Send paging cmds based on elapsed time */
3604 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3605 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003606 var MobileIdentityV mi;
3607
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003608 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003609 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003610 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003611 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003612 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003613 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003614
3615 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003616 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 +02003617
3618 st.num_paging_sent := st.num_paging_sent + 1;
3619 }
3620 if (st.num_paging_sent < pkt_total) {
3621 /* Wait for interval to next PAGING COMMAND */
3622 var float time_now := T_total.read;
3623 var float next_sched := int2float(st.num_paging_sent)*interval;
3624 if (next_sched > time_now) {
3625 T_itv.start(next_sched - time_now);
3626 } else {
3627 T_itv.start(0.0);
3628 }
3629 } else {
3630 /* We are done, no need to keep counting */
3631 T_total.stop;
3632 }
3633 }
3634 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003635 }
3636 }
3637
3638 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3639 timer T_wait := 18.0;
3640 T_wait.start;
3641 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003642 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003643 [] L1CTL.receive { repeat; }
3644 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003645 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3646 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003647 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003649 }
Harald Welte68e495b2018-02-25 00:05:57 +01003650 }
3651
3652 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3653 " rcvd_ids=", st.num_paging_rcv_ids);
3654 return st;
3655}
3656
3657/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3658 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3659 * - that CCCH LOAD IND (PCH) are being generated
3660 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3661testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003662 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003663 var PagingTestCfg cfg := {
3664 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003665 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003666 load_factor := 0.8,
3667 exp_load_ind := true,
3668 exp_overload := false,
3669 use_tmsi := false
3670 };
3671 var PagingTestState st := f_TC_paging(cfg);
3672 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3674 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003675 } else {
3676 setverdict(pass);
3677 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003678 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003679}
3680
3681/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3682 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3683 * - that CCCH LOAD IND (PCH) are being generated
3684 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3685testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003686 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003687 var PagingTestCfg cfg := {
3688 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003689 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003690 load_factor := 0.8,
3691 exp_load_ind := true,
3692 exp_overload := false,
3693 use_tmsi := true
3694 };
3695 var PagingTestState st := f_TC_paging(cfg);
3696 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3698 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003699 } else {
3700 setverdict(pass);
3701 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003703}
3704
3705/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3706 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3707 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3708 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3709testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003710 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003711 var PagingTestCfg cfg := {
3712 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003713 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003714 load_factor := 2.0,
3715 exp_load_ind := true,
3716 exp_overload := true,
3717 use_tmsi := false
3718 };
3719 var PagingTestState st := f_TC_paging(cfg);
3720 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3721 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003722 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003723 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003724 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 +01003725 } else {
3726 setverdict(pass);
3727 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003729}
3730
3731/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3732 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3733 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3734 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3735testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003736 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003737 var PagingTestCfg cfg := {
3738 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003739 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003740 load_factor := 2.0,
3741 exp_load_ind := true,
3742 exp_overload := true,
3743 use_tmsi := true
3744 };
3745 var PagingTestState st := f_TC_paging(cfg);
3746 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3747 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003748 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003749 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003750 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 +01003751 } else {
3752 setverdict(pass);
3753 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003755}
3756
3757
Harald Welte93640c62018-02-25 16:59:33 +01003758/***********************************************************************
3759 * Immediate Assignment / AGCH
3760 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003761private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003762 len := 0,
3763 ma := ''B
3764}
Harald Welte93640c62018-02-25 16:59:33 +01003765
Harald Weltee8d750e2018-06-10 21:41:35 +02003766private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3767 return int2str(num_tx) & " sent, "
3768 & int2str(num_rx) & " received, "
3769 & int2str(num_del) & " deleted";
3770}
3771
3772private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3773 var L1ctlDlMessage l1_dl;
3774 timer T := 10.0;
3775 var integer num_tx := 0;
3776 var integer num_rx := 0;
3777 var integer num_del := 0;
3778 var charstring res_str;
3779 var float rx_ratio;
3780
Harald Welte10474062019-05-30 16:48:17 +02003781 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003782 f_init_l1ctl();
3783 f_l1_tune(L1CTL);
3784
3785 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07003786 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07003787 mp_trx_pars[0].arfcn,
3788 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02003789 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3790 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003791 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003792 num_tx := num_tx+1;
3793 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003794 }
3795 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003796 T.start;
3797 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003798 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003799 num_del := num_del+1;
3800 repeat;
3801 }
3802 [] RSL_CCHAN.receive {
3803 repeat;
3804 }
3805 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003806 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3807 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3808 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003809 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003810 } else {
3811 num_rx := num_rx+1;
3812 }
3813 repeat;
3814 }
3815 [] L1CTL.receive { repeat; }
3816 [] T.timeout { }
3817 }
3818 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3819 log("AGCH test: " & res_str);
3820 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003822 }
3823 rx_ratio := int2float(num_rx) / int2float(num_tx);
3824 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003825 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 +02003826 } else {
3827 setverdict(pass);
3828 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003830}
3831
Harald Weltee8d750e2018-06-10 21:41:35 +02003832/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3833testcase TC_imm_ass_1000_20ms() runs on test_CT {
3834 f_TC_imm_ass(1000, 0.02, 0.25);
3835}
3836
3837/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3838testcase TC_imm_ass_200_0ms() runs on test_CT {
3839 f_TC_imm_ass(200, 0.0, 0.05);
3840}
3841
3842/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3843testcase TC_imm_ass_200_76ms() runs on test_CT {
3844 f_TC_imm_ass(150, 0.076, 1.00);
3845}
3846
3847
3848
Harald Welte48494ca2018-02-25 16:59:50 +01003849/***********************************************************************
3850 * BCCH
3851 ***********************************************************************/
3852
3853/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003854private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003855 GsmFrameNumber frame_number,
3856 SystemInformation si
3857}
3858
3859/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003860private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003861
3862/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003863private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003864
3865/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003866private function f_si_vecslot_contains(SystemInformationVector arr,
3867 RrMessageType key,
3868 boolean bcch_ext := false)
3869return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003870 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3871 var integer fn_mod51 := arr[i].frame_number mod 51;
3872 if (not bcch_ext and fn_mod51 == 2 or
3873 bcch_ext and fn_mod51 == 6) {
3874 if (arr[i].si.header.message_type == key) {
3875 return true;
3876 }
3877 }
3878 }
3879 return false;
3880}
3881
3882/* 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 +07003883private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3884 integer tc, RrMessageType key,
3885 boolean ext_bcch := false)
3886{
Harald Welte48494ca2018-02-25 16:59:50 +01003887 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003888 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003889 }
3890}
3891
3892/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003893private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3894 RrMessageType key)
3895return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003896 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3897 if (f_si_vecslot_contains(arr[tc], key) or
3898 f_si_vecslot_contains(arr[tc], key, true)) {
3899 return true;
3900 }
3901 }
3902 return false;
3903}
3904
3905/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003906private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3907 RrMessageType key,
3908 boolean bcch_ext := false,
3909 integer n := 1, integer m := 4)
3910return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003911 var integer count := 0;
3912 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3914 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003915 }
3916 for (var integer i:= 0; i < m; i := i + 1) {
3917 var integer fn_mod51 := arr[i].frame_number mod 51;
3918 if (not bcch_ext and fn_mod51 == 2 or
3919 bcch_ext and fn_mod51 == 6) {
3920 if (arr[i].si.header.message_type == key) {
3921 count := count + 1;
3922 }
3923 }
3924 }
3925 if (count >= n) {
3926 return true;
3927 } else {
3928 return false;
3929 }
3930}
3931
3932/* 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 +07003933private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3934 integer tc, RrMessageType key,
3935 boolean ext_bcch := false,
3936 integer n, integer m)
3937{
Harald Welte48494ca2018-02-25 16:59:50 +01003938 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003940 }
3941}
3942
3943/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003944private function f_si_vecslot_contains_only(SystemInformationVector arr,
3945 RrMessageType key,
3946 boolean bcch_ext := false)
3947return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003948 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3949 var integer fn_mod51 := arr[i].frame_number mod 51;
3950 if (not bcch_ext and fn_mod51 == 2 or
3951 bcch_ext and fn_mod51 == 6) {
3952 if (arr[i].si.header.message_type != key) {
3953 return false;
3954 }
3955 }
3956 }
3957 return true;
3958}
3959
3960/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003961private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3962 integer tc, RrMessageType key,
3963 boolean ext_bcch := false)
3964{
Harald Welte48494ca2018-02-25 16:59:50 +01003965 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003967 }
3968}
3969
3970/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003971private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003972 boolean bcch_extended,
3973 boolean si1_present,
3974 boolean si2bis_present,
3975 boolean si2ter_present,
3976 boolean si2quater_present,
3977 boolean si7_present,
3978 boolean si8_present,
3979 boolean si9_present,
3980 boolean si13_present,
3981 boolean si13alt_present,
3982 boolean si15_present,
3983 boolean si16_present,
3984 boolean si17_present,
3985 boolean si2n_present,
3986 boolean si21_present,
3987 boolean si22_present
3988}
3989
3990/* 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 +07003991private function f_validate_si_scheduling(SystemInformationConfig cfg,
3992 SystemInformationVectorPerTc si_per_tc)
3993{
Harald Welte48494ca2018-02-25 16:59:50 +01003994 var integer i;
3995 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3996 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003998 }
3999 }
4000 if (cfg.si1_present) {
4001 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4002 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4003 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4004 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4005 /* make sure *ALL* contain SI1 */
4006 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4007 }
4008 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4009 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4010 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4011 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4012 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4013 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4014
4015 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4016 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4017 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4018 * consecutive occurrences of TC = 4. */
4019 if (cfg.si2bis_present and not cfg.si2ter_present) {
4020 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4021 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4022 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4023 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4024 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4025 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4026 }
4027
4028 if (cfg.si7_present or cfg.si8_present) {
4029 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4030 * if System Information type 4 does not contain all information needed for cell
4031 * selection and reselection. */
4032 if (not cfg.bcch_extended) {
4033 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4034 }
4035 if (cfg.si7_present) {
4036 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4037 }
4038 if (cfg.si8_present) {
4039 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4040 }
4041 }
4042
4043 if (cfg.si2quater_present) {
4044 /* iii) System information type 2 quater is sent if needed, as determined by the system
4045 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4046 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4047 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4048 * within any of 4 consecutive occurrences of TC = 5. */
4049 if (not (cfg.bcch_extended)) {
4050 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4051 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4052 } else {
4053 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4054 }
4055 } else {
4056 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4057 }
4058 }
4059 if (cfg.si9_present) {
4060 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4061 * in system information type 3 as defined in 3GPP TS 44.018. */
4062 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4063 }
4064 if (cfg.si13_present) {
4065 /* vii) System Information type 13 is only related to the GPRS service. System Information
4066 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4067 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4068 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4069 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4070 * within any of 4 consecutive occurrences of TC=4. */
4071 if (not cfg.bcch_extended) {
4072 log("not-bccch-extended");
4073 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4074 } else {
4075 log("bccch-extended");
4076 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4077 }
4078 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004079 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004080 }
4081 }
4082 if (cfg.si16_present or cfg.si17_present) {
4083 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4084 * should not be sent in a cell where network sharing is used (see rule xv). */
4085 if (cfg.si22_present) {
4086 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4087 }
4088 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004090 }
4091 if (not cfg.bcch_extended) {
4092 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4093 }
4094 if (cfg.si16_present) {
4095 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4096 }
4097 if (cfg.si17_present) {
4098 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4099 }
4100 }
4101
4102 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4103 * broadcast information. The frequency with which they are sent is determined by the
4104 * system operator. System Information type 9 identifies the scheduling of System
4105 * Information type 18 and 20 messages. */
4106
4107 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4108 * Information Type 19 is present, then its scheduling shall be indicated in System
4109 * Information Type 9. */
4110
4111 if (cfg.si15_present) {
4112 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4113 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4114 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4115 * 4 consecutive occurrences of TC = 1. */
4116 if (not cfg.bcch_extended) {
4117 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4118 } else {
4119 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4120 }
4121 }
4122 if (cfg.si13alt_present) {
4123 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4124 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4125 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4126 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4127 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4128 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4129 * of TC = 4. */
4130 if (cfg.si13_present) {
4131 testcase.stop("Error: Cannot have SI13alt and SI13");
4132 }
4133 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004134 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004135 }
4136 if (not cfg.bcch_extended) {
4137 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4138 } else {
4139 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4140 }
4141 }
4142 if (cfg.si2n_present) {
4143 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4144 * as determined by the system operator. In the case that the message is sent on the
4145 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4146 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4147 * consecutive occurrences of TC = 4. */
4148 if (not cfg.bcch_extended) {
4149 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4150 } else {
4151 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4152 }
4153 }
4154 if (cfg.si21_present) {
4155 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4156 * determined by the system operator. If Extended Access Barring is in use in the cell
4157 * then this message is sent at least once within any of 4 consecutive occurrences of
4158 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4159 * cell then this message shall only be sent on BCCH Ext. */
4160 if (not cfg.bcch_extended) {
4161 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4162 } else {
4163 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4164 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004165 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004166 }
4167 }
4168 }
4169 if (cfg.si22_present) {
4170 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4171 * should not be sent in a cell where SoLSA is used (see rule viii). System
4172 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4173 * =2 and TC=6. */
4174 if (cfg.si16_present or cfg.si17_present) {
4175 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4176 }
4177 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4178 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004180 }
4181 if (not cfg.bcch_extended) {
4182 testcase.stop("Error: SI22 requires BCCH Extd!");
4183 } else {
4184 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4185 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4186 }
4187 }
4188}
4189
4190/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004191private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4192return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004193 timer T := duration;
4194 var SystemInformationVectorPerTc si_per_tc;
4195 var L1ctlDlMessage l1_dl;
4196
4197 /* initialize all per-TC vectors empty */
4198 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4199 si_per_tc[i] := {};
4200 }
4201
4202 /* flush all previous L1 queued msgs */
4203 pt.clear;
4204
4205 T.start;
4206 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004207 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004208 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4209 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4210 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004211 repeat;
4212 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004213
Harald Welte48494ca2018-02-25 16:59:50 +01004214 var integer tc := f_gsm_compute_tc(sig.frame_number);
4215 log("SI received at TC=", tc, ": ", sig.si);
4216 /* append to the per-TC bucket */
4217 si_per_tc[tc] := si_per_tc[tc] & { sig };
4218 repeat;
4219 }
4220 [] pt.receive { repeat; }
4221 [] T.timeout { }
4222 }
4223
4224 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4225 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4226 }
4227 log("si_per_tc=", si_per_tc);
4228 return si_per_tc;
4229}
4230
4231/* helper function: Set given SI via RSL + validate scheduling.
4232 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004233private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004234 var SystemInformationVectorPerTc si_per_tc;
4235 f_init_l1ctl();
4236 f_l1_tune(L1CTL);
4237
4238 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004239 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004240 f_validate_si_scheduling(si_cfg, si_per_tc);
4241
4242 setverdict(pass);
4243}
4244
4245testcase TC_si_sched_default() runs on test_CT {
4246 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004247 /* 2+3+4 are mandatory and set in f_init() */
4248 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004250}
4251
4252testcase TC_si_sched_1() runs on test_CT {
4253 f_init();
4254 si_cfg.si1_present := true;
4255 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004256 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004258}
4259
4260testcase TC_si_sched_2bis() runs on test_CT {
4261 f_init();
4262 si_cfg.si2bis_present := true;
4263 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4264 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004265 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004266}
4267
4268testcase TC_si_sched_2ter() runs on test_CT {
4269 f_init();
4270 si_cfg.si2ter_present := true;
4271 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4272 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004273 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004274}
4275
4276testcase TC_si_sched_2ter_2bis() runs on test_CT {
4277 f_init();
4278 si_cfg.si2bis_present := true;
4279 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4280 si_cfg.si2ter_present := true;
4281 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4282 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004284}
4285
4286testcase TC_si_sched_2quater() runs on test_CT {
4287 f_init();
4288 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004289 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004290 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004291 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004292}
4293
4294testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004295 /* NOTE: PCUIF connection is not used in this test case, but
4296 * without it the IUT would not broadcast SI13 (see OS#3075). */
4297 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004298 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004299 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004300 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004301 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004302}
4303
4304testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004305 /* NOTE: PCUIF connection is not used in this test case, but
4306 * without it the IUT would not broadcast SI13 (see OS#3075). */
4307 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004308 si_cfg.si2bis_present := true;
4309 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4310 si_cfg.si2ter_present := true;
4311 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4312 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004313 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004314 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004315 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004316 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004318}
4319
4320
Harald Welte68e495b2018-02-25 00:05:57 +01004321testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004322 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004323 /* FIXME: enable / disable individual BCCH info */
4324 //ts_RSL_BCCH_INFO(si_type, info);
4325 /* expect no ERROR REPORT after either of them *
4326 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004327 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004328}
4329
Harald Welte93640c62018-02-25 16:59:33 +01004330/***********************************************************************
4331 * Low-Level Protocol Errors / ERROR REPORT
4332 ***********************************************************************/
4333
Harald Welte01d982c2018-02-25 01:31:40 +01004334private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4335 timer T := 5.0;
4336 T.start;
4337 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004338 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004339 setverdict(pass);
4340 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004341 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004342 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004343 }
4344 [] RSL_CCHAN.receive {
4345 repeat;
4346 }
4347 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004349 }
4350 }
4351}
4352
4353/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4354testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004355 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004356 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4357 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004358 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004359
4360 f_exp_err_rep(RSL_ERR_PROTO);
4361}
4362
4363/* Provoke a mandatory IE error and match on ERROR REPORT */
4364testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004365 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004366
4367 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4368 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004369 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004370
4371 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4372}
4373
4374/* Provoke an IE content error and match on ERROR REPORT */
4375testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004376 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004377 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4378 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004379 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004380
4381 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4382}
4383
Harald Welteee25aae2019-05-19 14:32:37 +02004384/* attempt to activate channel with wrong RSL Message Discriminator IE */
4385function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4386 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4387 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4388 RSL.send(rsl);
4389 f_rslem_unregister(0, g_chan_nr);
4390}
4391testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4392 var ConnHdlr vc_conn;
4393 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4394
Harald Welte10474062019-05-30 16:48:17 +02004395 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004396
4397 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4398 vc_conn.done;
4399 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4400
4401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4402}
4403
4404/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004405private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004406 var template (value) RSL_Message rsl_tx;
4407 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4408 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4409 RSL.send(rsl_tx);
4410 f_rslem_unregister(0, g_chan_nr);
4411}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004412private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004413 var template (value) RSL_Message rsl_tx;
4414 /* we first have to activate the dedicated channel */
4415 f_rsl_chan_act(g_pars.chan_mode);
4416 /* ... to then send an invalid RLL message */
4417 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4418 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4419 RSL.send(rsl_tx);
4420 f_rslem_unregister(0, g_chan_nr);
4421}
4422testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4423 var ConnHdlr vc_conn;
4424 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4425 var template (value) RSL_Message rsl_tx;
4426
Harald Welte10474062019-05-30 16:48:17 +02004427 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004428
4429 /* Common Channel with wrong message type */
4430 RSL_CCHAN.clear;
4431 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4432 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004433 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004434 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4435
4436 /* TRX Management */
4437 RSL_CCHAN.clear;
4438 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4439 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004440 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004441 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4442
4443 /* Dedicated Channel */
4444 RSL_CCHAN.clear;
4445 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4446 vc_conn.done;
4447 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4448
4449 /* RLL */
4450 RSL_CCHAN.clear;
4451 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4452 vc_conn.done;
4453 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4454}
4455
4456/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004457private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004458 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4459 f_rslem_unregister(0, g_chan_nr);
4460}
4461testcase TC_err_rep_wrong_sequence() runs on test_CT {
4462 var ConnHdlr vc_conn;
4463 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4464
Harald Welte10474062019-05-30 16:48:17 +02004465 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004466
4467 RSL_CCHAN.clear;
4468 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4469 vc_conn.done;
4470 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4471}
4472
Harald Welte93640c62018-02-25 16:59:33 +01004473/***********************************************************************
4474 * IPA CRCX/MDCX/DLCS media stream handling
4475 ***********************************************************************/
4476
Harald Weltea871a382018-02-25 02:03:14 +01004477/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004478private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004479 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4480 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004481}
4482testcase TC_ipa_dlcx_not_active() runs on test_CT {
4483 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004484 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004485 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4486 vc_conn.done;
4487}
Harald Welte68e495b2018-02-25 00:05:57 +01004488
Harald Weltea3f1df92018-02-25 12:49:55 +01004489/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004490private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004491 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4492 "IPA CRCX ACK");
4493 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4494 "IPA CRCX NACK");
4495}
4496testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4497 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004498 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004499 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4500 vc_conn.done;
4501}
4502
4503/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004504private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004505 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4506 "IPA CRCX ACK");
4507 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4508 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4509 var uint7_t rtp_pt2 := f_rnd_int(127);
4510 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4511 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4512 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4513 "IPA MDCX ACK");
4514 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4515 "IPA DLCX ACK");
4516}
4517testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4518 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004519 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004520 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4521 vc_conn.done;
4522}
4523
Harald Welte3ae11da2018-02-25 13:36:06 +01004524/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004525private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004526 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4527 "IPA CRCX ACK");
4528 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4529 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4530 var uint7_t rtp_pt2 := f_rnd_int(127);
4531 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4532 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4533 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4534 "IPA MDCX ACK");
4535 /* Second MDCX */
4536 remote_ip := f_rnd_int(c_UINT32_MAX);
4537 remote_port := f_rnd_int(c_UINT16_MAX);
4538 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4539 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4540 "IPA MDCX ACK");
4541 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4542 "IPA DLCX ACK");
4543}
4544testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4545 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004546 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004547 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4548 vc_conn.done;
4549}
4550
Harald Welte9912eb52018-02-25 13:30:15 +01004551/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004552private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004553 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4554 "IPA CRCX NACK");
4555}
4556testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4557 var ConnHdlrPars pars;
4558 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004559 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004560
4561 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4562 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4563 vc_conn.done;
4564
4565 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4566 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4567 vc_conn.done;
4568}
4569
Harald Weltea3f1df92018-02-25 12:49:55 +01004570
Harald Welte883340c2018-02-28 18:59:29 +01004571/***********************************************************************
4572 * PCU Socket related tests
4573 ***********************************************************************/
4574
Harald Welte07bd2d22019-05-25 11:03:30 +02004575/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004576friend 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 +01004577runs on test_CT {
4578 timer T := 3.0;
4579
4580 /* we don't expect any RTS.req before PDCH are active */
4581 T.start;
4582 alt {
4583 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004585 }
4586 [] PCU.receive { repeat; }
4587 [] T.timeout { }
4588 }
4589
4590 /* Send PDCH activate request for known PDCH timeslot */
4591 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4592
4593 /* we now expect RTS.req for this timeslot (only) */
4594 T.start;
4595 alt {
4596 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4597 setverdict(pass);
4598 }
4599 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4600 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004602 }
4603 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004604 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004605 }
4606 [] PCU.receive { repeat; }
4607 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004608 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004609 }
4610 [not exp_success] T.timeout {
4611 setverdict(pass);
4612 }
4613 }
4614}
4615
Harald Welte07bd2d22019-05-25 11:03:30 +02004616/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004617friend 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 +01004618runs on test_CT {
4619 timer T := 3.0;
4620
4621 /* Send PDCH activate request for known PDCH timeslot */
4622 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 +02004623 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4624 * when it will actually have been executed in the BTS */
4625 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004626 PCU.clear;
4627 /* we now expect no RTS.req for this timeslot */
4628 T.start;
4629 alt {
4630 [] 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 +02004631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004632 }
4633 [] PCU.receive { repeat; }
4634 [] T.timeout {
4635 setverdict(pass);
4636 }
4637 }
4638}
4639
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004640friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004641 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004642 map(self:PCU, system:PCU);
4643 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01004644 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4645}
4646
Harald Welte883340c2018-02-28 18:59:29 +01004647/* PDCH activation via PCU socket; check for presence of RTS.req */
4648testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004649 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004650
Harald Welte883340c2018-02-28 18:59:29 +01004651 f_TC_pcu_act_req(0, 0, 7, true);
4652}
4653
4654/* PDCH activation via PCU socket on non-PDCU timeslot */
4655testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004656 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004657
Harald Welte883340c2018-02-28 18:59:29 +01004658 f_TC_pcu_act_req(0, 0, 1, false);
4659}
4660
4661/* PDCH activation via PCU socket on wrong BTS */
4662testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004663 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004664
Harald Welte883340c2018-02-28 18:59:29 +01004665 f_TC_pcu_act_req(23, 0, 7, false);
4666}
4667
4668/* PDCH activation via PCU socket on wrong TRX */
4669testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004670 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004671
Harald Welte883340c2018-02-28 18:59:29 +01004672 f_TC_pcu_act_req(0, 23, 7, false);
4673}
4674
4675/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4676testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004677 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004678
Harald Welte883340c2018-02-28 18:59:29 +01004679 /* Activate PDCH */
4680 f_TC_pcu_act_req(0, 0, 7, true);
4681 f_sleep(1.0);
4682 /* and De-Activate again */
4683 f_TC_pcu_deact_req(0, 0, 7);
4684}
4685
4686/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4687testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004688 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004689
Harald Welte883340c2018-02-28 18:59:29 +01004690 f_TC_pcu_deact_req(0, 0, 1);
4691}
4692
4693/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01004694function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01004695 var PCUIF_send_data sd;
4696 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004697 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01004698
4699 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01004700 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01004701
Harald Welte883340c2018-02-28 18:59:29 +01004702 T.start;
4703 alt {
4704 [] 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 +01004705 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01004706 setverdict(pass);
4707 } else {
4708 repeat;
4709 }
4710 }
4711 [] PCU.receive { repeat; }
4712 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01004713 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01004714 }
4715 }
4716}
4717
Philipp Maier94c08482021-02-01 17:36:05 +01004718/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
4719testcase TC_pcu_ver_si1() runs on test_CT {
4720 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
4721 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
4722}
4723
4724/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
4725testcase TC_pcu_ver_si3() runs on test_CT {
4726 const octetstring si3 := '49012223242526272929AABBCC'O;
4727 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
4728}
4729
4730/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4731testcase TC_pcu_ver_si13() runs on test_CT {
4732 const octetstring si13 := '01010203040506070909'O;
4733 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
4734}
4735
Harald Welte883340c2018-02-28 18:59:29 +01004736private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4737
4738/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004739friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004740 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4741runs on test_CT
4742{
4743 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4744 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4745}
4746
4747/* 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 +02004748friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4749 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004750runs on test_CT
4751{
4752 var PCUIF_send_data sd;
4753
4754 timer T := 3.0;
4755 T.start;
4756 alt {
4757 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4758 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4759 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4760 sd.data.u.rts_req.fn, sapi, data);
4761 }
4762 [] PCU.receive { repeat; }
4763 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004764 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004765 }
4766 }
4767}
4768
4769/* Send DATA.req on invalid BTS */
4770testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004771 var TfiUsfArr tua := f_TfiUsfArrInit();
4772 var octetstring data := '0000'O & f_rnd_octstring(21);
4773
4774 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004775
Harald Welte883340c2018-02-28 18:59:29 +01004776 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004777 f_TfiUsfArrSet(tua, 7, 0);
4778 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4779 f_sleep(1.0);
4780
4781 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004782}
4783
4784/* Send DATA.req on invalid TRX */
4785testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004786 var TfiUsfArr tua := f_TfiUsfArrInit();
4787 var octetstring data := '0000'O & f_rnd_octstring(21);
4788
4789 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004790
Harald Welte883340c2018-02-28 18:59:29 +01004791 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004792 f_TfiUsfArrSet(tua, 7, 0);
4793 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4794 f_sleep(1.0);
4795
4796 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004797}
4798
4799/* Send DATA.req on invalid timeslot */
4800testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004801 var TfiUsfArr tua := f_TfiUsfArrInit();
4802 var octetstring data := '0000'O & f_rnd_octstring(21);
4803
4804 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004805
Harald Welte883340c2018-02-28 18:59:29 +01004806 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004807 f_TfiUsfArrSet(tua, 7, 0);
4808 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4809 f_sleep(1.0);
4810
4811 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004812}
4813
4814/* Send DATA.req on timeslot that hasn't been activated */
4815testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004816 var TfiUsfArr tua := f_TfiUsfArrInit();
4817 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004818
Harald Welte7162a612019-05-26 12:56:09 +02004819 f_virtphy_common();
4820
4821 f_TfiUsfArrSet(tua, 7, 0);
4822 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4823 f_sleep(1.0);
4824
4825 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004826}
4827
Harald Weltead033dc2019-05-25 17:28:16 +02004828private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004829 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4830 boolean wait_rts := true)
4831runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004832 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004833 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004834
4835 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004836 if (wait_rts) {
4837 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4838 } else {
4839 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4840 }
Harald Weltead033dc2019-05-25 17:28:16 +02004841
4842 T.start;
4843 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004844 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004845 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4846 setverdict(pass);
4847 }
Harald Welte7162a612019-05-26 12:56:09 +02004848 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4849 setverdict(fail, "Received unexpected ", rx_dl);
4850 }
Harald Weltead033dc2019-05-25 17:28:16 +02004851 [] L1CTL.receive {
4852 repeat;
4853 }
Harald Welte7162a612019-05-26 12:56:09 +02004854 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004855 setverdict(fail, "Timeout waiting for ", data);
4856 }
Harald Welte7162a612019-05-26 12:56:09 +02004857 [not expect_data] T.timeout {
4858 setverdict(pass);
4859 }
Harald Weltead033dc2019-05-25 17:28:16 +02004860 }
4861}
4862
4863private function f_disable_dynamic_ts() runs on test_CT
4864{
4865 f_init_vty_bsc();
4866 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4867 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4868 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4869 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004870 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02004871}
4872
4873private function f_virtphy_common() runs on test_CT {
4874 f_disable_dynamic_ts();
4875 f_init_l1ctl();
4876 f_l1_tune(L1CTL);
4877}
4878
4879testcase TC_pcu_data_req_pdtch() runs on test_CT {
4880 var TfiUsfArr tua := f_TfiUsfArrInit();
4881 var octetstring data := '0000'O & f_rnd_octstring(21);
4882
4883 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004884
Harald Welte883340c2018-02-28 18:59:29 +01004885 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004886 f_TfiUsfArrSet(tua, 7, 0);
4887 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4888 f_sleep(1.0);
4889
4890 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004891}
4892
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004893/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004894testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004895 var TfiUsfArr tua := f_TfiUsfArrInit();
4896 var octetstring data := '0000'O & f_rnd_octstring(21);
4897
4898 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004899
Harald Welte883340c2018-02-28 18:59:29 +01004900 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004901 f_TfiUsfArrSet(tua, 7, 0);
4902 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4903 f_sleep(1.0);
4904
4905 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004906}
4907
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004908private function f_TC_pcu_ptcch_ul(uint16_t ra)
4909runs on test_CT {
4910 var template PCUIF_Message pcu_rach_ind;
4911 var PCUIF_send_data sd;
4912 var GsmFrameNumber fn;
4913 timer T;
4914
4915 /* Send an Access Burst on PTCCH/U over the Um-interface */
4916 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4917 chan_nr := ts_RslChanNr_PDCH(7),
4918 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4919
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004920 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4921 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004922
4923 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4924 T.start(52.0 * 4.615 / 1000.0);
4925 alt {
4926 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4927 log("Rx an Access Burst on the PCU interface: ", sd.data);
4928 setverdict(pass);
4929 T.stop;
4930 }
4931 [] PCU.receive { repeat; }
4932 [] T.timeout {
4933 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4934 /* Keep going, that's not the end of the world */
4935 }
4936 }
4937}
4938
4939testcase TC_pcu_ptcch() runs on test_CT {
4940 var L1ctlDlMessage dl;
4941 var octetstring data;
4942 timer T;
4943
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004944 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004945 f_init_l1ctl();
4946 f_l1_tune(L1CTL);
4947
4948 /* Activate PDCH channel on TS7 */
4949 f_TC_pcu_act_req(0, 0, 7, true);
4950
4951 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004952 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004953 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004954 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004955 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004956
4957 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4958 for (var integer i := 0; i < 16; i := i + 1) {
4959 log("Sending an Access Burst towards the L1CTL interface");
4960 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4961 }
4962
4963 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4964 data := f_rnd_octstring(23);
4965
4966 /* Verify PTCCH/D: send a random data block, make sure it's received */
4967 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4968 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4969
4970 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4971 * let's give it more time in case if we miss the beginning. */
4972 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4973 alt {
4974 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4975 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4976 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4977 frame := data)) -> value dl {
4978 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4979 setverdict(pass);
4980 T.stop;
4981 }
4982 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4983 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4984 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4985 l2_data := data)) -> value dl {
4986 log("Rx PTCCH/D data block on L1CTL: ", dl);
4987 setverdict(pass);
4988 T.stop;
4989 }
4990 [] L1CTL.receive { repeat; }
4991 [] T.timeout {
4992 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4993 }
4994 }
4995}
4996
Harald Welte883340c2018-02-28 18:59:29 +01004997/* Send AGCH from PCU; check it appears on Um side */
4998testcase TC_pcu_data_req_agch() runs on test_CT {
4999 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005000 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005001 f_init_l1ctl();
5002 f_l1_tune(L1CTL);
5003
5004 f_TC_pcu_act_req(0, 0, 7, true);
5005 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5006
5007 T.start;
5008 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005009 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005010 setverdict(pass);
5011 }
5012 [] L1CTL.receive { repeat; }
5013 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005015 }
5016 }
5017}
5018
Harald Welte928622b2019-05-26 13:22:59 +02005019/* Send AGCH from PCU; check it appears on Um side */
5020testcase TC_pcu_data_req_pch() runs on test_CT {
5021 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005022 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005023 f_init_l1ctl();
5024 f_l1_tune(L1CTL);
5025
5026 f_TC_pcu_act_req(0, 0, 7, true);
5027 /* three characters prefix: last 3 digits of IMSI as ASCII */
5028 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5029
5030 T.start;
5031 alt {
5032 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5033 setverdict(pass);
5034 }
5035 [] L1CTL.receive { repeat; }
5036 [] T.timeout {
5037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5038 }
5039 }
5040}
5041
Harald Welte883340c2018-02-28 18:59:29 +01005042/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5043testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5044 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005045 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005046 f_init_l1ctl();
5047 f_l1_tune(L1CTL);
5048
5049 /* append 3 last imsi digits so BTS can compute pagng group */
5050 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5051
5052 timer T := 0.5;
5053 T.start;
5054 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005055 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005056 /* TODO: verify paging group */
5057 setverdict(pass);
5058 }
5059 [] L1CTL.receive { repeat; }
5060 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005061 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005062 }
5063 }
5064}
5065
5066/* Send RACH from Um side, expect it to show up on PCU socket */
5067testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005068 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005069 f_init_l1ctl();
5070 f_l1_tune(L1CTL);
5071
5072 var GsmFrameNumber fn_last := 0;
5073 for (var integer i := 0; i < 1000; i := i+1) {
5074 var OCT1 ra := f_rnd_ra_ps();
5075 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5076 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005078 }
5079 fn_last := fn;
5080
5081 timer T := 2.0;
5082 T.start;
5083 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005084 [] 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 +01005085 T.stop;
5086 }
5087 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005088 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005089 }
5090 [] PCU.receive { repeat; }
5091 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005093 }
5094 }
5095 }
5096 setverdict(pass);
5097}
5098
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005099/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5100 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5101testcase TC_pcu_ext_rach_content() runs on test_CT {
5102 var template PCUIF_Message pcu_rach_ind;
5103 var GsmFrameNumber fn_last := 0;
5104 var L1ctlRachSynchSeq synch_seq;
5105 var PCUIF_BurstType pcu_bt;
5106 var GsmFrameNumber fn;
5107 var BIT11 ra11;
5108
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005109 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005110 f_init_l1ctl();
5111 f_l1_tune(L1CTL);
5112
5113 for (var integer i := 0; i < 1000; i := i+1) {
5114 /* We need to test both TS1 & TS2 */
5115 if (i rem 2 == 0) {
5116 synch_seq := RACH_SYNCH_SEQ_TS1;
5117 pcu_bt := BURST_TYPE_1;
5118 } else {
5119 synch_seq := RACH_SYNCH_SEQ_TS2;
5120 pcu_bt := BURST_TYPE_2;
5121 }
5122
5123 ra11 := f_rnd_ra11_ps();
5124 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5125 if (fn == fn_last) {
5126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5127 "Two RACH in same FN?!?");
5128 }
5129 fn_last := fn;
5130
5131 /* Compose the expected message */
5132 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005133 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005134 ra := bit2int(ra11),
5135 is_11bit := 1,
5136 burst_type := pcu_bt,
5137 fn := fn);
5138
5139 timer T := 2.0;
5140 T.start;
5141 alt {
5142 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5143 T.stop;
5144 }
5145 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5146 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5147 }
5148 [] PCU.receive { repeat; }
5149 [] T.timeout {
5150 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5151 }
5152 }
5153 }
5154 setverdict(pass);
5155}
5156
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005157private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5158runs on test_CT {
5159 var template PCUIF_send_data sdt;
5160 var PCUIF_send_data sd;
5161 var int16_t lqual_cb;
5162 timer T := 1.0;
5163
5164 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5165 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5166
5167 /* Send a random PDTCH frame over Um */
5168 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5169 '0000'O & f_rnd_octstring(21)));
5170
5171 T.start;
5172 alt {
5173 /* If expected link quality is above the threshold */
5174 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5175 lqual_cb := sd.data.u.data_ind.lqual_cb;
5176 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5177
5178 /* Make sure the actual link quality matches the expected value */
5179 if (not match(lqual_cb, lqual_cb_exp)) {
5180 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5181 "expected value ", lqual_cb_exp));
5182 } else {
5183 setverdict(pass);
5184 }
5185 }
5186 /* If expected link quality is below the threshold */
5187 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5189 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5190 }
5191 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5192 [] PCU.receive { repeat; }
5193 [lqual_cb_exp < thresh] T.timeout {
5194 log("Rx nothing, as expected");
5195 setverdict(pass);
5196 }
5197 [lqual_cb_exp >= thresh] T.timeout {
5198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5199 "Timeout waiting for PCUIF_DATA.ind");
5200 }
5201 }
5202}
5203
5204/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5205testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005206 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005207 PCU.clear;
5208
5209 f_init_l1ctl();
5210 f_l1_tune(L1CTL);
5211
5212 /* Activate a PDCH channel on TS7 */
5213 f_TC_pcu_act_req(0, 0, 7, true);
5214
5215 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005216 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005217 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005218 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005219 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005220
5221 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5222 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5223 var TrxcMessage ret;
5224
5225 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5226 valueof(ts_TRXC_FAKE_CI(i)));
5227
5228 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5229 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5230 }
5231}
5232
Harald Welte883340c2018-02-28 18:59:29 +01005233/* Send PAGING via RSL, expect it to shw up on PCU socket */
5234testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005235 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005236
5237 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005238 var MobileIdentityLV mi_lv;
5239 var octetstring mi_lv_enc;
5240 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005241 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005242
Harald Welte883340c2018-02-28 18:59:29 +01005243 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005244 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005245 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005246 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005247 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005248
5249 /* Fancy encoding for PCUIF */
5250 mi_lv := valueof(ts_MI_LV(mi));
5251 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5252 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005253
5254 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005255 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005256 T.start;
5257 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005258 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005259 }
5260 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005262 }
5263 [] PCU.receive { repeat; }
5264 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005265 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005266 }
5267 }
5268 }
5269 setverdict(pass);
5270}
5271
Harald Welted66c9b82019-05-25 09:03:15 +02005272/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5273testcase TC_pcu_time_ind() runs on test_CT {
5274 var PCUIF_send_data pcu_sd;
5275 var integer num_time_ind := 0;
5276 var integer first_fn, last_fn;
5277 var float test_duration := 5.0;
5278 timer T;
5279
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005280 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005281 f_TC_pcu_act_req(0, 0, 7, true);
5282
5283 PCU.clear;
5284 T.start(test_duration);
5285 alt {
5286 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5287 num_time_ind := num_time_ind + 1;
5288 if (not isbound(first_fn)) {
5289 first_fn := pcu_sd.data.u.time_ind.fn;
5290 }
5291 last_fn := pcu_sd.data.u.time_ind.fn;
5292 repeat;
5293 }
5294 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5295 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5296 repeat;
5297 }
5298 [] PCU.receive {
5299 repeat;
5300 }
5301 [] T.timeout {}
5302 }
5303 var integer fn_expired := last_fn - first_fn;
5304 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5305
5306 /* verify the number of frames expired matches our expectation */
5307 const float c_GSM_FN_DURATION_MS := 4.61538;
5308 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005309 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005310 if (not match(fn_expired, t_fn_expected)) {
5311 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5312 }
5313
5314 /* There are three TIME.ind in every fn MOD 13 */
5315 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5316 /* Add some tolerance */
5317 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5318 if (not match(num_time_ind, t_time_ind_exp)) {
5319 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5320 }
5321
5322 setverdict(pass);
5323}
5324
Harald Welte4832c862019-05-25 14:57:18 +02005325/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5326testcase TC_pcu_rts_req() runs on test_CT {
5327 var PCUIF_send_data pcu_sd;
5328 var integer first_fn, last_fn;
5329 var integer num_rts_pdtch := 0;
5330 var integer num_rts_ptcch := 0;
5331 var float test_duration := 5.0;
5332 timer T;
5333
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005334 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005335 f_TC_pcu_act_req(0, 0, 7, true);
5336
5337 PCU.clear;
5338 T.start(test_duration);
5339 alt {
5340 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5341 -> value pcu_sd {
5342 num_rts_pdtch := num_rts_pdtch + 1;
5343 if (not isbound(first_fn)) {
5344 first_fn := pcu_sd.data.u.rts_req.fn;
5345 }
5346 last_fn := pcu_sd.data.u.rts_req.fn;
5347 repeat;
5348 }
5349 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5350 -> value pcu_sd {
5351 num_rts_ptcch := num_rts_ptcch + 1;
5352 if (not isbound(first_fn)) {
5353 first_fn := pcu_sd.data.u.rts_req.fn;
5354 }
5355 last_fn := pcu_sd.data.u.rts_req.fn;
5356 repeat;
5357 }
5358 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5359 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5360 repeat;
5361 }
5362 [] PCU.receive {
5363 repeat;
5364 }
5365 [] T.timeout {}
5366 }
5367 var integer fn_expired := last_fn - first_fn;
5368 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5369 ", num_rts_ptcch=", num_rts_ptcch);
5370
5371 /* verify the number of frames expired matches our expectation */
5372 const float c_GSM_FN_DURATION_MS := 4.61538;
5373 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005374 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005375 if (not match(fn_expired, t_fn_expected)) {
5376 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5377 }
5378
5379 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5380 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5381 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5382 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5383 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5384 t_ptcch_exp);
5385 }
5386
5387 /* We have 12 PDTCH blocks every 52-multiframe */
5388 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5389 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5390 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5391 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5392 t_pdtch_exp);
5393 }
5394
5395 setverdict(pass);
5396}
5397
Harald Welte07bd2d22019-05-25 11:03:30 +02005398/* test for generating Abis side OML ALERT from the PCU */
5399testcase TC_pcu_oml_alert() runs on test_CT {
5400 var PCUIF_send_data pcu_sd;
5401 var integer num_time_ind := 0;
5402 var integer first_fn, last_fn;
5403 var float test_duration := 5.0;
5404 timer T;
5405
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005406 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005407 f_TC_pcu_act_req(0, 0, 7, true);
5408
5409 /* re-connect CTRL port from BTS to BSC */
5410 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005411 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005412
5413 /* Send that OML Alert */
5414 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5415
5416 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5417 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5418 setverdict(pass);
5419}
5420
Harald Welteeaa9a862019-05-26 23:01:08 +02005421/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5422private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5423 var PCUIF_Message first_info;
5424 var integer pcu_conn_id := -1;
5425 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5426 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5427 var OCT4 tlli := '01020304'O;
5428 var OCT1 cause := '23'O;
5429 timer T := 5.0;
5430
5431 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5432
5433 f_l1_tune(L1CTL);
5434 RSL.clear;
5435
5436 f_est_dchan();
5437 L1CTL.clear;
5438
5439 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5440
5441 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5442 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5443 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5444
5445 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5446 T.start;
5447 alt {
5448 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5449 setverdict(pass);
5450 }
5451 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5452 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5453 }
5454 [] PCU.receive {
5455 repeat;
5456 }
5457 [] T.timeout {
5458 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5459 }
5460 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005461
5462 /* release the channel */
5463 f_rsl_chan_deact();
5464 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5465 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005466}
5467testcase TC_pcu_rr_suspend() runs on test_CT {
5468 var ConnHdlrPars pars;
5469 var ConnHdlr vc_conn;
5470
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005471 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005472
5473 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5474 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5475 vc_conn.done;
5476}
Harald Welte07bd2d22019-05-25 11:03:30 +02005477
Harald Weltea2e0e942019-05-27 18:12:53 +02005478/* Ensure that PCUIF socket can accept only a single connection */
5479testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005480 var boolean connected := false;
5481 var UD_connect_result cr;
5482 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005483 timer T := 5.0;
5484
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005485 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5486 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5487
Harald Weltea2e0e942019-05-27 18:12:53 +02005488 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005489 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005490
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005491 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005492 PCU.send(UD_connect:{mp_pcu_socket, -1});
5493 T.start;
5494 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005495 /* the IUT will first accept() the new connection, and close() it immediately */
5496 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5497 log("BTS has accept()ed connection");
5498 connected := true;
5499 cid := cr.id;
5500 repeat;
5501 }
5502 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5503 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005504 setverdict(pass);
5505 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005506 /* ignore other messages related to the first connection */
5507 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005508 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005509 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005510 }
5511 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005512
Harald Weltea2e0e942019-05-27 18:12:53 +02005513 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5514}
5515
Harald Weltec8effb72019-05-27 18:23:04 +02005516/* Ensure that PCUIF socket can disconnect + reconnect */
5517testcase TC_pcu_socket_reconnect() runs on test_CT {
5518 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005519 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005520
5521 f_sleep(1.0);
5522
5523 f_pcuif_close(PCU, g_pcu_conn_id);
5524 g_pcu_conn_id := -1;
5525
5526 f_sleep(1.0);
5527
5528 /* re-connect */
5529 PCU.clear;
5530 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5531 setverdict(pass);
5532
5533 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5534}
5535
Harald Weltebe030482019-05-27 22:29:35 +02005536/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005537private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5538runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005539 var L1ctlDlMessage l1_dl;
5540 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005541 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005542 timer T := 5.0;
5543 T.start;
5544 alt {
5545 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005546 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5547 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005548 repeat;
5549 }
5550 }
5551 [] pt.receive {
5552 repeat;
5553 }
5554 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005555 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5556 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005557 }
5558 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005559 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005560}
5561
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005562/* Check if GPRS Indicator is present in RR System Information of a given type */
5563private function f_si_has_gprs_indicator(RrMessageType si_type)
5564runs on test_CT return boolean {
5565 var SystemInformation si := f_get_si(L1CTL, si_type);
5566
5567 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005568 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005569 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005570 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005571 }
5572
5573 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5574 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005575}
5576
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005577/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5578private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5579runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005580 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02005581 f_init_l1ctl();
5582 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005583 f_sleep(2.0);
5584 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005585
5586 if (f_si_has_gprs_indicator(si_type)) {
5587 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005588 } else {
5589 setverdict(pass);
5590 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005591
Harald Weltebe030482019-05-27 22:29:35 +02005592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5593}
5594
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005595testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5596 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5597}
Harald Weltebe030482019-05-27 22:29:35 +02005598
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005599testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5600 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5601}
5602
5603/* Ensure that GPRS capability is advertised after PCU socket connect */
5604private function f_TC_pcu_socket_connect(RrMessageType si_type)
5605runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005606 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005607 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005608 f_init_l1ctl();
5609 f_l1_tune(L1CTL);
5610
5611 f_sleep(2.0);
5612 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005613
5614 if (not f_si_has_gprs_indicator(si_type)) {
5615 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005616 } else {
5617 setverdict(pass);
5618 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005619
Harald Weltebe030482019-05-27 22:29:35 +02005620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5621}
5622
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005623testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5624 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5625}
Harald Weltebe030482019-05-27 22:29:35 +02005626
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005627testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5628 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5629}
5630
5631/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5632private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5633runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005634 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005635 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005636 f_init_l1ctl();
5637 f_l1_tune(L1CTL);
5638
5639 f_pcuif_close(PCU, g_pcu_conn_id);
5640 g_pcu_conn_id := -1;
5641
5642 f_sleep(1.0);
5643
5644 /* re-connect */
5645 PCU.clear;
5646 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5647
5648 f_sleep(2.0);
5649 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005650
5651 if (f_si_has_gprs_indicator(si_type)) {
5652 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005653 } else {
5654 setverdict(pass);
5655 }
5656
5657 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5658}
5659
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005660testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5661 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5662}
5663
5664testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5665 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5666}
5667
Oliver Smithf5239c72019-08-28 10:01:25 +02005668/* 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) */
5669testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5670 var SystemInformation si3 := valueof(ts_SI3_default);
5671
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005672 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02005673
Harald Welte76220222020-10-11 20:32:44 +02005674 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5675 * information */
5676 timer T := 2.0;
5677 T.start;
5678 alt {
5679 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5680 [] T.timeout {}
5681 }
5682
Oliver Smithf5239c72019-08-28 10:01:25 +02005683 /* Verify cell_id */
5684 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5685 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5686 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005687 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5688 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5689 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005690 }
5691
5692 /* Verify LAC */
5693 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5694 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5695 if (lac_si3 != lac_pcu) {
5696 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5697 }
5698
5699 setverdict(pass);
5700}
Harald Welted66c9b82019-05-25 09:03:15 +02005701
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005702/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5703testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5704 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005705 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005706
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005707 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005708
5709 info_ind := g_pcu_last_info.u.info_ind;
5710
5711 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5712 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005713 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005714 /* Skip inactive timeslots */
5715 continue;
5716 }
5717
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005718 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005719 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005720 else
5721 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005722
5723 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005724 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005725 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005726 hsn := fhp.maio_hsn.hsn,
5727 maio := fhp.maio_hsn.maio,
5728 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005729 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005730 } else {
5731 tr_ts := tr_PCUIF_InfoTrxTsH0;
5732 }
5733
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005734 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005735 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5736 if (not match(ts, tr_ts)) {
5737 setverdict(fail, "Hopping parameters do not match: ",
5738 "received ", ts, " vs expected ", tr_ts);
5739 } else {
5740 setverdict(pass);
5741 }
5742 }
5743 }
5744}
5745
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005746/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02005747testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5748 f_init_vty_bsc();
5749 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5750 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5751
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005752 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02005753
5754 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005755 var template PCUIF_RemoteAddr tr_remote_addr := {
5756 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01005757 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005758 };
Alexander Couzens5283f552020-07-28 15:39:04 +02005759
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005760 if (not match(remote_addr, tr_remote_addr)) {
5761 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02005762 }
5763
5764 setverdict(pass);
5765}
5766
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005767/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02005768testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5769 f_init_vty_bsc();
5770 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5771
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005772 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02005773
5774 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005775 var template PCUIF_RemoteAddr tr_remote_addr := {
5776 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
5777 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
5778 };
Alexander Couzens5283f552020-07-28 15:39:04 +02005779
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005780 if (not match(remote_addr, tr_remote_addr)) {
5781 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02005782 }
5783
5784 setverdict(pass);
5785}
5786
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005787/* Verify coding of two NSVCs in the INFO.ind message */
5788testcase TC_pcu_socket_two_nsvc() runs on test_CT {
5789 f_init_vty_bsc();
5790
5791 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
5792 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
5793 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5794 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
5795
5796 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
5797 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
5798 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
5799 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
5800
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005801 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005802
5803 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
5804 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
5805 var template PCUIF_RemoteAddr tr_remote_addr := {
5806 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01005807 addr := {
5808 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
5809 f_inet6_addr("fd00::ca:ff:ee")
5810 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005811 };
5812
5813 if (not match(info_ind.nsvci, { 1234, 5678 }))
5814 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
5815 if (not match(remote_addr, tr_remote_addr))
5816 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
5817 if (not match(info_ind.local_port, { 1234, 5678 }))
5818 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
5819 if (not match(info_ind.remote_port, { 1234, 5678 }))
5820 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
5821
5822 setverdict(pass);
5823}
5824
Harald Welte3d04ae62018-04-04 20:29:05 +02005825/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005826 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005827 ***********************************************************************/
5828
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005829private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5830 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005831runs on ConnHdlr {
5832 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005833
5834 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005835 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005836 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5837 repeat;
5838 }
5839 }
5840}
5841
5842private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5843runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005844 /* Expect BTS to immediately acknowledge activation as PDCH */
5845 PCU.clear;
5846 f_rsl_chan_act(g_pars.chan_mode);
5847 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005848 timer T_wait := 2.0;
5849 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005850 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005851 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005852 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005853 [] T_wait.timeout {
5854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5855 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5856 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005857 }
5858 /* try to activate this PDCH from the PCU point of view */
5859 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5860 /* FIXME: is there a response? */
5861}
5862
5863private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5864runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005865 /* Send RSL CHAN REL (deactivate) */
5866 PCU.clear;
5867 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5868 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005869 timer T_wait := 2.0;
5870 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005871 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005872 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005873 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005874 [] T_wait.timeout {
5875 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5876 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5877 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005878 }
5879 /* Emulate PCU asking BTS to deactivate PDCH */
5880 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5881 alt {
5882 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5883 setverdict(pass);
5884 }
5885 [] RSL.receive { repeat; }
5886 }
5887}
5888
5889/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005890private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005891 var PCUIF_Message first_info;
5892 var integer ts_nr := g_chan_nr.tn;
5893 var integer trx_nr := 0;
5894 var integer bts_nr := 0;
5895 var integer pcu_conn_id := -1;
5896
5897 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5898
5899 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5900 f_sleep(3.0);
5901 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5902 setverdict(pass);
5903}
5904testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5905 var ConnHdlrPars pars;
5906 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005907 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005908
5909 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5910 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5911 vc_conn.done;
5912}
5913
5914/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005915private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005916 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005917 var integer pcu_conn_id := -1;
5918
5919 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5920
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005921 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5922 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5923 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005924 setverdict(pass);
5925}
5926testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5927 var ConnHdlrPars pars;
5928 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005929 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005930
5931 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5932 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5933 vc_conn.done;
5934}
5935
5936/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005937private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005938 var PCUIF_Message first_info;
5939 var integer ts_nr := g_chan_nr.tn;
5940 var integer trx_nr := 0;
5941 var integer bts_nr := 0;
5942 var integer pcu_conn_id := -1;
5943
5944 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5945
5946 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005947 /* Send a second Chan Activ and expect it to be NACKed */
5948 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5949 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005950 setverdict(pass);
5951}
5952testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5953 var ConnHdlrPars pars;
5954 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005955 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005956
5957 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5958 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5959 vc_conn.done;
5960}
5961
5962/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005963private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005964 var PCUIF_Message first_info;
5965 var integer ts_nr := g_chan_nr.tn;
5966 var integer trx_nr := 0;
5967 var integer bts_nr := 0;
5968 var integer pcu_conn_id := -1;
5969 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5970
5971 /* register for the TCH/F channel number */
5972 f_rslem_register(0, chan_nr);
5973
5974 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5975
5976 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5977 "RSL CHAN ACT");
5978 setverdict(pass);
5979}
5980testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5981 var ConnHdlrPars pars;
5982 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005983 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005984
5985 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5986 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5987 vc_conn.done;
5988}
5989
5990/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005991private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005992 var PCUIF_Message first_info;
5993 var integer ts_nr := g_chan_nr.tn;
5994 var integer trx_nr := 0;
5995 var integer bts_nr := 0;
5996 var integer pcu_conn_id := -1;
5997 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5998 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5999
6000 /* register for the TCH/H channel numbers */
6001 f_rslem_register(0, chan_nr[0]);
6002 f_rslem_register(0, chan_nr[1]);
6003
6004 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6005
6006 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6007 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6008 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6009 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6010 setverdict(pass);
6011}
6012testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6013 var ConnHdlrPars pars;
6014 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006015 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006016
6017 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6018 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6019 vc_conn.done;
6020}
6021
Harald Welte9bbbfb52018-04-05 09:33:19 +02006022/***********************************************************************
6023 * IPA Style Dynamic Timeslot Support
6024 ***********************************************************************/
6025
6026private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6027runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006028 /* Expect BTS to immediately acknowledge activation as PDCH */
6029 PCU.clear;
6030 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6031 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006032 timer T_wait := 2.0;
6033 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006034 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006035 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006036 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006037 [] T_wait.timeout {
6038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6039 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6040 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006041 }
6042 /* try to activate this PDCH from the PCU point of view */
6043 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6044 /* FIXME: is there a response? */
6045
6046 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6047}
6048
6049private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6050runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006051 /* Send RSL CHAN REL (deactivate) */
6052 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6053 PCU.clear;
6054 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006055 timer T_wait := 2.0;
6056 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006057 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006058 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006059 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006060 [] T_wait.timeout {
6061 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6062 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6063 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006064 }
6065 /* Emulate PCU asking BTS to deactivate PDCH */
6066 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6067 alt {
6068 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6069 setverdict(pass);
6070 }
6071 [] RSL.receive { repeat; }
6072 }
6073}
6074
6075/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006076private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006077 var PCUIF_Message first_info;
6078 var integer ts_nr := g_chan_nr.tn;
6079 var integer trx_nr := 0;
6080 var integer bts_nr := 0;
6081 var integer pcu_conn_id := -1;
6082
6083 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6084
6085 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6086 f_sleep(3.0);
6087 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6088
6089 setverdict(pass);
6090
6091}
6092testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6093 var ConnHdlrPars pars;
6094 var ConnHdlr vc_conn;
6095 f_init();
6096
6097 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6098 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6099 vc_conn.done;
6100}
6101
6102/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006103private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006104 var PCUIF_Message first_info;
6105 var integer ts_nr := g_chan_nr.tn;
6106 var integer trx_nr := 0;
6107 var integer bts_nr := 0;
6108 var integer pcu_conn_id := -1;
6109
6110 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6111
6112 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6113 "RSL CHAN ACT");
6114 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6115 "RF CHAN REL", true);
6116 setverdict(pass);
6117}
6118testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6119 var ConnHdlrPars pars;
6120 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006121 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006122
6123 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6124 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6125 vc_conn.done;
6126}
6127
6128/* 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 +07006129private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006130 var PCUIF_Message first_info;
6131 var integer ts_nr := g_chan_nr.tn;
6132 var integer trx_nr := 0;
6133 var integer bts_nr := 0;
6134 var integer pcu_conn_id := -1;
6135
6136 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6137
6138 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6139 "RSL CHAN ACT");
6140
6141 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6142 alt {
6143 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6144 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006145 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006146 }
6147 [] RSL.receive { repeat; }
6148 }
6149
6150 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6151 "RF CHAN REL", true);
6152 setverdict(pass);
6153}
6154testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6155 var ConnHdlrPars pars;
6156 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006157 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006158
6159 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6160 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6161 vc_conn.done;
6162}
6163
6164/* 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 +07006165private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006166 var PCUIF_Message first_info;
6167 var integer ts_nr := g_chan_nr.tn;
6168 var integer trx_nr := 0;
6169 var integer bts_nr := 0;
6170 var integer pcu_conn_id := -1;
6171
6172 /* register for the TCH/F channel number */
6173 f_rslem_register(0, g_chan_nr);
6174
6175 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6176
6177 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6178
6179 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6180 "RSL CHAN ACT");
6181
6182 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6183
6184 setverdict(pass);
6185}
6186testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6187 var ConnHdlrPars pars;
6188 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006189 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006190
6191 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6192 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6193 vc_conn.done;
6194}
6195
6196
Harald Welte0472ab42018-03-12 15:02:26 +01006197/***********************************************************************
6198 * LAPDm / RLL related
6199 ***********************************************************************/
6200
6201private function f_tx_lapdm(template (value) LapdmFrame l,
6202 template (value) RslLinkId link_id) runs on ConnHdlr {
6203 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006204 var template (value) SacchL1Header l1h;
6205
6206 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006207 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006208 /* Compose dummy L1 header */
6209 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6210 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 +02006211 } else {
6212 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006213 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 +01006214 }
Harald Welte0472ab42018-03-12 15:02:26 +01006215}
6216
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006217friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006218 uint3_t sapi,
6219 RslLinkId link_id,
6220 octetstring l3,
6221 boolean exp
6222}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006223friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006224friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6225 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006226 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006227 sapi := sapi,
6228 link_id := id,
6229 l3 := l3,
6230 exp := exp
6231}
6232
6233/* execute the same callback function with a set of different parameters (tcs) on a
6234 * variety of logical channels */
6235private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6236 var ConnHdlrPars pars;
6237 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006238 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006239
6240 /* test on each of the channels we have */
6241 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6242 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6243
6244 /* test each of the test cases on the current channel */
6245 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6246 pars.spec.rll := tcs[j];
6247 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6248 vc_conn := f_start_handler(fn, pars);
6249 vc_conn.done;
6250 }
6251 }
6252
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006254}
6255
6256/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6257private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6258 var RllTestCase tc := g_pars.spec.rll;
6259 timer T := 3.0;
6260
6261 f_l1_tune(L1CTL);
6262 RSL.clear;
6263
6264 /* activate the logical channel */
6265 f_est_dchan();
6266 L1CTL.clear;
6267
6268 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6269 T.start;
6270 alt {
6271 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6272 if (tc.exp) {
6273 setverdict(pass);
6274 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006275 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006276 }
6277 }
6278 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6279 if (tc.exp) {
6280 setverdict(pass);
6281 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006283 }
6284 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006285 /* We also expect to receive the measurements */
6286 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006287 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006288 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006289 }
6290 [not tc.exp] T.timeout {
6291 setverdict(pass);
6292 }
6293 }
6294
6295 f_rsl_chan_deact();
6296 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6297 f_rslem_unregister(0, g_chan_nr);
6298}
6299testcase TC_rll_est_ind() runs on test_CT {
6300 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006301 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006302 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006303 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006304 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006305 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006306 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6307 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006308 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006309 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006310 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006311 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006312 };
6313 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6314}
6315
6316/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6317private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6318 var RllTestCase tc := g_pars.spec.rll;
6319 var L1ctlDlMessage dl;
6320 timer T := 3.0;
6321
6322 f_l1_tune(L1CTL);
6323 RSL.clear;
6324
6325 /* activate the logical channel */
6326 f_est_dchan();
6327 L1CTL.clear;
6328
6329 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6330 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6331 T.start;
6332 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006333 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006334 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006335 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006336 }
6337 }
6338
6339 f_rsl_chan_deact();
6340 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6341 f_rslem_unregister(0, g_chan_nr);
6342}
6343testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6344 var RllTestCases tcs := {
6345 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006346 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006347 };
6348 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6349}
6350testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6351 var RllTestCases tcs := {
6352 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006353 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006354 }
6355 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6356}
6357
6358/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006359friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006360 var L1ctlDlMessage dl;
6361 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6362 var LapdmFrame lapdm;
6363 var octetstring l2 := dl.payload.data_ind.payload;
6364 if (dl.dl_info.link_id.c == SACCH) {
6365 /* remove L1 header */
6366 l2 := substr(l2, 2, lengthof(l2)-2);
6367 }
6368 if (ischosen(exp.ab)) {
6369 lapdm.ab := dec_LapdmFrameAB(l2);
6370 } else if (ischosen(exp.b4)) {
6371 lapdm.b4 := dec_LapdmFrameB4(l2);
6372 } else if (ischosen(exp.bbis)) {
6373 lapdm.bbis := dec_LapdmFrameBbis(l2);
6374 }
6375 log("Rx LAPDm ", lapdm);
6376 if (match(lapdm, exp)) {
6377 setverdict(pass);
6378 } else {
6379 repeat;
6380 }
6381 }
6382 [] L1CTL.receive { repeat; }
6383}
6384private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6385 timer T := t;
6386 T.start;
6387 alt {
6388 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006390 }
6391 [] as_l1_exp_lapdm(exp);
6392 }
6393}
6394
6395/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6396private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6397 /* send SABM from MS -> BTS */
6398 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6399 /* expect RLL EST IND on Abis */
6400 alt {
6401 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6402 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6403 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006404 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006405 }
6406 [] RSL.receive { repeat; }
6407 }
6408 /* expect UA from BTS -> MS */
6409 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6410}
6411
6412/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6413private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6414 var RllTestCase tc := g_pars.spec.rll;
6415
6416 f_l1_tune(L1CTL);
6417 RSL.clear;
6418
6419 /* activate the logical channel */
6420 f_est_dchan();
6421 L1CTL.clear;
6422
6423 /* first establish the link-layer */
6424 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6425
6426 /* then send the DISC */
6427 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6428 /* ... and expect the REL IND on the RSL side */
6429 alt {
6430 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6431 setverdict(pass);
6432 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006433 /* We also expect to receive the measurements */
6434 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006435 }
6436
6437 /* release the channel */
6438 f_rsl_chan_deact();
6439 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6440 f_rslem_unregister(0, g_chan_nr);
6441}
6442testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6443 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006444 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006445 };
6446 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6447}
6448
6449testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6450 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006451 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006452 };
6453 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6454}
6455testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6456 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006457 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006458 };
6459 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6460}
6461testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6462 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006463 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006464 };
6465 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6466}
6467
6468/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6469private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6470 var RllTestCase tc := g_pars.spec.rll;
6471 f_l1_tune(L1CTL);
6472 RSL.clear;
6473
6474 /* activate the logical channel */
6475 f_est_dchan();
6476 L1CTL.clear;
6477
6478 /* first establish the link-layer */
6479 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6480
6481 /* then send the REL REQ via RSL */
6482 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6483 /* ... and expect the DISC on the Um side */
6484 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006485 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006486 /* FIXME: send a UA in resposne to the DISC */
6487 }
6488 }
6489
6490 /* release the channel */
6491 f_rsl_chan_deact();
6492 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6493 f_rslem_unregister(0, g_chan_nr);
6494}
6495testcase TC_rll_rel_req() runs on test_CT {
6496 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006497 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
6498 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
6499 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
6500 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006501 };
6502 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6503}
6504
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006505/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006506testcase TC_rll_data_req() runs on test_CT {
6507}
6508
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006509/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006510testcase TC_rll_data_ind() runs on test_CT {
6511}
6512
6513/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6514private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6515 var RllTestCase tc := g_pars.spec.rll;
6516
6517 f_l1_tune(L1CTL);
6518 RSL.clear;
6519
6520 f_est_dchan();
6521 L1CTL.clear;
6522
6523 /* Send UNITDATA REQ on RSL side */
6524 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6525 /* Expect it to arrive on the other side */
6526 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006527 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006528 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006529 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006530 }
6531
6532 /* release the channel */
6533 f_rsl_chan_deact();
6534 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6535 f_rslem_unregister(0, g_chan_nr);
6536}
6537testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6538 var octetstring l3 := f_rnd_octstring(15);
6539 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006540 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6541 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006542 };
6543 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6544}
6545testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6546 var octetstring l3 := f_rnd_octstring(19);
6547 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006548 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6549 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006550 };
6551 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6552}
6553
6554/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6555private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6556 var RllTestCase tc := g_pars.spec.rll;
6557
6558 f_l1_tune(L1CTL);
6559 RSL.clear;
6560
6561 f_est_dchan();
6562 L1CTL.clear;
6563
6564 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006565 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006566 /* Expdct RLL UNITDATA IND on RSL side */
6567 alt {
6568 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6569 setverdict(pass);
6570 }
6571 [] RSL.receive { repeat; }
6572 }
6573
6574 /* release the channel */
6575 f_rsl_chan_deact();
6576 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6577 f_rslem_unregister(0, g_chan_nr);
6578}
6579testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006580 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006581 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006582 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6583 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006584 };
6585 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6586}
6587testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6588 var octetstring l3 := f_rnd_octstring(18);
6589 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006590 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6591 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006592 };
6593 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6594}
6595
Harald Weltee613f962018-04-18 22:38:16 +02006596/***********************************************************************
6597 * Encryption Related
6598 ***********************************************************************/
6599
6600/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006601private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006602 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6603 if (link_id.c == SACCH) {
6604 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6605 } else {
6606 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6607 }
6608}
6609
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006610/* Expect (or not expect) other kinds of messages */
6611private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6612 [exp_any] RSL.receive { repeat; }
6613 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006614 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006615 }
6616}
6617
Harald Weltee613f962018-04-18 22:38:16 +02006618/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006619private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006620 RslLinkId link_id,
6621 octetstring l3,
6622 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006623 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006624) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006625 timer T := 3.0;
6626 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6627 T.start;
6628 /* Expect RLL UNITDATA IND on RSL side */
6629 alt {
6630 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6631 setverdict(pass);
6632 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006633 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006634 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006635 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006637 }
Harald Weltee613f962018-04-18 22:38:16 +02006638 }
6639}
6640
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006641/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6642private function f_data_mo(
6643 RslLinkId link_id,
6644 boolean p, uint3_t nr, uint3_t ns,
6645 octetstring l3,
6646 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006647 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006648) runs on ConnHdlr {
6649 timer T := 3.0;
6650 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6651 T.start;
6652 /* Expect RLL DATA IND on RSL side */
6653 alt {
6654 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6655 setverdict(pass);
6656 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006657 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006658 [] as_rsl_any_ind(exp_any);
6659 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006660 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006661 }
6662 }
6663}
6664
Harald Weltee613f962018-04-18 22:38:16 +02006665/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006666private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006667 f_l1_tune(L1CTL);
6668 f_est_dchan(true);
6669
6670 /* now we actually need to transmit some data both ways to check if the encryption works */
6671 var L1ctlDlMessage dl;
6672
Stefan Sperling603d98e2018-07-25 16:47:28 +02006673 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006674 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6675
6676 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6677 f_unitdata_mt(link_id, l3);
6678
6679 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6680 f_unitdata_mo(link_id, l3);
6681
6682 /* release the channel */
6683 f_rsl_chan_deact();
6684 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6685 f_rslem_unregister(0, g_chan_nr);
6686}
6687testcase TC_chan_act_a51() runs on test_CT {
6688 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6689 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6690 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6691}
6692testcase TC_chan_act_a52() runs on test_CT {
6693 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6694 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6695 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6696}
6697testcase TC_chan_act_a53() runs on test_CT {
6698 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6699 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6700 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6701}
Eric Wildb9260392021-05-15 19:48:22 +02006702testcase TC_chan_act_a54() runs on test_CT {
6703 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6704 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
6705 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6706}
Harald Weltee613f962018-04-18 22:38:16 +02006707
Eric Wildf1827a72019-05-28 17:37:35 +02006708/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6709 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 +07006710private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006711 f_l1_tune(L1CTL);
6712 f_est_dchan(true);
6713
6714 /* now we actually need to transmit some data both ways to check if the encryption works */
6715 var L1ctlDlMessage dl;
6716
6717 var octetstring l3 := f_rnd_octstring(20);
6718 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6719
6720 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6721 f_unitdata_mt(link_id, l3);
6722
6723 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6724 f_unitdata_mo(link_id, l3);
6725
6726 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006727 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006728
6729 /* modify key to break proper encryption */
6730 g_pars.encr.key := f_rnd_octstring(8);
6731 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6732 rsl.ies := rsl.ies & { ei };
6733 RSL.send(rsl);
6734
6735 timer T0 := 1.0;
6736 T0.start;
6737 /* Expect RSL MODIFY ACK */
6738 alt {
6739 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6740 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6741 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6742 }
6743 [] T0.timeout {
6744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6745 }
6746 }
6747
6748 var octetstring l3msg := f_rnd_octstring(15);
6749 timer T1 := 3.0;
6750 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6751 due to broken encryption */
6752 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6753 T1.start;
6754 alt {
6755 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6756 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6757 }
6758 [] T1.timeout {
6759 setverdict(pass);
6760 }
6761 }
6762
6763 /* release the channel */
6764 f_rsl_chan_deact();
6765 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6766 f_rslem_unregister(0, g_chan_nr);
6767}
6768testcase TC_rsl_modify_encr() runs on test_CT {
6769 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6770 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6771 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6772}
Harald Weltee613f962018-04-18 22:38:16 +02006773
6774/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006775private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006776 /* L3 payload doesn't matter, as it is passed transparently */
6777 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6778 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6779 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6780
6781 f_l1_tune(L1CTL);
6782
6783 /* first establish a dedicated channel in the clear */
6784 f_est_dchan(false);
6785
6786 /* Establish ABM */
6787 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6788
6789 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6790 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6791 /* expect the L3 to arrive still unencrypted on the MS side */
6792 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6793
6794 /* configure L1 to apply ciphering */
6795 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6796 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6797
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006798 /* send first ciphered I-frame in response and expect it on RSL */
6799 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006800
6801 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6802 * and hence enable encryption also on the downlink */
6803
6804 /* expect bi-directional communication work in encrypted mode */
6805 f_unitdata_mo(link_id, f_rnd_octstring(15));
6806 f_unitdata_mt(link_id, f_rnd_octstring(15));
6807
6808 /* release the channel */
6809 f_rsl_chan_deact();
6810 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6811 f_rslem_unregister(0, g_chan_nr);
6812}
6813testcase TC_encr_cmd_a51() runs on test_CT {
6814 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6815 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6816 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6817}
6818testcase TC_encr_cmd_a52() runs on test_CT {
6819 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6820 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6821 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6822}
6823testcase TC_encr_cmd_a53() runs on test_CT {
6824 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6825 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6826 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6827}
Eric Wildb9260392021-05-15 19:48:22 +02006828testcase TC_encr_cmd_a54() runs on test_CT {
6829 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6830 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
6831 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6832}
Harald Weltee613f962018-04-18 22:38:16 +02006833
6834private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6835 var LapdmFrame lf;
6836 var octetstring reenc;
6837
6838 /* decode the LAPDm frame */
6839 if (ischosen(exp_match.ab)) {
6840 lf.ab := dec_LapdmFrameAB(enc);
6841 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006843 }
6844
6845 /* check if decoder result matches expectation */
6846 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006848 } else {
6849 log(name, ": matched");
6850 setverdict(pass);
6851 }
6852
6853 /* test if re-encoded frame equals original input */
6854 reenc := enc_LapdmFrame(lf);
6855 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006857 } else {
6858 setverdict(pass);
6859 }
6860}
6861
6862testcase TC_lapdm_selftest() runs on test_CT {
6863 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6864 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6865 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6866 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6867 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6868 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6869 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6870}
6871
Stefan Sperling4880be42018-08-07 18:12:59 +02006872/***********************************************************************
6873 * DTX Related (see GSM 05.08, section 8.3)
6874 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006875private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006876 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02006877 var GsmFrameNumber first_fn;
6878 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006879 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006880 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006881 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6882 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006883 const integer frame_dtx_tchf_mod := 104;
6884 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6885 * which operates in terms of blocks rather than frames. */
6886 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6887 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006888 timer T := 5.0;
6889
6890 f_l1_tune(L1CTL);
6891 RSL.clear;
6892 L1CTL.clear;
6893
6894 /* activate TCHF signalling channel */
6895 f_est_dchan(false);
6896
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006897 /* A template for matching dummy LAPDm func=UA frames */
6898 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
6899 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
6900 l2_data := f_pad_oct('030301'O, 23, '2B'O));
6901
Stefan Sperling4880be42018-08-07 18:12:59 +02006902 T.start;
6903 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006904 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02006905 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02006906
6907 if (is_first_frame) {
6908 is_first_frame := false;
6909 first_fn := dl.dl_info.frame_nr;
6910 }
6911
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006912 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006913 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006914 T.stop;
6915 f_rsl_chan_deact();
6916 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006917
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006918 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
6919 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006920
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006921 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006922 setverdict(fail, "Not enough fill frames received: ",
6923 nfill_frames, " out of ", expected_fill_frames);
6924 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006925 } else {
6926 setverdict(pass);
6927 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006928 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006929 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6930 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6931 * we should only see the subset of frames numbers which correspond to a block boundary.
6932 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6933 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6934 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006935 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006936 repeat;
6937 }
6938 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006939 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
6940 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6941 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006942 f_rsl_chan_deact();
6943 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02006944 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006945 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006946 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006947 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006948 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006949
6950 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006951 /* TCH/F: we expect 24 fill frames for every 104 frames. */
6952 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006953 /* TCH/H: we expect 2 fill frames for every 104 frames. */
6954 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
6955 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006956 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
6957 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006958 case else {
6959 /* This shall not happen, just to be sure */
6960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6961 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006962 }
6963
6964 f_rsl_chan_deact();
6965 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006966
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006967 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006968 setverdict(pass);
6969 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006970 setverdict(fail, "Not enough fill frames received: ",
6971 nfill_frames, " out of ", expected_fill_frames);
6972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006973 }
6974 } else {
6975 repeat;
6976 }
6977 }
6978 }
6979 [] L1CTL.receive { repeat; }
6980 [] T.timeout {
6981 f_rsl_chan_deact();
6982 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006984 }
6985 }
6986}
6987
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006988private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006989 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02006990 var ConnHdlr vc_conn;
6991 var ConnHdlrPars pars;
6992 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006993 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006994 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02006995 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006996 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02006997 if (dtxd) {
6998 if (i >= 4) { /* DTX is only allowed on TCH/F */
6999 break;
7000 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007001 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007002 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007003 vc_conn.done;
7004 }
7005}
7006
7007/* Verify that L2 fill frames are sent on TCH in signaling mode if
7008 * there is nothing to transmit while DTX is disabled on downlink. */
7009testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7010 f_tch_sign_l2_fill_frame(false);
7011}
7012
7013/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7014 * there is nothing to transmit while DTX is enabled on downlink. */
7015testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7016 f_tch_sign_l2_fill_frame(true);
7017}
Harald Welte0472ab42018-03-12 15:02:26 +01007018
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007019testcase TC_chopped_ipa_ping() runs on test_CT {
7020 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7021}
7022
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007023testcase TC_chopped_ipa_payload() runs on test_CT {
7024 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7025}
7026
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007027
7028/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7029 * Return value: Measurement Report to be sent (encoded octetstring). */
7030type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7031 runs on ConnHdlr return octetstring;
7032
7033private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7034runs on ConnHdlr {
7035 var L1ctlDlMessage l1_dl;
7036 var SacchL1Header l1h;
7037 var octetstring l2;
7038
7039 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7040 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7041 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7042 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7043
7044 /* Pass it to the user specified call-back function */
7045 l2 := cb.apply(l1h, num_blocks);
7046 /* Send a Measurement Report generated by the call-back */
7047 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7048 l1_dl.dl_info.link_id,
7049 l1h, l2));
7050
7051 /* Shall we keep going? */
7052 num_blocks := num_blocks - 1;
7053 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7054 if (num_blocks > 0) { repeat; }
7055 }
7056 [] L1CTL.receive { repeat; }
7057}
7058
7059private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7060runs on ConnHdlr return octetstring {
7061 /* Command the L1 to apply received parameters */
7062 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7063
7064 /* Dummy measurement report (the results are invalid) */
7065 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7066}
7067
7068private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7069runs on ConnHdlr return octetstring {
7070 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7071 setverdict(fail, "Unexpected MS Power level change: ",
7072 g_pars.l1_pars.ms_power_level, " -> ",
7073 l1h.ms_power_lvl);
7074 }
7075
7076 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7077}
7078
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007079private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7080runs on ConnHdlr return octetstring {
7081 /* UL RSSI oscillation driven by SACCH block number */
7082 if (num_blocks rem 2 == 0) {
7083 f_trxc_fake_rssi(-100);
7084 } else {
7085 f_trxc_fake_rssi(-50);
7086 }
7087
7088 /* Make sure that MS power level remains constant */
7089 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7090}
7091
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007092/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7093private function f_TC_ms_pwr_ctrl_constant(charstring id)
7094runs on ConnHdlr {
7095 var integer num_blocks := 8;
7096 timer T := int2float(num_blocks);
7097
7098 f_l1_tune(L1CTL);
7099 RSL.clear;
7100
7101 /* These IEs are needed for autonomous MS power control */
7102 var template (value) RSL_IE_List ies := {
7103 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7104 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7105 }),
7106 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7107 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7108 })
7109 };
7110
7111 /* Ensure that 'rx-current' equals 'rx-target' */
7112 f_trxc_fake_rssi(mp_uplink_power_target);
7113
7114 /* Establish a dedicated channel */
7115 f_est_dchan(more_ies := valueof(ies));
7116
7117 L1CTL.clear;
7118 T.start;
7119 alt {
7120 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7121 [] T.timeout {
7122 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7123 num_blocks, " were not handled");
7124 }
7125 }
7126}
7127testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7128 var ConnHdlr vc_conn;
7129 var ConnHdlrPars pars;
7130
7131 f_init();
7132
7133 /* Explicitly configure the Uplink power target (in dBm) */
7134 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7135
7136 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7137 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7138 log(testcasename(), ": starting on ", pars.chan_nr);
7139
7140 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7141 pars, trxc_comp := true);
7142 vc_conn.done;
7143 }
7144
7145 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7146 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7147}
7148
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007149/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7150private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7151runs on ConnHdlr {
7152 var integer num_blocks := 16;
7153 timer T := int2float(num_blocks);
7154
7155 f_l1_tune(L1CTL);
7156 RSL.clear;
7157
7158 /* These IEs are needed for autonomous MS power control */
7159 var template (value) RSL_IE_List ies := {
7160 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7161 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7162 }),
7163 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7164 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7165 })
7166 };
7167
7168 /* Ensure that 'rx-current' equals 'rx-target' */
7169 f_trxc_fake_rssi(mp_uplink_power_target);
7170
7171 /* Establish a dedicated channel */
7172 f_est_dchan(more_ies := valueof(ies));
7173
7174 L1CTL.clear;
7175 T.start;
7176 alt {
7177 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7178 [] T.timeout {
7179 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7180 num_blocks, " were not handled");
7181 }
7182 }
7183}
7184testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7185 var ConnHdlr vc_conn;
7186 var ConnHdlrPars pars;
7187
7188 f_init();
7189
7190 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7191 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7192 /* Explicitly configure the Uplink power range (target and delte) */
7193 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7194 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7195
7196 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7197 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7198 log(testcasename(), ": starting on ", pars.chan_nr);
7199
7200 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7201 pars, trxc_comp := true);
7202 vc_conn.done;
7203 }
7204
7205 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7207}
7208
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007209private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7210 var template L1ctlDlMessage tr_bad_frame;
7211 var L1ctlDlMessage l1_dl;
7212 timer T := 8.0;
7213
7214 f_l1_tune(L1CTL);
7215 RSL.clear;
7216
7217 f_est_dchan();
7218
7219 /* There may be a few errors right after the channel activation */
7220 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7221 L1CTL.clear;
7222
7223 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7224 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7225 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7226 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7227 tr_bad_frame.payload := ?;
7228
7229 T.start;
7230 alt {
7231 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7232 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7233 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7234 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7235 }
7236 [] as_l1_sacch();
7237 [] L1CTL.receive { repeat; }
7238 [] T.timeout {
7239 /* We're done, break the loop */
7240 setverdict(pass);
7241 }
7242 }
7243
7244 f_rsl_chan_deact();
7245 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7246}
7247testcase TC_speech_no_rtp_tchf() runs on test_CT {
7248 var ConnHdlr vc_conn;
7249 var ConnHdlrPars pars;
7250
7251 f_init();
7252
7253 /* TS1, TCH/F, V1 (FR codec) */
7254 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7255 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7256 vc_conn.done;
7257}
7258testcase TC_speech_no_rtp_tchh() runs on test_CT {
7259 var ConnHdlr vc_conn;
7260 var ConnHdlrPars pars;
7261
7262 f_init();
7263
7264 /* TS5, TCH/H, V1 (HR codec) */
7265 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7266 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7267 vc_conn.done;
7268}
7269
Harald Welte0472ab42018-03-12 15:02:26 +01007270/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7271/* protocol error as per 44.006 */
7272/* link layer failure (repetition of I-frame N200 times without ACK */
7273/* repetition of SABM or DISC N200 times without ACK */
7274/* receptiom of SABM in multi-frame established state */
7275
7276
Harald Welte68e495b2018-02-25 00:05:57 +01007277/* TODO Areas:
7278
7279* channel activation
7280** with BS_Power / MS_Power, bypassing power control loop
7281** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007282** with timing advance from initial activation on
7283* mode modify
7284** encryption
7285** multirate
7286* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007287** unsupported algorithm
7288* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007289* BS Power Control
7290* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007291* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007292* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007293** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007294* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007295** DATA_IND from BTS->PCU
7296** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007297
7298*/
Harald Welte70767382018-02-21 12:16:40 +01007299
7300control {
7301 execute( TC_chan_act_stress() );
7302 execute( TC_chan_act_react() );
7303 execute( TC_chan_deact_not_active() );
7304 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007305 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007306 execute( TC_sacch_filling() );
7307 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007308 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007309 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007310 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007311 execute( TC_sacch_chan_act_ho_async() );
7312 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007313 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007314 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007315 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007316 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007317 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007318 execute( TC_rach_load_idle_thresh0() );
7319 execute( TC_rach_load_idle_below_thresh() );
7320 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007321 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02007322 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007323 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02007324 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07007325 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01007326 execute( TC_meas_res_sign_tchf() );
7327 execute( TC_meas_res_sign_tchh() );
7328 execute( TC_meas_res_sign_sdcch4() );
7329 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007330 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007331 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007332 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007333 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007334 execute( TC_rsl_bs_pwr_static_ass() );
7335 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007336 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007337 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007338 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007339 execute( TC_rsl_ms_pwr_dyn_up() );
7340 execute( TC_rsl_ms_pwr_dyn_down() );
7341 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7342 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007343 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007344 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007345 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007346 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007347 execute( TC_paging_imsi_80percent() );
7348 execute( TC_paging_tmsi_80percent() );
7349 execute( TC_paging_imsi_200percent() );
7350 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007351 execute( TC_rsl_protocol_error() );
7352 execute( TC_rsl_mand_ie_error() );
7353 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007354 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007355 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007356 execute( TC_si_sched_2bis() );
7357 execute( TC_si_sched_2ter() );
7358 execute( TC_si_sched_2ter_2bis() );
7359 execute( TC_si_sched_2quater() );
7360 execute( TC_si_sched_13() );
7361 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007362 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007363 execute( TC_ipa_crcx_twice_not_active() );
7364 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007365 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007366 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007367
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007368 if (mp_pcu_socket != "") {
7369 execute( TC_pcu_act_req() );
7370 execute( TC_pcu_act_req_wrong_ts() );
7371 execute( TC_pcu_act_req_wrong_bts() );
7372 execute( TC_pcu_act_req_wrong_trx() );
7373 execute( TC_pcu_deact_req() );
7374 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01007375 execute( TC_pcu_ver_si1() );
7376 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007377 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007378 if (mp_l1_supports_gprs) {
7379 execute( TC_pcu_data_req_pdtch() );
7380 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007381 execute( TC_pcu_data_req_wrong_bts() );
7382 execute( TC_pcu_data_req_wrong_trx() );
7383 execute( TC_pcu_data_req_wrong_ts() );
7384 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007385 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007386 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007387 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007388 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007389 execute( TC_pcu_data_req_imm_ass_pch() );
7390 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007391 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007392 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007393 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007394 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007395 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007396 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007397 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007398 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007399 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007400 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007401 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007402 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007403 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007404 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007405 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007406 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007407 execute( TC_dyn_osmo_pdch_act_deact() );
7408 execute( TC_dyn_osmo_pdch_double_act() );
7409 execute( TC_dyn_ipa_pdch_act_deact() );
7410 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01007411 execute( TC_pcu_info_ind_fh_params() );
7412 execute( TC_pcu_socket_nsvc_ipv4() );
7413 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01007414 execute( TC_pcu_socket_two_nsvc() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007415 } else {
7416 log("PCU socket path not available, skipping PCU tests");
7417 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007418
Harald Welte3d04ae62018-04-04 20:29:05 +02007419 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007420 execute( TC_dyn_osmo_pdch_tchf_act() );
7421 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007422 execute( TC_dyn_ipa_pdch_tchf_act() );
7423 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007424
7425 execute( TC_rll_est_ind() );
7426 execute( TC_rll_est_req_DCCH_3() );
7427 execute( TC_rll_est_req_ACCH_3() );
7428 execute( TC_rll_rel_ind_DCCH_0() );
7429 execute( TC_rll_rel_ind_DCCH_3() );
7430 execute( TC_rll_rel_ind_ACCH_0() );
7431 execute( TC_rll_rel_ind_ACCH_3() );
7432 execute( TC_rll_rel_req() );
7433 execute( TC_rll_unit_data_req_DCCH() );
7434 execute( TC_rll_unit_data_req_ACCH() );
7435 execute( TC_rll_unit_data_ind_DCCH() );
7436 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007437
7438 execute( TC_chan_act_a51() );
7439 execute( TC_chan_act_a52() );
7440 execute( TC_chan_act_a53() );
7441 execute( TC_encr_cmd_a51() );
7442 execute( TC_encr_cmd_a52() );
7443 execute( TC_encr_cmd_a53() );
7444
Harald Welteee25aae2019-05-19 14:32:37 +02007445 execute( TC_err_rep_wrong_mdisc() );
7446 execute( TC_err_rep_wrong_msg_type() );
7447 execute( TC_err_rep_wrong_sequence() );
7448
Harald Weltee613f962018-04-18 22:38:16 +02007449 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007450
7451 execute( TC_tch_sign_l2_fill_frame() );
7452 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007453
7454 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007455 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007456
7457 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007458 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007459
7460 execute( TC_speech_no_rtp_tchf() );
7461 execute( TC_speech_no_rtp_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007462}
7463
7464
7465}