blob: c9553a3524073a5feb5c7e8e4f75644849bafa13 [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;
Vadim Yanitskiy73878132021-05-05 02:22:45 +020069friend module BTS_Tests_VAMOS;
Harald Weltead033dc2019-05-25 17:28:16 +020070friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020071friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010072friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030073
Harald Welte70767382018-02-21 12:16:40 +010074/* The tests assume a BTS with the following timeslot configuration:
75 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020076 * TS1 : TCH/F
77 * TS2 : TCH/F
78 * TS3 : TCH/F_PDCH (IPA Style)
79 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010080 * TS5 : TCH/H
81 * TS6 : SDCCH/8
82 * TS7 : PDCH
83 */
84
85modulepar {
86 charstring mp_rsl_ip := "127.0.0.2";
87 integer mp_rsl_port := 3003;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070088 charstring mp_bts_trxc_ip := "127.0.0.1";
89 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010090 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020091 charstring mp_ctrl_ip := "127.0.0.1";
92 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020093 charstring mp_bsc_ctrl_ip := "127.0.0.1";
94 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020095 integer mp_tolerance_rxqual := 1;
96 integer mp_tolerance_rxlev := 3;
97 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020098 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020099 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200100 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200101 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
102 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 +0200103 integer mp_ms_actual_ta_exp := 0;
104 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700105 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700106 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100107 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200108 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200109 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200110 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
111 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700112 /* how many transceivers do we expect to connect */
113 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700114 /* frequency hopping status */
115 boolean mp_freq_hop_enabled := false;
116 /* frequency hopping parameters */
117 FreqHopConfig mp_fh_config;
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700118 /* configuration for each individual transceiver */
119 TrxPars mp_trx_pars; /* see BTS_Tests.default */
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700120 /* default Training Sequence Code */
121 GsmTsc mp_tsc_def := 7;
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +0200122 /* Default interference boundaries in osmo-bsc (in dBm):
123 * 0(-85) X1(-91) X2(-97) X3(-103) X4(-109) X5(-115)
124 * Default interference level reported by fake_trx.py:
125 * 0: -109 >= -85 dBm (no)
126 * X1: -109 >= -91 dBm (no)
127 * X2: -109 >= -97 dBm (no)
128 * X3: -109 >= -103 dBm (no)
129 * X4: -109 >= -109 dBm (yes)
130 * X5: -109 >= -115 dBm (no)
131 * So all channels should be in band 4. */
132 uint3_t mp_interf_band := 4;
Harald Welte70767382018-02-21 12:16:40 +0100133}
134
Harald Welte629cc6b2018-03-11 17:19:05 +0100135type record of RslChannelNr ChannelNrs;
136
Harald Welte70767382018-02-21 12:16:40 +0100137type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100138 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100139 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100140 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100141 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100142 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100143 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100144
145 /* L1CTL port (for classic tests) */
146 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100147
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700148 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700149 port TRXC_CODEC_PT BTS_TRXC;
150 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100151
Harald Weltef50e3ae2018-09-10 10:27:56 +0200152 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100153 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200154 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100155
Harald Welte883340c2018-02-28 18:59:29 +0100156 /* PCU Interface of BTS */
157 port PCUIF_CODEC_PT PCU;
158 var integer g_pcu_conn_id;
159 /* Last PCU INFO IND we received */
160 var PCUIF_Message g_pcu_last_info;
161
Harald Welte48494ca2018-02-25 16:59:50 +0100162 /* SI configuration */
163 var SystemInformationConfig si_cfg := {
164 bcch_extended := false,
165 si1_present := false,
166 si2bis_present := false,
167 si2ter_present := false,
168 si2quater_present := false,
169 si7_present := false,
170 si8_present := false,
171 si9_present := false,
172 si13_present := false,
173 si13alt_present := false,
174 si15_present := false,
175 si16_present := false,
176 si17_present := false,
177 si2n_present := false,
178 si21_present := false,
179 si22_present := false
180 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100181
182 /* all logical channels available on the BTS */
183 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100184 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100185}
186
187/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200188type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100189 port L1CTL_PT L1CTL;
190
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700191 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700192 port TRXC_CODEC_PT BTS_TRXC;
193 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100194
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200195 /* port to be initialized optionally to access BSC VTY */
196 port TELNETasp_PT BSCVTY;
197
Harald Welte70767382018-02-21 12:16:40 +0100198 timer g_Tguard;
199 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
200
201 var ConnHdlrPars g_pars;
202 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100203 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200204
205 /* PCU Interface of BTS */
206 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100207}
208
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700209private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700210 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200211 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700212 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200213 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700214 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200215 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700216 timer T;
217
Harald Welte70767382018-02-21 12:16:40 +0100218 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
219 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
220
221 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
222 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
223 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
224
225 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
226 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700227
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700228 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700229 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700230 T.start(mp_ipa_up_timeout);
231 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700232 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700233 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
234 /* Make sure that all transceivers use unique stream ID */
235 if (trx_mask[enum2int(ev.sid)] == '1'B) {
236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
237 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
238 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700239
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700240 trx_mask[enum2int(ev.sid)] := '1'B;
241 trx_count := trx_count + 1;
242
243 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200244 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700245 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200246 /* This message (RF RESource INDication) is sent by the IUT itself */
247 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
248 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
250 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
251 }
252 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
254 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
255 }
256
257 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
258 rfind_count := rfind_count + 1;
259 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
260 if (rfind_count < mp_transceiver_num) { repeat; }
261 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700262 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
263 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
264 [] T.timeout {
265 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
266 "Timeout waiting for RSL bring up");
267 }
268 }
Harald Welte70767382018-02-21 12:16:40 +0100269}
270
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700271friend type record length(1 .. 256) of TrxParsItem TrxPars;
272friend type record TrxParsItem {
273 GsmArfcn arfcn,
274 TrxTsPars ts
275};
276
277friend type record length(8) of TrxTsParsItem TrxTsPars;
278friend type record TrxTsParsItem {
279 PchanConfig config
280};
281
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700282friend type record FreqHopPars {
283 /* Whether frequency hopping is in use */
284 boolean enabled,
285 /* Mobile Allocation Index Offset / Hopping Sequence Number */
286 MaioHsn maio_hsn,
287 /* MA bitmap to be indicated in RR Immediate Assignment */
288 MobileAllocationLV ma_map,
289 /* The actual Mobile Allocation (ARFCN list) to be used */
290 L1ctlMA ma
291};
292
Harald Welte70767382018-02-21 12:16:40 +0100293type record ConnHdlrPars {
294 RslChannelNr chan_nr,
295 RSL_IE_ChannelMode chan_mode,
296 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100297 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200298 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200299 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700300 BtsBand bts0_band optional,
301
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700302 /* Training Sequence Code */
303 GsmTsc tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700304 /* Frequency hopping parameters */
305 FreqHopPars fhp
306};
Harald Welte0472ab42018-03-12 15:02:26 +0100307
308/* Test-specific parameters */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +0200309friend type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100310 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100311}
312
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700313private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100314 max_retrans := RACH_MAX_RETRANS_7,
315 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100316 cell_barr_access := false,
317 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100318 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100319};
320
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700321private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100322 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200323 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100324 acs := '0'B,
325 neci := true,
326 rxlev_access_min := 0
327}
328
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700329private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100330 mcc_mnc := '262F42'H,
331 lac := 42
332}
333
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700334private template (value) GPRSIndicator ts_GPRSIndicator_def := {
335 ra_colour := 0,
336 si13_pos := '0'B
337}
338
339private template (value) SI3RestOctets ts_SI3RestOctets_def
340modifies ts_SI3RestOctets := {
341 gprs_ind := {
342 presence := CSN1_H,
343 ind := ts_GPRSIndicator_def
344 }
345}
346
347private template (value) SI4RestOctets ts_SI4RestOctets_def
348modifies ts_SI4RestOctets := {
349 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700350 presence := CSN1_H,
351 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700352 }
353}
354
Harald Welte7484fc42018-02-24 14:09:45 +0100355/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700356private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100357 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100358 payload := {
359 si3 := {
360 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100361 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100362 ctrl_chan_desc := {
363 msc_r99 := true,
364 att := true,
365 bs_ag_blks_res := 1,
366 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100367 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100368 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
369 spare := '00'B,
370 bs_pa_mfrms := 0, /* 2 multiframes */
371 t3212 := 1 /* 6 minutes */
372 },
Harald Welte82ccef72018-02-25 16:17:33 +0100373 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100374 dn_ind := false,
375 pwrc := false,
376 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100377 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100378 },
Harald Weltef10153f2018-02-25 16:34:05 +0100379 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100380 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200381 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100382 }
383 }
384}
Harald Welte70767382018-02-21 12:16:40 +0100385
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700386private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100387 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100388 payload := {
389 si2 := {
390 bcch_freq_list := '00000000000000000000000000000000'O,
391 ncc_permitted := '11111111'B,
392 rach_control := ts_RachCtrl_default
393 }
394 }
395}
396
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700397private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100398 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100399 payload := {
400 si4 := {
401 lai := ts_LAI_default,
402 cell_sel_par := ts_CellSelPar_default,
403 rach_control := ts_RachCtrl_default,
404 cbch_chan_desc := omit,
405 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200406 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100407 }
408 }
409}
410
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700411private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100412runs on test_CT {
413 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700414 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100415}
416
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700417private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100418runs on test_CT {
419 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
420 log("Setting ", rsl_si_type, ": ", si_dec);
421 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
422}
423
Harald Welte505cf9b2018-09-15 17:47:23 +0300424friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100425 map(self:BTSVTY, system:BTSVTY);
426 f_vty_set_prompts(BTSVTY);
427 f_vty_transceive(BTSVTY, "enable");
428}
429
Harald Welte505cf9b2018-09-15 17:47:23 +0300430friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200431 map(self:BSCVTY, system:BSCVTY);
432 f_vty_set_prompts(BSCVTY, "OsmoBSC");
433 f_vty_transceive(BSCVTY, "enable");
434}
435
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200436friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
437 map(self:BSCVTY, system:BSCVTY);
438 f_vty_set_prompts(BSCVTY, "OsmoBSC");
439 f_vty_transceive(BSCVTY, "enable");
440}
441
Harald Welte883340c2018-02-28 18:59:29 +0100442/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200443private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
444 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100445 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200446 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
447 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100448 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200449 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100451 }
452}
453
Harald Weltef26de0b2018-04-04 20:28:05 +0200454private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
455 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100456 timer T := 2.0;
457 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100458 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200459 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100460 return;
461 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200462 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100463
464 T.start;
465 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200466 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100467 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100469 }
470 }
471}
472
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700473private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
474 out integer trxc_conn_id) {
475 var Result res;
476
477 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
478 "", -1, -1, { udp := {} }, {});
479 if (not ispresent(res.connId)) {
480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
481 "Could not connect to the control (TRXC) interface " &
482 "of FakeTRX, check your configuration");
483 }
484 trxc_conn_id := res.connId;
485}
486
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100487/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700488friend function f_init(uint8_t trx_nr := 0)
489runs on test_CT
490{
491 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200492 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100493
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700494 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
495 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700496 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200497 g_AllChanTypes := {
498 /* TS 1..4: TCH/F */
499 valueof(ts_RslChanNr_Bm(1)),
500 /* TS 5: TCH/H */
501 valueof(ts_RslChanNr_Lm(5,1)),
502 /* TS 0: SDCCH/4 */
503 valueof(ts_RslChanNr_SDCCH4(0,2)),
504 /* TS 6: SDCCH/8 */
505 valueof(ts_RslChanNr_SDCCH8(6,4))
506 };
507 } else {
508 g_AllChanTypes := {
509 /* TS 1..4: TCH/F */
510 valueof(ts_RslChanNr_Bm(1)),
511 /* TS 0: SDCCH/4 */
512 valueof(ts_RslChanNr_SDCCH4(0,2)),
513 /* TS 6: SDCCH/8 */
514 valueof(ts_RslChanNr_SDCCH8(6,4))
515 };
516 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700517
518 g_AllChannels := { };
519
520 /* Generate list of all logical channels from module parameters */
521 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
522 select (trx_pars.ts[tn].config) {
523 case (GSM_PCHAN_CCCH_SDCCH4) {
524 g_AllChannels := g_AllChannels &
525 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
526 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
527 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
528 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
529 }
530 case (GSM_PCHAN_SDCCH8) {
531 g_AllChannels := g_AllChannels &
532 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
533 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
534 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
535 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
536 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
537 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
538 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
539 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
540 }
541 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
542 g_AllChannels := g_AllChannels &
543 { valueof(ts_RslChanNr_Lm(tn, 0)),
544 valueof(ts_RslChanNr_Lm(tn, 1)),
545 valueof(ts_RslChanNr_Bm(tn)) };
546 }
547 case (GSM_PCHAN_TCHH) {
548 g_AllChannels := g_AllChannels &
549 { valueof(ts_RslChanNr_Lm(tn, 0)),
550 valueof(ts_RslChanNr_Lm(tn, 1)) };
551 }
552 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
553 g_AllChannels := g_AllChannels &
554 { valueof(ts_RslChanNr_Bm(tn)) };
555 }
556 }
557 }
558
Harald Welte70767382018-02-21 12:16:40 +0100559 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100560 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100561 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100562 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100563
564 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100565 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
566 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
567 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
568 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100569
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700570 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100571 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700572
573 /* Init TRXC interface to FakeTRX */
574 map(self:BTS_TRXC, system:BTS_TRXC);
575 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
576
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700577 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700578 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 +0700579 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700580 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
581 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100582 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200583
584 /* Wait some extra time to make sure the BTS emits a stable carrier.
585 * (this is only relevant when running the tests with a physical BTS.) */
586 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100587}
588
Harald Welte68e495b2018-02-25 00:05:57 +0100589/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700590friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100591 map(self:L1CTL, system:L1CTL);
592 f_connect_reset(L1CTL);
593}
594
Vadim Yanitskiy73878132021-05-05 02:22:45 +0200595friend type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100596
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700597private type record length(8) of FreqHopGroups FreqHopConfig;
598
599private type record of FreqHopGroup FreqHopGroups;
600private type record FreqHopGroup {
601 uint6_t hsn,
602 FreqHopGroupItems trx_maio
603};
604
605private type record of FreqHopGroupItem FreqHopGroupItems;
606private type record FreqHopGroupItem {
607 uint8_t trx_nr,
608 uint6_t maio
609};
610
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700611friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
612 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700613{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700614 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700615 var integer i, j;
616
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700617 fhp.enabled := false;
618
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700619 for (i := 0; i < lengthof(groups); i := i + 1) {
620 var FreqHopGroup g := groups[i];
621 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
622 var FreqHopGroupItem gi := g.trx_maio[j];
623 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700624 fhp.maio_hsn.maio := gi.maio;
625 fhp.maio_hsn.hsn := g.hsn;
626 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700627 break;
628 }
629 }
630
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700631 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700632 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700633 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
634 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
635 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700636
637 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700638 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
639 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700640 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700641 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700642 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700643 }
644
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700645 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700646 break; /* We're done */
647 }
648 }
649}
650
Harald Welte70767382018-02-21 12:16:40 +0100651/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700652friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
653 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200654 boolean trxc_comp := false,
655 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100656runs on test_CT return ConnHdlr {
657 var charstring id := testcasename();
658 var ConnHdlr vc_conn;
659
660 vc_conn := ConnHdlr.create(id);
661 /* connect to RSL Emulation main component */
662 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
663 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700664
665 /* The ConnHdlr component may want to talk to some ports directly,
666 * so we disconnect it from the test_CT and connect it to the component.
667 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200668 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200669 unmap(self:PCU, system:PCU);
670 map(vc_conn:PCU, system:PCU);
671 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700672 if (trxc_comp) {
673 unmap(self:BTS_TRXC, system:BTS_TRXC);
674 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
675 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200676 if (l1ctl) {
677 map(vc_conn:L1CTL, system:L1CTL);
678 }
Harald Welte70767382018-02-21 12:16:40 +0100679
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700680 /* Obtain frequency hopping parameters for a given timeslot */
681 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700682 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700683 }
684
Harald Welte70767382018-02-21 12:16:40 +0100685 vc_conn.start(f_handler_init(fn, id, pars));
686 return vc_conn;
687}
688
Harald Welte70767382018-02-21 12:16:40 +0100689private altstep as_Tguard() runs on ConnHdlr {
690 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100692 }
693}
694
Harald Welte990a3612019-05-27 14:02:13 +0200695friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700696 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700697 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100698}
699
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700700private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100701 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700702 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100703}
704
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700705private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100706 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700707 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100708}
709
710/* first function started in ConnHdlr component */
711private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
712runs on ConnHdlr {
713 g_pars := pars;
714 g_chan_nr := pars.chan_nr;
715
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200716 if (L1CTL.checkstate("Mapped")) {
717 f_connect_reset(L1CTL);
718 }
Harald Welte70767382018-02-21 12:16:40 +0100719
Harald Welted48c0c72019-06-05 10:01:15 +0200720 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700721 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100722 }
Harald Welte70767382018-02-21 12:16:40 +0100723
724 g_Tguard.start(pars.t_guard);
725 activate(as_Tguard());
726
727 f_rslem_register(0, pars.chan_nr);
728
729 /* call the user-supplied test case function */
730 fn.apply(id);
731}
732
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700733private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
734 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200735runs on ConnHdlr return RSL_Message {
736 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100737 timer T := 3.0;
738 RSL.send(tx);
739 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100740 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200741 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100742 T.stop;
743 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100744 }
Harald Welte1eba3742018-02-25 12:48:14 +0100745 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200746 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100747 }
Harald Welte21240e62018-03-11 21:43:35 +0100748 [not ignore_other] as_l1_sacch();
749 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700750 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700751 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100752 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200753 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100754 }
Harald Welte21240e62018-03-11 21:43:35 +0100755 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100756 }
Harald Welteb1726c92018-03-30 11:56:38 +0200757 return rx;
758}
759
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700760friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
761 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200762runs on ConnHdlr {
763 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100764}
765
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700766friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
767 boolean encr_enable := false,
768 RSL_IE_List more_ies := {},
769 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
770runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200771 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200772 if (encr_enable) {
773 /* append encryption related IEs, if requested */
774 var RSL_IE_EncryptionInfo encr_info;
775 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
776 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
777encr_info})) };
778 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200779 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200780 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100781}
782
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700783friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100784 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 +0100785 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100786}
787
Harald Welte2f2b2b72019-05-31 22:24:57 +0200788friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200789 template RSL_IE_ChannelMode chan_mode,
790 template (omit) TestSpecUnion spec := omit,
791 float t_guard := 20.0) := {
Harald Welte70767382018-02-21 12:16:40 +0100792 chan_nr := valueof(chan_nr),
793 chan_mode := valueof(chan_mode),
794 t_guard := t_guard,
795 l1_pars := {
796 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100797 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100798 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100799 meas_ul := {
800 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200801 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100802 rxqual := 0
803 },
804 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200805 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100806 rxqual := 0
807 }
808 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200809 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100810 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200811 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200812 ms_actual_ta := mp_ms_actual_ta_exp,
813 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100814 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200815 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200816 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700817 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700818 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700819 fhp := {
820 enabled := false,
821 maio_hsn := ts_HsnMaio(0, 0),
822 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700823 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700824 }
Harald Welte70767382018-02-21 12:16:40 +0100825}
826
Harald Welte93640c62018-02-25 16:59:33 +0100827/***********************************************************************
828 * Channel Activation / Deactivation
829 ***********************************************************************/
830
Harald Welte70767382018-02-21 12:16:40 +0100831/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700832private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100833 for (var integer i := 0; i < 500; i := i+1) {
834 f_rsl_chan_act(g_pars.chan_mode);
835 f_rsl_chan_deact();
836 }
837 setverdict(pass);
838}
839testcase TC_chan_act_stress() runs on test_CT {
840 var ConnHdlr vc_conn;
841 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200842 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100843 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
844 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100846}
847
848/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700849private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100850 f_rsl_chan_act(g_pars.chan_mode);
851 /* attempt to activate the same lchan again -> expect reject */
852 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
853 alt {
854 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100856 }
857 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
858 setverdict(pass);
859 }
860 }
861 f_rsl_chan_deact();
862}
863testcase TC_chan_act_react() runs on test_CT {
864 var ConnHdlr vc_conn;
865 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100866 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100867 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
868 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200869 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100870}
871
872/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700873private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100874 timer T := 3.0;
875 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
876 T.start;
877 alt {
878 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
879 setverdict(pass);
880 }
881 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100883 }
884 }
885}
886testcase TC_chan_deact_not_active() runs on test_CT {
887 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100888 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100889 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
890 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200891 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100892}
893
894/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700895private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100896 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
897 alt {
898 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200899 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100900 }
901 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
902 setverdict(pass);
903 }
904 }
905}
906private type record WrongChanNrCase {
907 RslChannelNr chan_nr,
908 charstring description
909}
910private type record of WrongChanNrCase WrongChanNrCases;
911private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
912 chan_nr := chan_nr,
913 description := desc
914}
915
916testcase TC_chan_act_wrong_nr() runs on test_CT {
917 var ConnHdlr vc_conn;
918 var ConnHdlrPars pars;
919
Harald Welte294b0a22018-03-10 23:26:48 +0100920 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100921
922 var WrongChanNrCases wrong := {
923 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
924 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
925 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
926 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
927 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
928 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
929 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
930 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
931 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
932 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
933 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
934 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
935 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
936 };
937
938 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
939 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
940 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
941 vc_conn.done;
942 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200943 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100944}
945
Harald Weltee613f962018-04-18 22:38:16 +0200946/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200947friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200948 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200949 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200950
951 /* test on each of the channels we have */
952 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
953 pars.chan_nr := valueof(g_AllChanTypes[i]);
954
955 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
956 vc_conn := f_start_handler(fn, pars);
957 vc_conn.done;
958 }
959
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200961}
962
Harald Welte93640c62018-02-25 16:59:33 +0100963/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100964 * SACCH handling
965 ***********************************************************************/
966
967private function f_exp_sacch(boolean exp) runs on ConnHdlr {
968 timer T_sacch := 3.0;
969 T_sacch.start;
970 alt {
971 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100973 }
974 [not exp] T_sacch.timeout {
975 setverdict(pass);
976 }
977 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
978 setverdict(pass);
979 }
980 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100982 }
983 [] L1CTL.receive { repeat; }
984 [] RSL.receive { repeat; }
985 }
986}
987
988/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
989private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
990 f_l1_tune(L1CTL);
991 RSL.clear;
992
993 /* activate the logical channel */
994 f_est_dchan();
995 L1CTL.clear;
996
997 /* check that SACCH actually are received as expected */
998 f_exp_sacch(true);
999
1000 /* deactivate SACCH on the logical channel */
1001 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
1002 f_sleep(1.0);
1003 L1CTL.clear;
1004
1005 /* check that no SACCH are received anymore */
1006 f_exp_sacch(false);
1007
1008 /* release the channel */
1009 f_rsl_chan_deact();
1010 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1011}
1012testcase TC_deact_sacch() runs on test_CT {
1013 var ConnHdlr vc_conn;
1014 var ConnHdlrPars pars;
1015 f_init();
1016 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1017 //for (var integer i := 0; i < 1; i := i+1) {
1018 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1019 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1020 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1021 vc_conn.done;
1022 }
1023 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001025}
1026
Harald Welte55700662018-03-12 13:15:43 +01001027/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +01001028private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
1029 var L1ctlDlMessage dl;
1030 /* check that the specified SI5 value is actually sent */
1031 timer T_sacch := 3.0;
1032 L1CTL.clear;
1033 T_sacch.start;
1034 alt {
1035 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1036 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1037 if (match(l3, l3_exp)) {
1038 setverdict(pass);
1039 } else {
1040 repeat;
1041 }
1042 }
1043 [] L1CTL.receive { repeat; }
1044 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001045 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +01001046 }
1047 }
1048}
1049
Harald Welte55700662018-03-12 13:15:43 +01001050/* verify that given SACCH payload is not present */
1051private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1052 var L1ctlDlMessage dl;
1053 /* check that the specified SI5 value is actually sent */
1054 timer T_sacch := 3.0;
1055 L1CTL.clear;
1056 T_sacch.start;
1057 alt {
1058 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1059 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1060 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001061 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001062 } else {
1063 repeat;
1064 }
1065 }
1066 [] L1CTL.receive { repeat; }
1067 [] T_sacch.timeout {
1068 setverdict(pass);
1069 }
1070 }
1071}
1072
Harald Welte629cc6b2018-03-11 17:19:05 +01001073/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001074private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1075 /* Set a known default SACCH filling for SI5 */
1076 var octetstring si5 := f_rnd_octstring(19);
1077 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1078
1079 f_l1_tune(L1CTL);
1080 RSL.clear;
1081
1082 /* activate the logical channel */
1083 f_est_dchan();
1084
1085 /* check that the specified SI5 value is actually sent */
1086 f_sacch_present(si5);
1087
1088 /* release the channel */
1089 RSL.clear;
1090 f_rsl_chan_deact();
1091 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1092}
1093testcase TC_sacch_filling() runs on test_CT {
1094 var ConnHdlr vc_conn;
1095 var ConnHdlrPars pars;
1096 f_init();
1097 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1098 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1099 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1100 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1101 vc_conn.done;
1102 }
1103 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001105}
1106
Harald Welte629cc6b2018-03-11 17:19:05 +01001107/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001108private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1109 /* Set a known default SACCH filling for SI5 */
1110 var octetstring si5 := f_rnd_octstring(19);
1111 var octetstring si5_diff := f_rnd_octstring(19);
1112 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1113
1114 f_l1_tune(L1CTL);
1115 RSL.clear;
1116
1117 log("Activating channel, expecting standard SI5");
1118 /* activate the logical channel */
1119 f_est_dchan();
1120 /* check that the specified SI5 value is actually sent */
1121 f_sacch_present(si5);
1122
1123 /* set channel-specific different SI5 */
1124 log("Setting channel specific SACCH INFO, expecting it");
1125 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1126 /* check that the specified lchan-specific value is now used */
1127 f_sacch_present(si5_diff);
1128
1129 /* deactivate the channel and re-activate it, this should result in default SI5 */
1130 log("De-activating and re-activating channel, expecting standard SI5");
1131 f_rsl_chan_deact();
1132 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1133 /* Verify that the TRX-wide default SACCH filling is present again */
1134 f_sacch_present(si5);
1135
1136 /* release the channel */
1137 RSL.clear;
1138 f_rsl_chan_deact();
1139 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1140}
1141testcase TC_sacch_info_mod() runs on test_CT {
1142 var ConnHdlr vc_conn;
1143 var ConnHdlrPars pars;
1144 f_init();
1145 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1146 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1147 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1148 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1149 vc_conn.done;
1150 }
1151 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001152 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001153}
1154
Harald Welte075d84c2018-03-12 13:07:24 +01001155/* Test SACCH scheduling of multiple different SI message types */
1156private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1157 var octetstring si5 := f_rnd_octstring(19);
1158 var octetstring si5bis := f_rnd_octstring(19);
1159 var octetstring si5ter := f_rnd_octstring(19);
1160 var octetstring si6 := f_rnd_octstring(19);
1161
1162 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1163 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1164 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1165 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1166
1167 f_l1_tune(L1CTL);
1168 RSL.clear;
1169
1170 /* activate the logical channel */
1171 f_est_dchan();
1172 L1CTL.clear;
1173
1174 /* check that SACCH actually are received as expected */
1175 f_sacch_present(si5);
1176 f_sacch_present(si5bis);
1177 f_sacch_present(si5ter);
1178 f_sacch_present(si6);
1179
1180 /* release the channel */
1181 f_rsl_chan_deact();
1182 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1183}
1184testcase TC_sacch_multi() runs on test_CT {
1185 var ConnHdlr vc_conn;
1186 var ConnHdlrPars pars;
1187 f_init();
1188 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1189 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1190 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1191 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1192 vc_conn.done;
1193 }
1194 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001195 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001196}
1197
Harald Welte55700662018-03-12 13:15:43 +01001198/* Test if SACH information is modified as expected */
1199private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1200 var octetstring si5 := f_rnd_octstring(19);
1201 var octetstring si6 := f_rnd_octstring(19);
1202
1203 /* First, configure both SI5 and SI6 to be transmitted */
1204 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1205 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1206
1207 f_l1_tune(L1CTL);
1208 RSL.clear;
1209
1210 /* activate the logical channel */
1211 f_est_dchan();
1212 L1CTL.clear;
1213
1214 /* check that SACCH actually are received as expected */
1215 f_sacch_present(si5);
1216 f_sacch_present(si6);
1217
1218 /* disable SI6 */
1219 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1220
1221 /* check that SI5 is still transmitted */
1222 f_sacch_present(si5);
1223 /* check if SI6 is now gone */
1224 f_sacch_missing(si6);
1225
1226 /* release the channel */
1227 f_rsl_chan_deact();
1228 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1229}
1230testcase TC_sacch_multi_chg() runs on test_CT {
1231 var ConnHdlr vc_conn;
1232 var ConnHdlrPars pars;
1233 f_init();
1234 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1235 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1236 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1237 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1238 vc_conn.done;
1239 }
1240 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001242}
1243
Harald Weltec8d363c2019-05-19 20:36:48 +02001244/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1245private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1246 var octetstring si5 := f_rnd_octstring(19);
1247 var octetstring si6 := f_rnd_octstring(19);
1248 var octetstring si5_specific := f_rnd_octstring(19);
1249 var octetstring si6_specific := f_rnd_octstring(19);
1250
1251 /* First, configure both SI5 and SI6 to be transmitted */
1252 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1253 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1254
1255 f_l1_tune(L1CTL);
1256 RSL.clear;
1257
1258 /* activate channel with different SACCH filling */
1259 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1260 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1261 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1262 }));
1263 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1264 RSL_IE_Body:{sacch_info := sacch_info})) };
1265 f_est_dchan(more_ies := addl_ies);
1266
1267 /* check that SACCH actually are received as expected */
1268 f_sacch_present(si5_specific);
1269 f_sacch_present(si6_specific);
1270
1271 /* release the channel */
1272 f_rsl_chan_deact();
1273 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1274}
1275testcase TC_sacch_chan_act() runs on test_CT {
1276 var ConnHdlr vc_conn;
1277 var ConnHdlrPars pars;
1278 f_init();
1279
1280 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1281 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1282 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1283 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1284 vc_conn.done;
1285 }
1286 /* TODO: do the above in parallel, rather than sequentially? */
1287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1288}
1289
Harald Welte8b01c792019-05-19 22:51:25 +02001290/* verify that SACCH DL transmission is started only if MS power IE present
1291 * see section 4.1.3 of 3GPP TS 48.058 */
1292private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1293 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001294 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001295
1296 f_l1_tune(L1CTL);
1297 RSL.clear;
1298
1299 /* Step 1: Activate ASYNC HO channel without MS power IE */
1300
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001301 var integer ho_ref := oct2int(f_rnd_octstring(1));
1302 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1303 RSL_IE_Body:{ handover_ref := ho_ref }));
1304 var RSL_IE_List addl_ies := {
1305 ho_ref_ie
1306 };
1307
Harald Welte8b01c792019-05-19 22:51:25 +02001308 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001309 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 +02001310 /* don't perform immediate assignment here, as we're testing non-IA case */
1311 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001312 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001313
1314 /* Verify that no DL SACCH is being received */
1315 f_sacch_missing(?);
1316
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001317 /* Send handover Access Burst and expect SACCH to start */
1318 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1319
1320 f_sacch_present(si5);
1321
Harald Welte8b01c792019-05-19 22:51:25 +02001322 f_rsl_chan_deact();
1323 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1324
1325
1326 /* Step 2: Activate ASYNC HO channel with MS power IE */
1327
1328 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001329 addl_ies := {
1330 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001331 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1332 };
1333 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1334 /* don't perform immediate assignment here, as we're testing non-IA case */
1335 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001336 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001337
1338 /* Verify that DL SACCH is being received */
1339 f_sacch_present(si5);
1340
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001341 /* Send handover Access Burst and expect SACCH to remain present */
1342 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1343
1344 f_sacch_present(si5);
1345
Harald Welte8b01c792019-05-19 22:51:25 +02001346 f_rsl_chan_deact();
1347 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1348}
1349testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1350 var ConnHdlr vc_conn;
1351 var ConnHdlrPars pars;
1352 f_init();
1353
1354 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1355 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1356 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1357 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1358 vc_conn.done;
1359 }
1360 /* TODO: do the above in parallel, rather than sequentially? */
1361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1362}
1363
1364/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1365 * see section 4.1.4 of 3GPP TS 48.058 */
1366private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1367 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001368 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1369
Harald Welte8b01c792019-05-19 22:51:25 +02001370 var RSL_IE_List addl_ies;
1371
1372 f_l1_tune(L1CTL);
1373 RSL.clear;
1374
1375 /* Step 1: Activate SYNC HO channel without MS power IE */
1376
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001377 var integer ho_ref := oct2int(f_rnd_octstring(1));
1378 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1379 RSL_IE_Body:{ handover_ref := ho_ref }));
1380 addl_ies := {
1381 ho_ref_ie
1382 };
1383
Harald Welte8b01c792019-05-19 22:51:25 +02001384 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001385 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 +02001386 /* don't perform immediate assignment here, as we're testing non-IA case */
1387 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001388 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001389
1390 /* Verify that no DL SACCH is being received */
1391 f_sacch_missing(?);
1392
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001393 /* Send handover Access Burst and expect SACCH to start */
1394 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1395
1396 f_sacch_present(si5);
1397
Harald Welte8b01c792019-05-19 22:51:25 +02001398 f_rsl_chan_deact();
1399 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1400
1401
1402 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1403
1404 /* Activate channel on BTS side */
1405 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001406 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001407 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1408 };
1409 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1410 /* don't perform immediate assignment here, as we're testing non-IA case */
1411 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001412 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001413
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001414 /* Verify that DL SACCH is being received, because MS Power IE was sent */
1415 f_sacch_present(si5);
Harald Welte8b01c792019-05-19 22:51:25 +02001416
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001417 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001418 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1419
1420 f_sacch_present(si5);
1421
Harald Welte8b01c792019-05-19 22:51:25 +02001422 f_rsl_chan_deact();
1423 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1424
1425
1426 /* Step 2b: Activate SYNC HO channel with TA IE */
1427
1428 /* Activate channel on BTS side */
1429 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001430 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001431 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1432 };
1433 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1434 /* don't perform immediate assignment here, as we're testing non-IA case */
1435 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001436 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001437
1438 /* Verify that no DL SACCH is being received */
1439 f_sacch_missing(?);
1440
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001441 /* Send handover Access Burst and expect SACCH to start */
1442 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1443
1444 f_sacch_present(si5);
1445
Harald Welte8b01c792019-05-19 22:51:25 +02001446 f_rsl_chan_deact();
1447 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1448
1449
1450 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1451
1452 /* Activate channel on BTS side */
1453 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001454 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001455 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1456 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1457 };
1458 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1459 /* don't perform immediate assignment here, as we're testing non-IA case */
1460 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001461 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001462
1463 /* Verify that DL SACCH is being received */
1464 f_sacch_present(si5);
1465
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001466 /* Send handover Access Burst and expect SACCH to remain present */
1467 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1468
1469 f_sacch_present(si5);
1470
Harald Welte8b01c792019-05-19 22:51:25 +02001471 f_rsl_chan_deact();
1472 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1473}
1474testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1475 var ConnHdlr vc_conn;
1476 var ConnHdlrPars pars;
1477 f_init();
1478
1479 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1480 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1481 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1482 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1483 vc_conn.done;
1484 }
1485 /* TODO: do the above in parallel, rather than sequentially? */
1486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1487}
Harald Welte629cc6b2018-03-11 17:19:05 +01001488
1489
1490/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001491 * RACH Handling
1492 ***********************************************************************/
1493
Harald Welte8c24c2b2018-02-26 08:31:31 +01001494/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001495private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001496 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001497 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001498 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001499
Harald Welte8c24c2b2018-02-26 08:31:31 +01001500 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001501 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001502 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001503 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001504 if (emerg == true) {
1505 ra := f_rnd_ra_emerg();
1506 } else {
1507 ra := f_rnd_ra_cs();
1508 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001509 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1510 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001511 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001512 }
1513 fn_last := fn;
1514
1515 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001516 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001517 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001518 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001519 T.stop;
1520 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001521 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001523 }
1524 [] RSL_CCHAN.receive { repeat; }
1525 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001526 test_failed := true;
1527 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001528 }
1529 }
1530 }
Maxba06feb2019-03-05 10:52:46 +01001531 if (test_failed) {
1532 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001533 }
Maxba06feb2019-03-05 10:52:46 +01001534 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001536}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001537
Philipp Maier16ade782020-07-08 21:36:00 +02001538/* Normal variant */
1539testcase TC_rach_content() runs on test_CT {
1540 f_TC_rach_content(emerg := false);
1541}
1542
1543/* Emergency call variant */
1544testcase TC_rach_content_emerg() runs on test_CT {
1545 f_TC_rach_content(emerg := true);
1546}
1547
Harald Welte8c24c2b2018-02-26 08:31:31 +01001548/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1549testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001550 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001551 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001552 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001553 f_l1_tune(L1CTL);
1554
1555 var GsmFrameNumber fn_last := 0;
1556 for (var integer i := 0; i < 1000; i := i+1) {
1557 var OCT1 ra := f_rnd_ra_cs();
1558 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1559 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001561 }
1562 fn_last := fn;
1563 }
1564 var integer rsl_chrqd := 0;
1565 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001566 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001567 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001568 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001569 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001570 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001571 repeat;
1572 }
1573 [] RSL_CCHAN.receive { repeat; }
1574 [] T.timeout { }
1575 }
1576 if (rsl_chrqd == 1000) {
1577 setverdict(pass);
1578 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001579 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001580 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001581 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001582}
1583
Harald Welte3453ab42019-05-24 21:19:58 +02001584private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1585 var charstring bts_str := "bts " & int2str(bts_nr);
1586 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1587}
1588
1589/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1590private template integer tr_rach_slots_per_interval := (90 .. 130);
1591
1592/* Expect 0 RACH load on an idle BTS that has just started up */
1593testcase TC_rach_load_idle_thresh0() runs on test_CT {
1594 var ASP_RSL_Unitdata rx_ud;
1595
1596 f_init_vty_bsc();
1597 /* send load indications even at 0% load */
1598 f_vty_load_ind_thresh(0);
1599 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1600 f_sleep(2.0);
1601
1602 f_init();
1603
Harald Weltee37f9a52020-10-11 20:45:23 +02001604 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1605 alt {
1606 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1607 [] RSL_CCHAN.receive { repeat }
1608 }
1609
Harald Welte3453ab42019-05-24 21:19:58 +02001610 timer T := 5.0;
1611 T.start;
1612 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001613 [] 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 +02001614 setverdict(pass);
1615 repeat;
1616 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001617 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001618 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1619 repeat;
1620 }
1621 [] RSL_CCHAN.receive {
1622 repeat;
1623 }
1624 [] T.timeout { }
1625 }
1626
1627 f_vty_load_ind_thresh(10);
1628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1629}
1630
1631/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1632testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1633 var ASP_RSL_Unitdata rx_ud;
1634
1635 f_init_vty_bsc();
1636 f_init();
1637
1638 timer T := 5.0;
1639 T.start;
1640 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001641 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001642 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1643 repeat;
1644 }
1645 [] RSL_CCHAN.receive {
1646 repeat;
1647 }
1648 [] T.timeout {
1649 setverdict(pass);
1650 }
1651 }
1652
1653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1654}
1655
1656/* Expect 0 RACH load on an idle BTS that has just started up */
1657testcase TC_rach_load_count() runs on test_CT {
1658 var ASP_RSL_Unitdata rx_ud;
1659 var integer load_access_count := 0;
1660
1661 f_init_vty_bsc();
1662 /* send load indications even at 0% load */
1663 f_vty_load_ind_thresh(0);
1664 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1665 f_sleep(2.0);
1666 f_init();
1667
1668 f_init_l1ctl();
1669 f_sleep(1.0);
1670 f_l1_tune(L1CTL);
1671
Harald Welte52ae1682020-10-11 20:45:55 +02001672 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1673 alt {
1674 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1675 [] RSL_CCHAN.receive { repeat }
1676 }
1677
Harald Welte3453ab42019-05-24 21:19:58 +02001678 var GsmFrameNumber fn_last := 0;
1679 for (var integer i := 0; i < 1000; i := i+1) {
1680 var OCT1 ra := f_rnd_ra_cs();
1681 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1682 if (fn == fn_last) {
1683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1684 }
1685 fn_last := fn;
1686 }
1687
1688 timer T := 5.0;
1689 T.start;
1690 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001691 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001692 -> value rx_ud {
1693 var RSL_IE_Body ie;
1694 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1695 load_access_count := load_access_count + ie.rach_load.access_count;
1696 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1697 setverdict(fail, "Access count cannot be < Busy count");
1698 }
1699 repeat;
1700 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001701 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001702 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1703 repeat;
1704 }
1705 [] RSL_CCHAN.receive {
1706 repeat;
1707 }
1708 [] T.timeout { }
1709 }
1710 if (load_access_count == 1000) {
1711 setverdict(pass);
1712 } else {
1713 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1714 }
1715
1716 f_vty_load_ind_thresh(10);
1717 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1718}
1719
Harald Welte54a2a2d2018-02-26 09:14:05 +01001720private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001721 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001722 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001723 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001724 f_sleep(0.5);
1725
1726 /* Transmit RACH request + wait for confirmation */
1727 var OCT1 ra := f_rnd_ra_cs();
1728 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1729
1730 /* Check for expected result */
1731 timer T := 1.5;
1732 T.start;
1733 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001734 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001735 setverdict(pass);
1736 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001737 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001739 }
1740 [] RSL_CCHAN.receive { repeat; }
1741 [not expect_pass] T.timeout {
1742 setverdict(pass);
1743 }
1744 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001745 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001746 }
1747 }
1748}
1749
1750/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1751testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001752 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001753 f_init_l1ctl();
1754 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001755 f_sleep(1.0);
1756
1757 /* default max-ta is 63 (full range of GSM timing advance */
1758
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001759 /* We allow early arrival up to 2 symbols */
1760 f_rach_toffs(-1*256, true);
1761 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001762 f_rach_toffs(-10*256, false);
1763
1764 /* 0 / 32 / 63 bits is legal / permitted */
1765 f_rach_toffs(0, true);
1766 f_rach_toffs(32*256, true);
1767 f_rach_toffs(63*256, true);
1768
1769 /* more than 63 bits is not legal / permitted */
1770 f_rach_toffs(64*256, false);
1771 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001772 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001773}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001774
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001775private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001776 var GsmFrameNumber fn;
1777 var RSL_Message rm;
1778
1779 f_l1_tune(L1CTL);
1780 RSL.clear;
1781
1782 /* Generate a random Handover Reference */
1783 var integer ho_ref := oct2int(f_rnd_octstring(1));
1784
1785 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1786 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1787 RSL_IE_Body:{ handover_ref := ho_ref }));
1788
1789 /* Activate a channel on the BTS side (no encryption) */
1790 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1791 act_type := t_RSL_IE_ActType_HO_SYNC);
1792
1793 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1794 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001795 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001796
1797 /* Send handover Access Burst */
1798 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1799
1800 /* TODO: test mismatching Handover Reference, and missing IE */
1801
1802 /* Wait for handover detection */
1803 timer T := 3.0;
1804 T.start;
1805 alt {
1806 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1807 log("Handover RACH has been detected: ", rm);
1808 setverdict(pass);
1809 }
1810 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1812 log2str("RSL_CHAN_RQD was not expected: ", rm));
1813 }
1814 [] RSL.receive { repeat; }
1815 [] T.timeout {
1816 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1817 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1818 }
1819 }
1820
1821 /* Release the channel */
1822 f_rsl_chan_deact();
1823 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1824}
1825
1826/* Test handover RACH detection */
1827testcase TC_ho_rach() runs on test_CT {
1828 var ConnHdlrPars pars;
1829 var ConnHdlr vc_conn;
1830
1831 f_init();
1832
1833 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1834 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1835 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1836 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1837 vc_conn.done;
1838 }
1839
1840 /* TODO: do the above in parallel, rather than sequentially? */
1841 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1842}
1843
Harald Welte93640c62018-02-25 16:59:33 +01001844/***********************************************************************
1845 * Measurement Processing / Reporting
1846 ***********************************************************************/
1847
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001848private template (value) LapdmAddressField
1849ts_LapdmAddr(template (value) LapdmSapi sapi,
1850 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001851 spare := '0'B,
1852 lpd := 0,
1853 sapi := sapi,
1854 c_r := c_r,
1855 ea := true
1856}
1857
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001858private template (value) LapdmFrameAB
1859ts_LAPDm_AB(template (value) LapdmSapi sapi,
1860 template (value) GsmRrL3Message l3,
1861 template (value) boolean c_r := false,
1862 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01001863 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001864 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01001865 len := 0, /* overwritten */
1866 m := false,
1867 el := 1,
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001868 payload := enc_GsmRrL3Message(valueof(l3))
Harald Welte70767382018-02-21 12:16:40 +01001869}
1870
1871/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001872private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001873 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01001874 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001875
Harald Weltef8df4cb2018-03-10 15:15:08 +01001876 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001877 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001878
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001879 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07001880 g_pars.l1_pars.meas_ul.full.rxlev,
1881 g_pars.l1_pars.meas_ul.sub.rxlev,
1882 g_pars.l1_pars.meas_ul.full.rxqual,
1883 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01001884 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001885
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001886 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1887 g_pars.l1_pars.ms_power_level, false,
1888 g_pars.l1_pars.ms_actual_ta);
1889
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01001890 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
1891 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001892
1893 log("Sending Measurement Report: ", l1h, l2);
1894 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001895 repeat;
1896 }
1897}
1898
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07001899/* handle incoming downlink SACCH, decode the L1 header into the given record */
1900private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
1901 boolean do_apply := true)
1902runs on ConnHdlr
1903{
1904 var L1ctlDlMessage l1_dl;
1905
1906 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1907 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
1908 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
1909 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
1910
1911 if (do_apply) {
1912 /* Update TA and MS power to follow what BTS requests */
1913 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
1914 }
1915 }
1916}
1917
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001918private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001919 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001920 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001921 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1922 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001923 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1924 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001925 repeat;
1926 }
1927}
1928
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001929private altstep as_l1_tch_loop() runs on ConnHdlr {
1930 var L1ctlDlMessage l1_dl;
1931 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1932 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001933
1934 /* occasionaly inject FACCH frames into the uplink */
1935 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1936 var octetstring pl := '010301'O;
1937 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1938 f_pad_oct(pl, 23, '2B'O)));
1939 } else {
1940 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1941 l1_dl.payload.traffic_ind.data));
1942 }
1943
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001944 repeat;
1945 }
1946}
1947
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001948private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001949 uint6_t rxlev,
1950 uint3_t rxqual
1951}
1952
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001953private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001954 MeasElem full,
1955 MeasElem sub
1956}
1957
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001958private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001959 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001960 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001961 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01001962 MeasElemFS meas_ul,
1963 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001964 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001965 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02001966 uint8_t ms_actual_ta,
1967 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01001968}
1969
1970/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1971private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1972 return 63 + (toffs256s/256);
1973}
1974
Harald Welted5684392018-03-10 18:22:04 +01001975private function f_max(integer a, integer b) return integer {
1976 if (a > b) {
1977 return a;
1978 } else {
1979 return b;
1980 }
1981}
1982
1983private function f_min(integer a, integer b) return integer {
1984 if (a < b) {
1985 return a;
1986 } else {
1987 return b;
1988 }
1989}
1990
1991/* compute negative tolerance val-tolerance, ensure >= min */
1992private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1993 val := val - tolerance;
1994 return f_max(val, min);
1995}
1996
1997/* compute positive tolerance val+tolerance, ensure <= max */
1998private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1999 val := val + tolerance;
2000 return f_min(val, max);
2001}
2002
2003/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
2004private function f_tolerance(integer val, integer min, integer max, integer tolerance)
2005return template integer {
2006 var template integer ret;
2007 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
2008 return ret;
2009}
2010
2011
Harald Welte70767382018-02-21 12:16:40 +01002012/* build a template for matching measurement results against */
2013private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2014 var ConnL1Pars l1p := g_pars.l1_pars;
2015 var template RSL_IE_UplinkMeas ul_meas := {
2016 len := 3,
2017 rfu := '0'B,
2018 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002019 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002020 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002021 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002022 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002023 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2024 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002025 supp_meas_info := omit
2026 };
Harald Welte685d5982018-02-27 20:42:05 +01002027 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002028 ul_meas.len := (3+8);
2029 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002030 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002031 toa256_min := ?,
2032 toa256_max := ?,
2033 toa256_std_dev := ?
2034 }
Harald Welte685d5982018-02-27 20:42:05 +01002035 }
Harald Welte70767382018-02-21 12:16:40 +01002036 var template RSL_IE_BS_Power bs_power := {
2037 reserved := 0,
2038 epc := false,
2039 fpc := false,
2040 power_level := l1p.bs_power_level
2041 };
2042 var template RSL_IE_L1Info l1_info := {
2043 ms_power_lvl := l1p.ms_power_level,
2044 fpc := false,
2045 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002046 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002047 };
2048 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002049 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002050 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2051 ?, t_toffs);
2052}
2053
Philipp Maierdd841d32019-12-17 14:44:54 +01002054/* build a template for matching measurement results that do not contain any
2055 * MS related measurement (l1_info, l3_info and ms timing offset). */
2056private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2057 var ConnL1Pars l1p := g_pars.l1_pars;
2058 var template RSL_IE_UplinkMeas ul_meas := {
2059 len := 3,
2060 rfu := '0'B,
2061 dtx_d := l1p.dtx_enabled,
2062 rxlev_f_u := ?,
2063 reserved1 := '00'B,
2064 rxlev_s_u := ?,
2065 reserved2 := '00'B,
2066 rxq_f_u := ?,
2067 rxq_s_u := ?,
2068 supp_meas_info := omit
2069 };
2070 if (l1p.toa256_enabled) {
2071 ul_meas.len := (3+8);
2072 ul_meas.supp_meas_info := {
2073 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2074 toa256_min := ?,
2075 toa256_max := ?,
2076 toa256_std_dev := ?
2077 }
2078 }
2079 var template RSL_IE_BS_Power bs_power := {
2080 reserved := 0,
2081 epc := false,
2082 fpc := false,
2083 power_level := l1p.bs_power_level
2084 };
2085
2086 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2087}
2088
Harald Welte70767382018-02-21 12:16:40 +01002089/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002090private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002091 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002092 var boolean chan_est := false;
2093
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002094 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002095
2096 /* Receive osmocom specific measurement reports. This is the normal
2097 * case. Here we verify that the measurement reports we sent are
2098 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002099 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2100 /* increment counter of next to-be-expected meas rep */
2101 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2102 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002103 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002104
2105 /* The following two cases may only happen in the beginning
2106 * of the channel establishment phase. Once we have received
2107 * the "our" measurement report the first time, the channel
2108 * is established and empty or hardcoded TRXCON reports must
2109 * not occur anymore. */
2110 chan_est := true;
2111
2112 repeat;
2113 }
2114
2115 /* When the BTS has established the channel, the MS might need slightly
2116 * more time to establish the channel and actually start sending. The
2117 * result is then a measurement report that just lacks the measurement
2118 * information of the MS. This is normal and we tolerate this behavior. */
2119 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2120 /* increment counter of next to-be-expected meas rep */
2121 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2122 /* Re-start the timer expecting the next MEAS RES */
2123 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002124 repeat;
2125 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002126
2127 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2128 * measurements if the TTCN3 side does not supply measurement input in
2129 * time. In those cases TRXCON will either use a cached measurement
2130 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2131 * report the templates above will not match. We tolerate this
2132 * behavior, but only once. */
2133 [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 +01002134 /* increment counter of next to-be-expected meas rep */
2135 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2136 if (g_first_meas_res) {
2137 g_first_meas_res := false;
2138 repeat;
2139 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002140 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002141 }
Harald Welte70767382018-02-21 12:16:40 +01002142 }
2143 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002145 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002146 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002148 }
2149}
2150
Harald Weltee613f962018-04-18 22:38:16 +02002151private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2152 select (rsl_alg_id) {
2153 case (RSL_ALG_ID_A5_0) { return 0; }
2154 case (RSL_ALG_ID_A5_1) { return 1; }
2155 case (RSL_ALG_ID_A5_2) { return 2; }
2156 case (RSL_ALG_ID_A5_3) { return 3; }
2157 case (RSL_ALG_ID_A5_4) { return 4; }
2158 case (RSL_ALG_ID_A5_5) { return 5; }
2159 case (RSL_ALG_ID_A5_6) { return 6; }
2160 case (RSL_ALG_ID_A5_7) { return 7; }
2161 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002162 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2163 /* Make compiler happy by calling mtc.stop here. It is already
2164 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002165 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002166 }
2167 }
2168}
2169
2170private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2171 select (rsl_alg_id) {
2172 case (RSL_ALG_ID_A5_1) { return '000'B; }
2173 case (RSL_ALG_ID_A5_2) { return '001'B; }
2174 case (RSL_ALG_ID_A5_3) { return '010'B; }
2175 case (RSL_ALG_ID_A5_4) { return '011'B; }
2176 case (RSL_ALG_ID_A5_5) { return '100'B; }
2177 case (RSL_ALG_ID_A5_6) { return '101'B; }
2178 case (RSL_ALG_ID_A5_7) { return '110'B; }
2179 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2181 /* Make compiler happy by calling mtc.stop here. It is already
2182 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002183 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002184 }
2185 }
2186}
2187
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002188/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2189private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2190 var GsmFrameNumber fn;
2191 timer T := 8.0;
2192
2193 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2194 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2195
2196 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2197 /* Send the actual RACH */
2198 fn := f_L1CTL_RACH(L1CTL, ra);
2199
2200 T.start;
2201 alt {
2202 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2203 [] T.timeout {
2204 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2205 }
2206 }
2207 T.stop
2208 return fn;
2209}
Harald Weltee613f962018-04-18 22:38:16 +02002210
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002211/* Tune to a dedicated channel: L1CTL only */
2212private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002213 if (not pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002214 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07002215 mp_trx_pars[0].arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002216 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002217 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002218 pars.fhp.maio_hsn.hsn,
2219 pars.fhp.maio_hsn.maio,
2220 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002221 }
2222}
2223
Harald Welte70767382018-02-21 12:16:40 +01002224/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002225private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002226 var GsmFrameNumber fn;
2227 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002228 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002229 var integer ra := 23;
2230
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002231 /* Send RACH request and wait for ChanReq */
2232 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002233
2234 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002235 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002236
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002237 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002238 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002239 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002240 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002241 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002242 }
2243
Harald Welte70767382018-02-21 12:16:40 +01002244 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002245 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 +01002246 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2247
2248 /* receive IMM.ASS on MS side */
2249 var ImmediateAssignment ia_um;
2250 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002251
2252 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2253 if (ch_desc.h != ia_um.chan_desc.h) {
2254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2255 }
2256
Harald Welte70767382018-02-21 12:16:40 +01002257 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002258 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002259 /* enable encryption, if requested */
2260 if (encr_enable) {
2261 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2262 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2263 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002264
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002265 /* Send TCH Mode Request to the L1 if needed */
2266 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2267 var L1ctlTchMode tch_mode;
2268
2269 select (g_pars.chan_mode.coding_alg_rate) {
2270 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2271 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2272 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2273 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2274 case else {
2275 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2276 " is not supported by the L1, falling back to signalling");
2277 tch_mode := L1CTL_CHAN_MODE_SIGN;
2278 }
2279 }
2280
2281 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2282 }
2283
Harald Weltefa45e9e2018-03-10 18:59:03 +01002284 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002285}
2286
2287/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002288private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002289 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002290 RSL.clear;
2291
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002292 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002293 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002294 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002295 }
Harald Welte70767382018-02-21 12:16:40 +01002296
2297 f_est_dchan();
2298
2299 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2300 * RSL measurement reports on Abis side */
2301 timer T := 8.0;
2302 T.start;
2303 alt {
2304 [] as_l1_sacch();
2305 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002306 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002307 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002308 [] L1CTL.receive { repeat; }
2309 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002310 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002311 * of any earlier errors, so if we reach this timeout, we're good */
2312 setverdict(pass);
2313 }
2314 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002315 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002316 }
2317 }
2318 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002319 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002320}
Harald Welte0472ab42018-03-12 15:02:26 +01002321
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002322/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2323private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002324 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002325 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2326 timer Tup := 10.0;
2327 Tup.start;
2328 alt {
2329 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2330 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2331 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002332
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002333 if (rx_lvl != max_rx_lvl) {
2334 repeat;
2335 }
2336 Tup.stop;
2337 }
2338 [] L1CTL.receive { repeat; }
2339 [] Tup.timeout {
2340 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2341 log2str("Didn't reach full power ", max_rx_lvl));
2342 }
2343 }
2344 return max_rx_lvl;
2345}
2346
2347/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2348private function f_verify_ramp_up() runs on ConnHdlr {
2349 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002350 var integer initial_rx_lvl := -1;
2351 var integer last_rx_lvl := -1;
2352 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2353
2354 timer T := 2.0;
2355 alt {
2356 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2357 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2358 log("Received rx_level=", rx_lvl);
2359 if (initial_rx_lvl == -1) {
2360 initial_rx_lvl := rx_lvl;
2361 last_rx_lvl := rx_lvl;
2362
2363 /* Expect a somehow low value during first received messages */
2364 if (initial_rx_lvl >= max_rx_lvl / 2) {
2365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2366 log2str("Detected high initial tx power during ramp up: ",
2367 initial_rx_lvl , ", full power is", max_rx_lvl));
2368 }
2369 }
2370
2371 /* received Rx level bigger than maximum allowed power by CN */
2372 if (rx_lvl > max_rx_lvl) {
2373 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2374 log2str("Detected Tx power higher than full power: ",
2375 rx_lvl , " > ", max_rx_lvl));
2376 }
2377
2378 /* Make sure it never decreases, since we are rumping up */
2379 if (last_rx_lvl > rx_lvl) {
2380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2381 log2str("Detected Tx power decrease during ramp up: ",
2382 last_rx_lvl , " -> ", rx_lvl));
2383 }
2384
2385 if (rx_lvl == max_rx_lvl and not T.running) {
2386 /* We reached the maximum power, start timer and receive
2387 /* a few more to make sure we don't surpass it */
2388 log("Reached full power, wating a bit more until success");
2389 T.start;
2390 }
2391
2392 last_rx_lvl := rx_lvl;
2393 repeat;
2394 }
2395 [] L1CTL.receive { repeat; }
2396 [] T.timeout { }
2397 }
2398
2399 /* We didn't increase tx power during ramp up */
2400 if (initial_rx_lvl < last_rx_lvl) {
2401 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2402 } else {
2403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2404 log2str("No Tx power increase during whole ramp up: ",
2405 initial_rx_lvl , " -> ", last_rx_lvl));
2406 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002407}
2408
2409/* verify BTS ramps power down to rx_level 0 */
2410private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2411 var L1ctlDlMessage l1_dl;
2412 var integer last_rx_lvl := max_rx_lvl;
2413
2414 timer Tdown := 5.0;
2415 Tdown.start;
2416 alt {
2417 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2418 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2419 log("Received rx_level=", rx_lvl);
2420
2421 /* received Rx level bigger than maximum allowed power by CN */
2422 if (rx_lvl > max_rx_lvl) {
2423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2424 log2str("Detected Tx power higher than full power: ",
2425 rx_lvl , " > ", max_rx_lvl));
2426 }
2427
2428 /* Make sure it never increases, since we are rumping down */
2429 if (last_rx_lvl < rx_lvl) {
2430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2431 log2str("Detected Tx power increase during ramp up: ",
2432 last_rx_lvl , " -> ", rx_lvl));
2433 }
2434
2435 last_rx_lvl := rx_lvl;
2436 if (last_rx_lvl != 0) {
2437 repeat;
2438 }
2439 /* we reached power level 0, we are done */
2440 Tdown.stop;
2441 }
2442 [] L1CTL.receive { repeat; }
2443 [] Tdown.timeout { }
2444 }
2445
2446 /* We didn't increase tx power during ramp down */
2447 if (max_rx_lvl > last_rx_lvl) {
2448 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2449 } else {
2450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2451 log2str("No Tx power decrease during whole ramp down: ",
2452 max_rx_lvl , " -> ", last_rx_lvl));
2453 }
2454}
2455
2456/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002457private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002458 f_l1_tune(L1CTL);
2459 RSL.clear;
2460
2461 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002462
2463 setverdict(pass);
2464}
2465testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2466 var ConnHdlr vc_conn;
2467 var ConnHdlrPars pars;
2468 f_init();
2469 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2470 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2471 pcu_comp := false, trxc_comp := true);
2472 vc_conn.done;
2473 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2474}
2475
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002476/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002477private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002478 f_connhdlr_init_vty_bsc();
2479
2480 f_l1_tune(L1CTL);
2481 RSL.clear;
2482
2483 /* Wait until BTS is started and at full power */
2484 var integer max_rx_lvl := f_wait_ramp_up();
2485 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2486
2487 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2488 f_verify_ramp_down(max_rx_lvl);
2489
2490 setverdict(pass);
2491}
2492testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2493 var ConnHdlr vc_conn;
2494 var ConnHdlrPars pars;
2495 f_init();
2496 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2497 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2498 pcu_comp := false, trxc_comp := true);
2499 vc_conn.done;
2500 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2501}
2502
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002503/* Verify Tx power:
2504 * + ramping down during ADM state UNLOCKED->LOCKED
2505 * + ramping up during ADM state LOCKED->UNLOCKED
2506 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002507private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002508 var L1ctlDlMessage l1_dl;
2509 var integer last_rx_lvl;
2510
2511 f_connhdlr_init_vty_bsc();
2512
2513 f_l1_tune(L1CTL);
2514 RSL.clear;
2515
2516 /* Wait until BTS is started and at full power */
2517 var integer max_rx_lvl := f_wait_ramp_up();
2518 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2519
2520 log("ADM STATE UNLOCKED->LOCKED");
2521 f_vty_enter_cfg_trx(BSCVTY);
2522 f_vty_transceive(BSCVTY, "rf_locked 1");
2523 last_rx_lvl := max_rx_lvl;
2524 f_verify_ramp_down(max_rx_lvl);
2525
2526 /* Let some time after we received 0dBm, then check we don't receive BCCH
2527 * anymore because scheduler has stopped after ramping down */
2528 f_sleep(2.0);
2529 L1CTL.clear;
2530 timer Tlocked := 2.0;
2531 Tlocked.start;
2532 alt {
2533 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2534 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2535 log2str("Received data_ind during rf_locked: ", l1_dl));
2536 }
2537 [] L1CTL.receive { repeat; }
2538 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2539 }
2540
2541 log("ADM STATE LOCKED->UNLOCKED");
2542 f_vty_transceive(BSCVTY, "rf_locked 0");
2543 f_verify_ramp_up();
2544 setverdict(pass);
2545}
2546testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2547 var ConnHdlr vc_conn;
2548 var ConnHdlrPars pars;
2549 f_init();
2550 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2551 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2552 pcu_comp := false, trxc_comp := true);
2553 vc_conn.done;
2554 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2555}
2556
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002557private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002558 timer T := 8.0;
2559 T.start;
2560 var RSL_Message rsl;
2561 alt {
2562 [] as_l1_sacch();
2563 [] L1CTL.receive { repeat; }
2564 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2565 if (rsl.ies[3].body.bs_power.power_level == level) {
2566 setverdict(pass)
2567 } else {
2568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2569 }
2570 }
2571 [] T.timeout {
2572 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2573 }
2574 }
2575}
2576
2577/* see if the rsl meas res contains our expeced bs power level
2578bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002579private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002580 f_l1_tune(L1CTL);
2581 RSL.clear;
2582
2583 if (mp_bts_trxc_port != -1) {
2584 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2585 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2586 }
2587
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002588 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002589 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2590 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2591
2592 f_est_dchan(more_ies :={valueof(pwr)});
2593
2594 f_check_meas_bs_power_level(pwr_var);
2595
2596 f_rsl_chan_deact();
2597 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2598}
2599
2600/* see if the rsl meas res contains our expeced bs power level
2601bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002602private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002603 f_l1_tune(L1CTL);
2604 RSL.clear;
2605
2606 if (mp_bts_trxc_port != -1) {
2607 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2608 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2609 }
2610
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002611 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002612 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2613
2614 f_est_dchan();
2615
2616 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2617
2618 f_check_meas_bs_power_level(pwr_var);
2619
2620 f_rsl_chan_deact();
2621 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2622}
2623
2624testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2625 var ConnHdlr vc_conn;
2626 var ConnHdlrPars pars;
2627 f_init();
2628 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2629 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2630 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2631 pcu_comp := false, trxc_comp := true);
2632 vc_conn.done;
2633 }
2634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2635}
2636
2637testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2638 var ConnHdlr vc_conn;
2639 var ConnHdlrPars pars;
2640 f_init();
2641 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2642 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2643 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2644 pcu_comp := false, trxc_comp := true);
2645 vc_conn.done;
2646 }
2647 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2648}
2649
Eric Wild61edb7e2019-06-03 12:38:31 +02002650/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2651second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2652These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002653private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002654 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002655 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002656
2657 f_trxc_fake_rssi(rxlev2dbm(10));
2658 f_l1_tune(L1CTL);
2659 RSL.clear;
2660
2661 var RSL_IE_List addl_ies;
2662 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2663
2664 addl_ies := {
2665 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2666 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2667 };
2668
2669 /* establish with power parameters */
2670 f_est_dchan(more_ies := addl_ies);
2671
2672 /* set a high value to ensure L1 power control level increases */
2673 f_trxc_fake_rssi(rxlev2dbm(20));
2674
2675 timer T2 := 6.0;
2676 T2.start;
2677 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002678 [] as_l1_sacch_l1h(l1h) {
2679 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002680 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002681 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002682 T2.stop;
2683 }
2684 [] L1CTL.receive { repeat; }
2685 [] T2.timeout {
2686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2687 "Power Level in L1 header has not increased sufficiently");
2688 }
2689 }
2690
2691 /* set a low value to ensure L1 power control level decreases */
2692 f_trxc_fake_rssi(rxlev2dbm(0));
2693
2694 timer T4 := 6.0;
2695 T4.start;
2696 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002697 [] as_l1_sacch_l1h(l1h) {
2698 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002699 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002700 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002701 T4.stop;
2702 setverdict(pass, "Power level in L1 decreased/increased as expected");
2703 }
2704 [] L1CTL.receive { repeat; }
2705 [] T4.timeout {
2706 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2707 "Power Level in L1 header has not decreased sufficiently");
2708 }
2709 }
2710
2711 f_rsl_chan_deact();
2712 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2713
2714}
2715
2716/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002717private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002718 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002719 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002720
2721 /* set a low value to ensure power increases */
2722 f_trxc_fake_rssi(rxlev2dbm(10));
2723 f_l1_tune(L1CTL);
2724 RSL.clear;
2725
2726 var RSL_IE_List addl_ies;
2727 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2728
2729 addl_ies := {
2730 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2731 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2732 };
2733
2734 /* establish with power parameters */
2735 f_est_dchan(more_ies := addl_ies);
2736
2737 timer T1 := 10.0;
2738 T1.start;
2739 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002740 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002741 [] L1CTL.receive { repeat; }
2742 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002743 if (not isbound(l1h)) {
2744 setverdict(fail, "No SACCH blocks were received");
2745 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002746 setverdict(fail, "Power level in L1 header should not have changed");
2747 }
2748 }
2749 }
2750
2751 f_rsl_chan_deact();
2752 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2753
2754}
2755
2756/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002757private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002758 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002759 var uint5_t pwr_var := 15;
2760 var uint5_t pwr_max_var := f_get_max_power_from_band();
2761
2762 /* set a low value to ensure power increases */
2763 f_trxc_fake_rssi(rxlev2dbm(10));
2764 f_l1_tune(L1CTL);
2765 RSL.clear;
2766
2767 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2768 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2769
2770 /* establish with fixed power level */
2771 f_est_dchan(more_ies :={valueof(pwr)});
2772
2773 /* check our initial power level */
2774 f_wait_for_l1_power_level(pwr_var);
2775
2776 /* update power param to enable power loop
2777 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2778 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2779
2780 /* wait, then check that our power level was reduced */
2781 timer T1 := 10.0;
2782 T1.start;
2783 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002784 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002785 [] L1CTL.receive { repeat; }
2786 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002787 if (not isbound(l1h)) {
2788 setverdict(fail, "No SACCH blocks were received");
2789 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002790 setverdict(pass, "Power level in L1 header reduced as expected");
2791 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002792 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
2793 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02002794 }
2795 }
2796 }
2797
2798 f_rsl_chan_deact();
2799 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2800
2801}
2802
2803/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002804private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002805 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002806
2807 /* set a high value to ensure power decreases */
2808 f_trxc_fake_rssi(rxlev2dbm(50));
2809 f_l1_tune(L1CTL);
2810 RSL.clear;
2811
2812 var uint5_t pwr_var := 5;
2813 var uint5_t pwr_target_val := 15;
2814
2815 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2816 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2817
2818 /* establish with fixed power level */
2819 f_est_dchan(more_ies :={valueof(pwr)});
2820
2821 /* check our initial power level */
2822 f_wait_for_l1_power_level(pwr_var);
2823
2824 /* update power param to enable power loop
2825 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002826 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002827
2828 /* wait, then check that our power level was increased */
2829 timer T1 := 10.0;
2830 T1.start;
2831 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002832 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002833 [] L1CTL.receive { repeat; }
2834 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002835 if (not isbound(l1h)) {
2836 setverdict(fail, "No SACCH blocks were received");
2837 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
2838 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002839 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002840 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002841 }
2842 }
2843 }
2844
2845 f_rsl_chan_deact();
2846 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2847
2848}
2849
Eric Wild095024b2019-06-17 15:08:57 +02002850/* see if we change the power level without receiving power parameters, which should not happen
2851rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002852private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002853 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02002854
2855 /* set a high value to ensure power decreases */
2856 f_trxc_fake_rssi(rxlev2dbm(50));
2857 f_l1_tune(L1CTL);
2858 RSL.clear;
2859
2860 var uint5_t pwr_var := 5;
2861
2862 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2863 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2864
2865 /* establish with fixed power level */
2866 f_est_dchan(more_ies :={valueof(pwr)});
2867
2868 /* check our initial power level */
2869 f_wait_for_l1_power_level(pwr_var);
2870
2871 /* wait, then check that our power level did not change */
2872 timer T1 := 10.0;
2873 T1.start;
2874 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002875 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2876 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02002877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2878 "BS power control should not be active unless we receive a power parameters IE!");
2879 }
2880 repeat;
2881 }
2882 [] L1CTL.receive { repeat; }
2883 [] T1.timeout { setverdict(pass); }
2884 }
2885
2886 f_rsl_chan_deact();
2887 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2888
2889}
2890
Eric Wild095024b2019-06-17 15:08:57 +02002891/* see if we change the power level without receiving power parameters, which should not happen
2892ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002893private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002894 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02002895
2896 /* set a high value to ensure power decreases */
2897 f_trxc_fake_rssi(rxlev2dbm(50));
2898 f_l1_tune(L1CTL);
2899 RSL.clear;
2900
2901 var uint5_t pwr_var := 5;
2902
2903 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2904 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2905
2906 /* establish with fixed power level */
2907 f_est_dchan(more_ies :={valueof(pwr)});
2908
2909 /* check our initial power level */
2910 f_wait_for_l1_power_level(pwr_var);
2911
2912 /* pwr control without power params IE, should NOT activate MS power control*/
2913 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2914
2915 /* wait, then check that our power level did not change */
2916 timer T1 := 10.0;
2917 T1.start;
2918 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002919 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2920 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02002921 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2922 "BS power control should not be active unless we receive a power parameters IE!");
2923 }
2924 repeat;
2925 }
2926 [] L1CTL.receive { repeat; }
2927 [] T1.timeout { setverdict(pass); }
2928 }
2929
2930 f_rsl_chan_deact();
2931 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2932
2933}
2934
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002935private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002936 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002937 timer T0 := 10.0;
2938 T0.start;
2939 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002940 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2941 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002942 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2943 "Power level in L1 header != signaled (RSL) power level.");
2944 }
2945 }
2946 [] L1CTL.receive { repeat; }
2947 [] T0.timeout {
2948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2949 "Timeout waiting for initial power level");
2950 }
2951 }
2952 T0.stop;
2953}
2954
2955private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2956 var IntegerRecord min_dbm_level;
2957 var IntegerRecord max_dbm_level;
2958 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2959
2960 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2961 if (min_dbm_level[i] == level) {
2962 return true;
2963 }
2964 }
2965 return false;
2966}
2967
2968private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2969 var IntegerRecord min_dbm_level;
2970 var IntegerRecord max_dbm_level;
2971 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2972
2973 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2974 if (max_dbm_level[i] == level) {
2975 return true;
2976 }
2977 }
2978 return false;
2979}
2980
2981private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2982 var IntegerRecord min_dbm_level;
2983 var IntegerRecord max_dbm_level;
2984 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2985 return max_dbm_level[0];
2986}
2987
2988type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002989private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002990private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2991 // 45.005 4.1.1
2992 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2993 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2994 2, 1, 0};
2995 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2996 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2997 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2998 var IntegerRecord rv;
2999
3000 select(band){
3001 case (BtsBand_allGSM){
3002 rv := gsm_power;
3003 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
3004 max_dbm_level := {2, 1, 0};
3005 }
3006 case("DCS1800"){
3007 rv := dcs_power;
3008 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
3009 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
3010 }
3011 case("PCS1900"){
3012 rv := pcs_power;
3013 min_dbm_level := {15};
3014 max_dbm_level := {30};
3015 }
Harald Welte194b6912020-10-11 21:01:55 +02003016 case else {
3017 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3018 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003019 }
3020
3021 return rv;
3022}
3023
3024private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003025 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 +02003026}
3027
3028testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3029 var ConnHdlr vc_conn;
3030 var ConnHdlrPars pars;
3031 f_init();
3032 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3033 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3034 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3035 pars.bts0_band := f_vty_get_bts0_band();
3036 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3037 vc_conn.done;
3038 }
3039 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3040 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3041}
3042
3043testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3044 var ConnHdlr vc_conn;
3045 var ConnHdlrPars pars;
3046 f_init();
3047 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3048 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3049 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3050 pars.bts0_band := f_vty_get_bts0_band();
3051 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3052 vc_conn.done;
3053 }
3054 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3056}
3057
3058testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3059 var ConnHdlr vc_conn;
3060 var ConnHdlrPars pars;
3061 f_init();
3062 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3063 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3064 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3065 pars.bts0_band := f_vty_get_bts0_band();
3066 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3067 vc_conn.done;
3068 }
3069 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3071}
3072
3073testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3074 var ConnHdlr vc_conn;
3075 var ConnHdlrPars pars;
3076 f_init();
3077 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3078 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3079 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3080 pars.bts0_band := f_vty_get_bts0_band();
3081 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3082 vc_conn.done;
3083 }
3084 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3085 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3086}
3087
Eric Wild280ccb82019-06-17 11:11:52 +02003088testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3089 var ConnHdlr vc_conn;
3090 var ConnHdlrPars pars;
3091 f_init();
3092 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3093 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3094 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3095 pars.bts0_band := f_vty_get_bts0_band();
3096 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3097 vc_conn.done;
3098 }
3099 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3101}
3102
Eric Wild095024b2019-06-17 15:08:57 +02003103testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3104 var ConnHdlr vc_conn;
3105 var ConnHdlrPars pars;
3106 f_init();
3107 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3108 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3109 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3110 pars.bts0_band := f_vty_get_bts0_band();
3111 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3112 vc_conn.done;
3113 }
3114 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3116}
3117
Philipp Maier149c3922020-10-22 17:29:36 +02003118function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003119 var template RSL_IE_ChannelMode ch_mode;
3120 var ConnHdlr vc_conn;
3121 var ConnHdlrPars pars;
3122 f_init();
3123 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3124 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3125 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003126 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003127 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3128 pcu_comp := false, trxc_comp := true);
3129 vc_conn.done;
3130 }
3131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3132}
Philipp Maier149c3922020-10-22 17:29:36 +02003133
3134testcase TC_meas_res_speech_tchf() runs on test_CT {
3135 f_TC_meas_res_speech_tchf(false);
3136}
3137
3138testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3139 f_TC_meas_res_speech_tchf(true);
3140}
3141
3142function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003143 var template RSL_IE_ChannelMode ch_mode;
3144 var ConnHdlr vc_conn;
3145 var ConnHdlrPars pars;
3146 f_init();
3147 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3148 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3149 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003150 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003151 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3152 pcu_comp := false, trxc_comp := true);
3153 vc_conn.done;
3154 }
3155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3156}
Philipp Maier149c3922020-10-22 17:29:36 +02003157
3158testcase TC_meas_res_speech_tchh() runs on test_CT {
3159 f_TC_meas_res_speech_tchh(false)
3160}
3161
3162testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3163 f_TC_meas_res_speech_tchh(true)
3164}
3165
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003166testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3167 var template RSL_IE_ChannelMode ch_mode;
3168 var ConnHdlr vc_conn;
3169 var ConnHdlrPars pars;
3170 f_init();
3171 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3172 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3173 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3174 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3175 pars.l1_pars.toa256_enabled := true;
3176 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3177 pcu_comp := false, trxc_comp := true);
3178 vc_conn.done;
3179 }
3180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3181}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003182
Harald Welte70767382018-02-21 12:16:40 +01003183testcase TC_meas_res_sign_tchf() 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 tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003188 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003189 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_tchh() 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 <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003200 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
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_sdcch4() 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 <= 3; ss := ss+1) {
3212 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, 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}
3219testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3220 var ConnHdlr vc_conn;
3221 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003222 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003223 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3224 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003225 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3226 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003227 vc_conn.done;
3228 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003229 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003230}
Harald Welte685d5982018-02-27 20:42:05 +01003231testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3232 var ConnHdlr vc_conn;
3233 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003234 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003235 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3236 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003237 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003238 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003239 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3240 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003241 vc_conn.done;
3242 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003243 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003244}
3245
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003246/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3247 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003248private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003249 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003250 var RSL_IE_MS_Power ms_power;
3251 var RSL_Message rsl;
3252 var uint5_t power_level := 0;
3253
3254 f_l1_tune(L1CTL);
3255 RSL.clear;
3256
3257 f_est_dchan();
3258
3259 ms_power.reserved := 0;
3260 ms_power.fpc_epc := false;
3261
3262 /* Send the first power control command. This will disable any BTS/TRX
3263 * internal power control and switch the MS (which is not in scope of
3264 * this test) to a constant power level. We start with a power level
3265 * of 0 */
3266 ms_power.power_level := power_level;
3267 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3268 RSL.send(rsl);
3269
3270 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003271 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3272 if (l1h.ms_power_lvl != power_level) {
3273 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3274 "match the signaled (RSL) power level := ", power_level);
3275 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003276 }
3277
3278 /* Signal a new power level via RSL for the next turn. */
3279 if (power_level < 31) {
3280 power_level := power_level + 1;
3281 ms_power.power_level := power_level;
3282 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3283 RSL.send(rsl);
3284 repeat;
3285 }
3286
3287 }
3288
3289 /* Ignore all other blocks */
3290 [] L1CTL.receive { repeat; }
3291
3292 }
3293
3294 f_rsl_chan_deact();
3295 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3296
3297 setverdict(pass);
3298}
3299
3300testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3301 var ConnHdlr vc_conn;
3302 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003303 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003304
3305 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3306 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3307 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3308 vc_conn.done;
3309 }
3310 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3311}
Harald Welte70767382018-02-21 12:16:40 +01003312
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003313/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003314TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003315private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003316 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003317 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003318
3319 f_l1_tune(L1CTL);
3320 RSL.clear;
3321
3322 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003323 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003324
3325 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3326
3327
3328 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003329 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3330 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003331 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3332 }
3333
3334 }
3335
3336 /* Ignore all other blocks */
3337 [] L1CTL.receive { repeat; }
3338
3339 }
3340
3341 f_rsl_chan_deact();
3342 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3343
3344 setverdict(pass);
3345}
3346
3347testcase TC_rsl_chan_initial_ta() runs on test_CT {
3348 var ConnHdlr vc_conn;
3349 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003350 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003351 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003352 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3353 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003354 vc_conn.done;
3355 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3356}
3357
Eric Wilde57e1a62019-05-28 13:30:55 +02003358/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003359private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003360 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003361 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003362
3363 var RSL_IE_MS_Power ms_power;
3364 ms_power.reserved := 0;
3365 ms_power.fpc_epc := false;
3366 ms_power.power_level := ms_power_level;
3367
3368 f_l1_tune(L1CTL);
3369 RSL.clear;
3370
3371 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3372
3373 timer T := 1.0;
3374 T.start;
3375 alt {
3376 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003377 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3378 if (l1h.ms_power_lvl != ms_power_level) {
3379 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3380 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003381 }
3382 }
3383 /* Ignore all other blocks */
3384 [] L1CTL.receive { repeat; }
3385 [] T.timeout {
3386 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3387 }
3388 }
3389
3390 f_rsl_chan_deact();
3391 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3392 setverdict(pass);
3393}
3394
3395testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3396 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3397 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3398}
3399
Harald Welte0472ab42018-03-12 15:02:26 +01003400/* 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 +01003401private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003402 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003403 RSL.clear;
3404
3405 f_est_dchan();
3406 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003407 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003408
3409 timer T := 40.0;
3410 T.start;
3411 alt {
3412 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3413 setverdict(pass)
3414 }
3415 [] RSL.receive { repeat };
3416 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003418 }
3419 }
3420 f_rsl_chan_deact();
3421}
3422testcase TC_conn_fail_crit() runs on test_CT {
3423 var ConnHdlr vc_conn;
3424 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003425 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003426 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3427 pars.t_guard := 60.0;
3428 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3429 vc_conn.done;
3430}
3431
Harald Welte93640c62018-02-25 16:59:33 +01003432/***********************************************************************
3433 * Paging
3434 ***********************************************************************/
3435
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003436private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003437 if (tmsi == 'FFFFFFFF'O) {
3438 return true;
3439 } else {
3440 return false;
3441 }
3442}
Harald Welte70767382018-02-21 12:16:40 +01003443
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003444private type record allowedFn { integer frame_nr }
3445private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3446private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3447private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3448private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3449private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3450private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3451private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3452private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3453private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003454{
3455 var integer frame_nr_51;
3456 frame_nr_51 := frame_nr mod 51
3457
3458 var allowedFn fn_check;
3459 fn_check.frame_nr := frame_nr_51;
3460
3461 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003462 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003463 return;
3464 }
3465
3466 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3467 return;
3468 }
3469 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3470 return;
3471 }
3472 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3473 return;
3474 }
3475 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3476 return;
3477 }
3478 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3479 return;
3480 }
3481 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3482 return;
3483 }
3484 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3485 return;
3486 }
3487 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3488 return;
3489 }
3490
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003492 return;
3493}
3494
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003495private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3496 inout integer num_paging_rcv_ids,
3497 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003498runs on test_CT {
3499 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003500 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003501 repeat;
3502 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003503 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003504 var octetstring without_plen :=
3505 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3506 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003507
3508 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3509
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003510 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3511 /* Ignore empty RR Paging Request (PCH filling) messages.
3512 * TODO: does it make sense to count them? */
3513 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003514 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3515 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003516 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003517 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3518 }
3519 } else if (match(rr, tr_PAGING_REQ2)) {
3520 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3521 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3522 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3523 }
3524 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3525 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3526 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003527 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003528 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3529 }
3530 } else if (match(rr, tr_PAGING_REQ3)) {
3531 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3532 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3533 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3534 }
3535 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3536 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3537 }
3538 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3539 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3540 }
3541 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3542 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3543 }
3544 }
3545 repeat;
3546 }
3547}
3548
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003549private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003550 boolean combined_ccch,
3551 integer bs_ag_blks_res,
3552 float load_factor,
3553 boolean exp_load_ind,
3554 boolean exp_overload,
3555 boolean use_tmsi
3556}
3557
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003558private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003559 integer num_paging_sent,
3560 integer num_paging_rcv_msgs,
3561 integer num_paging_rcv_ids,
3562 integer num_overload
3563}
3564
Harald Welte68e495b2018-02-25 00:05:57 +01003565/* Helper function for paging related testing */
3566private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003567 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003568 f_init_l1ctl();
3569 f_l1_tune(L1CTL);
3570
3571 var PagingTestState st := {
3572 num_paging_sent := 0,
3573 num_paging_rcv_msgs := 0,
3574 num_paging_rcv_ids := 0,
3575 num_overload := 0
3576 };
3577
3578 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3579 var float max_pch_imsi_per_sec;
3580 if (cfg.use_tmsi) {
3581 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3582 } else {
3583 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3584 }
3585 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3586 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003587 var float time_total := 20.0;
3588 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3589 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003590
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003591 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3592 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003593
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003594 timer T_itv := 0.0;
3595 T_itv.start;
3596 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003597 alt {
3598 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003599 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003600 st.num_overload := st.num_overload + 1;
3601 repeat;
3602 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003603 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003604 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003605 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003606 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003607 log("Rx LOAD_IND");
3608 /* FIXME: analyze/verify interval + contents */
3609 repeat;
3610 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003611 /* ignore other RSL messages like RF RESource INDication */
3612 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003613 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003614 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003615 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003616 [] T_itv.timeout {
3617 /* Send paging cmds based on elapsed time */
3618 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3619 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003620 var MobileIdentityV mi;
3621
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003622 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003623 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003624 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003625 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003626 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003627 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003628
3629 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003630 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 +02003631
3632 st.num_paging_sent := st.num_paging_sent + 1;
3633 }
3634 if (st.num_paging_sent < pkt_total) {
3635 /* Wait for interval to next PAGING COMMAND */
3636 var float time_now := T_total.read;
3637 var float next_sched := int2float(st.num_paging_sent)*interval;
3638 if (next_sched > time_now) {
3639 T_itv.start(next_sched - time_now);
3640 } else {
3641 T_itv.start(0.0);
3642 }
3643 } else {
3644 /* We are done, no need to keep counting */
3645 T_total.stop;
3646 }
3647 }
3648 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003649 }
3650 }
3651
3652 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3653 timer T_wait := 18.0;
3654 T_wait.start;
3655 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003656 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003657 [] L1CTL.receive { repeat; }
3658 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003659 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3660 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003661 /* ignore other RSL messages like RF RESource INDication */
3662 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003663 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003664 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003665 }
Harald Welte68e495b2018-02-25 00:05:57 +01003666 }
3667
3668 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3669 " rcvd_ids=", st.num_paging_rcv_ids);
3670 return st;
3671}
3672
3673/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3674 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3675 * - that CCCH LOAD IND (PCH) are being generated
3676 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3677testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003678 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003679 var PagingTestCfg cfg := {
3680 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003681 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003682 load_factor := 0.8,
3683 exp_load_ind := true,
3684 exp_overload := false,
3685 use_tmsi := false
3686 };
3687 var PagingTestState st := f_TC_paging(cfg);
3688 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3690 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003691 } else {
3692 setverdict(pass);
3693 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003694 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003695}
3696
3697/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3698 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3699 * - that CCCH LOAD IND (PCH) are being generated
3700 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3701testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003702 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003703 var PagingTestCfg cfg := {
3704 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003705 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003706 load_factor := 0.8,
3707 exp_load_ind := true,
3708 exp_overload := false,
3709 use_tmsi := true
3710 };
3711 var PagingTestState st := f_TC_paging(cfg);
3712 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003713 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3714 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003715 } else {
3716 setverdict(pass);
3717 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003719}
3720
3721/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3722 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3723 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3724 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3725testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003726 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003727 var PagingTestCfg cfg := {
3728 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003729 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003730 load_factor := 2.0,
3731 exp_load_ind := true,
3732 exp_overload := true,
3733 use_tmsi := false
3734 };
3735 var PagingTestState st := f_TC_paging(cfg);
3736 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3737 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003738 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003739 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003740 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 +01003741 } else {
3742 setverdict(pass);
3743 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003745}
3746
3747/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3748 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3749 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3750 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3751testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003752 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003753 var PagingTestCfg cfg := {
3754 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003755 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003756 load_factor := 2.0,
3757 exp_load_ind := true,
3758 exp_overload := true,
3759 use_tmsi := true
3760 };
3761 var PagingTestState st := f_TC_paging(cfg);
3762 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3763 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003764 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003765 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003766 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 +01003767 } else {
3768 setverdict(pass);
3769 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003771}
3772
3773
Harald Welte93640c62018-02-25 16:59:33 +01003774/***********************************************************************
3775 * Immediate Assignment / AGCH
3776 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003777private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003778 len := 0,
3779 ma := ''B
3780}
Harald Welte93640c62018-02-25 16:59:33 +01003781
Harald Weltee8d750e2018-06-10 21:41:35 +02003782private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3783 return int2str(num_tx) & " sent, "
3784 & int2str(num_rx) & " received, "
3785 & int2str(num_del) & " deleted";
3786}
3787
3788private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3789 var L1ctlDlMessage l1_dl;
3790 timer T := 10.0;
3791 var integer num_tx := 0;
3792 var integer num_rx := 0;
3793 var integer num_del := 0;
3794 var charstring res_str;
3795 var float rx_ratio;
3796
Harald Welte10474062019-05-30 16:48:17 +02003797 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003798 f_init_l1ctl();
3799 f_l1_tune(L1CTL);
3800
3801 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07003802 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07003803 mp_trx_pars[0].arfcn,
3804 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02003805 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3806 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003807 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003808 num_tx := num_tx+1;
3809 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003810 }
3811 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003812 T.start;
3813 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003814 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003815 num_del := num_del+1;
3816 repeat;
3817 }
3818 [] RSL_CCHAN.receive {
3819 repeat;
3820 }
3821 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003822 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3823 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3824 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003825 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003826 } else {
3827 num_rx := num_rx+1;
3828 }
3829 repeat;
3830 }
3831 [] L1CTL.receive { repeat; }
3832 [] T.timeout { }
3833 }
3834 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3835 log("AGCH test: " & res_str);
3836 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003837 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003838 }
3839 rx_ratio := int2float(num_rx) / int2float(num_tx);
3840 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003841 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 +02003842 } else {
3843 setverdict(pass);
3844 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003846}
3847
Harald Weltee8d750e2018-06-10 21:41:35 +02003848/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3849testcase TC_imm_ass_1000_20ms() runs on test_CT {
3850 f_TC_imm_ass(1000, 0.02, 0.25);
3851}
3852
3853/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3854testcase TC_imm_ass_200_0ms() runs on test_CT {
3855 f_TC_imm_ass(200, 0.0, 0.05);
3856}
3857
3858/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3859testcase TC_imm_ass_200_76ms() runs on test_CT {
3860 f_TC_imm_ass(150, 0.076, 1.00);
3861}
3862
3863
3864
Harald Welte48494ca2018-02-25 16:59:50 +01003865/***********************************************************************
3866 * BCCH
3867 ***********************************************************************/
3868
3869/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003870private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003871 GsmFrameNumber frame_number,
3872 SystemInformation si
3873}
3874
3875/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003876private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003877
3878/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003879private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003880
3881/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003882private function f_si_vecslot_contains(SystemInformationVector arr,
3883 RrMessageType key,
3884 boolean bcch_ext := false)
3885return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003886 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3887 var integer fn_mod51 := arr[i].frame_number mod 51;
3888 if (not bcch_ext and fn_mod51 == 2 or
3889 bcch_ext and fn_mod51 == 6) {
3890 if (arr[i].si.header.message_type == key) {
3891 return true;
3892 }
3893 }
3894 }
3895 return false;
3896}
3897
3898/* 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 +07003899private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3900 integer tc, RrMessageType key,
3901 boolean ext_bcch := false)
3902{
Harald Welte48494ca2018-02-25 16:59:50 +01003903 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003904 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003905 }
3906}
3907
3908/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003909private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3910 RrMessageType key)
3911return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003912 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3913 if (f_si_vecslot_contains(arr[tc], key) or
3914 f_si_vecslot_contains(arr[tc], key, true)) {
3915 return true;
3916 }
3917 }
3918 return false;
3919}
3920
3921/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003922private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3923 RrMessageType key,
3924 boolean bcch_ext := false,
3925 integer n := 1, integer m := 4)
3926return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003927 var integer count := 0;
3928 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3930 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003931 }
3932 for (var integer i:= 0; i < m; i := i + 1) {
3933 var integer fn_mod51 := arr[i].frame_number mod 51;
3934 if (not bcch_ext and fn_mod51 == 2 or
3935 bcch_ext and fn_mod51 == 6) {
3936 if (arr[i].si.header.message_type == key) {
3937 count := count + 1;
3938 }
3939 }
3940 }
3941 if (count >= n) {
3942 return true;
3943 } else {
3944 return false;
3945 }
3946}
3947
3948/* 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 +07003949private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3950 integer tc, RrMessageType key,
3951 boolean ext_bcch := false,
3952 integer n, integer m)
3953{
Harald Welte48494ca2018-02-25 16:59:50 +01003954 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003955 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003956 }
3957}
3958
3959/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003960private function f_si_vecslot_contains_only(SystemInformationVector arr,
3961 RrMessageType key,
3962 boolean bcch_ext := false)
3963return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003964 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3965 var integer fn_mod51 := arr[i].frame_number mod 51;
3966 if (not bcch_ext and fn_mod51 == 2 or
3967 bcch_ext and fn_mod51 == 6) {
3968 if (arr[i].si.header.message_type != key) {
3969 return false;
3970 }
3971 }
3972 }
3973 return true;
3974}
3975
3976/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003977private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3978 integer tc, RrMessageType key,
3979 boolean ext_bcch := false)
3980{
Harald Welte48494ca2018-02-25 16:59:50 +01003981 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003983 }
3984}
3985
3986/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003987private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003988 boolean bcch_extended,
3989 boolean si1_present,
3990 boolean si2bis_present,
3991 boolean si2ter_present,
3992 boolean si2quater_present,
3993 boolean si7_present,
3994 boolean si8_present,
3995 boolean si9_present,
3996 boolean si13_present,
3997 boolean si13alt_present,
3998 boolean si15_present,
3999 boolean si16_present,
4000 boolean si17_present,
4001 boolean si2n_present,
4002 boolean si21_present,
4003 boolean si22_present
4004}
4005
4006/* 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 +07004007private function f_validate_si_scheduling(SystemInformationConfig cfg,
4008 SystemInformationVectorPerTc si_per_tc)
4009{
Harald Welte48494ca2018-02-25 16:59:50 +01004010 var integer i;
4011 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4012 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004014 }
4015 }
4016 if (cfg.si1_present) {
4017 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4018 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4019 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4020 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4021 /* make sure *ALL* contain SI1 */
4022 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4023 }
4024 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4025 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4026 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4027 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4028 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4029 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4030
4031 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4032 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4033 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4034 * consecutive occurrences of TC = 4. */
4035 if (cfg.si2bis_present and not cfg.si2ter_present) {
4036 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4037 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4038 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4039 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4040 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4041 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4042 }
4043
4044 if (cfg.si7_present or cfg.si8_present) {
4045 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4046 * if System Information type 4 does not contain all information needed for cell
4047 * selection and reselection. */
4048 if (not cfg.bcch_extended) {
4049 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4050 }
4051 if (cfg.si7_present) {
4052 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4053 }
4054 if (cfg.si8_present) {
4055 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4056 }
4057 }
4058
4059 if (cfg.si2quater_present) {
4060 /* iii) System information type 2 quater is sent if needed, as determined by the system
4061 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4062 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4063 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4064 * within any of 4 consecutive occurrences of TC = 5. */
4065 if (not (cfg.bcch_extended)) {
4066 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4067 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4068 } else {
4069 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4070 }
4071 } else {
4072 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4073 }
4074 }
4075 if (cfg.si9_present) {
4076 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4077 * in system information type 3 as defined in 3GPP TS 44.018. */
4078 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4079 }
4080 if (cfg.si13_present) {
4081 /* vii) System Information type 13 is only related to the GPRS service. System Information
4082 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4083 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4084 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4085 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4086 * within any of 4 consecutive occurrences of TC=4. */
4087 if (not cfg.bcch_extended) {
4088 log("not-bccch-extended");
4089 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4090 } else {
4091 log("bccch-extended");
4092 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4093 }
4094 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004095 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004096 }
4097 }
4098 if (cfg.si16_present or cfg.si17_present) {
4099 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4100 * should not be sent in a cell where network sharing is used (see rule xv). */
4101 if (cfg.si22_present) {
4102 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4103 }
4104 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004105 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004106 }
4107 if (not cfg.bcch_extended) {
4108 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4109 }
4110 if (cfg.si16_present) {
4111 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4112 }
4113 if (cfg.si17_present) {
4114 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4115 }
4116 }
4117
4118 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4119 * broadcast information. The frequency with which they are sent is determined by the
4120 * system operator. System Information type 9 identifies the scheduling of System
4121 * Information type 18 and 20 messages. */
4122
4123 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4124 * Information Type 19 is present, then its scheduling shall be indicated in System
4125 * Information Type 9. */
4126
4127 if (cfg.si15_present) {
4128 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4129 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4130 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4131 * 4 consecutive occurrences of TC = 1. */
4132 if (not cfg.bcch_extended) {
4133 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4134 } else {
4135 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4136 }
4137 }
4138 if (cfg.si13alt_present) {
4139 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4140 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4141 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4142 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4143 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4144 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4145 * of TC = 4. */
4146 if (cfg.si13_present) {
4147 testcase.stop("Error: Cannot have SI13alt and SI13");
4148 }
4149 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004150 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004151 }
4152 if (not cfg.bcch_extended) {
4153 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4154 } else {
4155 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4156 }
4157 }
4158 if (cfg.si2n_present) {
4159 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4160 * as determined by the system operator. In the case that the message is sent on the
4161 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4162 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4163 * consecutive occurrences of TC = 4. */
4164 if (not cfg.bcch_extended) {
4165 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4166 } else {
4167 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4168 }
4169 }
4170 if (cfg.si21_present) {
4171 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4172 * determined by the system operator. If Extended Access Barring is in use in the cell
4173 * then this message is sent at least once within any of 4 consecutive occurrences of
4174 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4175 * cell then this message shall only be sent on BCCH Ext. */
4176 if (not cfg.bcch_extended) {
4177 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4178 } else {
4179 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4180 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004182 }
4183 }
4184 }
4185 if (cfg.si22_present) {
4186 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4187 * should not be sent in a cell where SoLSA is used (see rule viii). System
4188 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4189 * =2 and TC=6. */
4190 if (cfg.si16_present or cfg.si17_present) {
4191 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4192 }
4193 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4194 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004195 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004196 }
4197 if (not cfg.bcch_extended) {
4198 testcase.stop("Error: SI22 requires BCCH Extd!");
4199 } else {
4200 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4201 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4202 }
4203 }
4204}
4205
4206/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004207private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4208return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004209 timer T := duration;
4210 var SystemInformationVectorPerTc si_per_tc;
4211 var L1ctlDlMessage l1_dl;
4212
4213 /* initialize all per-TC vectors empty */
4214 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4215 si_per_tc[i] := {};
4216 }
4217
4218 /* flush all previous L1 queued msgs */
4219 pt.clear;
4220
4221 T.start;
4222 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004223 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004224 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4225 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4226 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004227 repeat;
4228 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004229
Harald Welte48494ca2018-02-25 16:59:50 +01004230 var integer tc := f_gsm_compute_tc(sig.frame_number);
4231 log("SI received at TC=", tc, ": ", sig.si);
4232 /* append to the per-TC bucket */
4233 si_per_tc[tc] := si_per_tc[tc] & { sig };
4234 repeat;
4235 }
4236 [] pt.receive { repeat; }
4237 [] T.timeout { }
4238 }
4239
4240 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4241 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4242 }
4243 log("si_per_tc=", si_per_tc);
4244 return si_per_tc;
4245}
4246
4247/* helper function: Set given SI via RSL + validate scheduling.
4248 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004249private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004250 var SystemInformationVectorPerTc si_per_tc;
4251 f_init_l1ctl();
4252 f_l1_tune(L1CTL);
4253
4254 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004255 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004256 f_validate_si_scheduling(si_cfg, si_per_tc);
4257
4258 setverdict(pass);
4259}
4260
4261testcase TC_si_sched_default() runs on test_CT {
4262 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004263 /* 2+3+4 are mandatory and set in f_init() */
4264 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004265 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004266}
4267
4268testcase TC_si_sched_1() runs on test_CT {
4269 f_init();
4270 si_cfg.si1_present := true;
4271 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004272 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_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 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004282}
4283
4284testcase TC_si_sched_2ter() runs on test_CT {
4285 f_init();
4286 si_cfg.si2ter_present := true;
4287 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4288 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004289 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004290}
4291
4292testcase TC_si_sched_2ter_2bis() runs on test_CT {
4293 f_init();
4294 si_cfg.si2bis_present := true;
4295 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4296 si_cfg.si2ter_present := true;
4297 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4298 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004300}
4301
4302testcase TC_si_sched_2quater() runs on test_CT {
4303 f_init();
4304 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004305 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004306 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004307 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004308}
4309
4310testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004311 /* NOTE: PCUIF connection is not used in this test case, but
4312 * without it the IUT would not broadcast SI13 (see OS#3075). */
4313 f_init_with_pcuif();
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 Welte48494ca2018-02-25 16:59:50 +01004316 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004318}
4319
4320testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004321 /* NOTE: PCUIF connection is not used in this test case, but
4322 * without it the IUT would not broadcast SI13 (see OS#3075). */
4323 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004324 si_cfg.si2bis_present := true;
4325 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4326 si_cfg.si2ter_present := true;
4327 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4328 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004329 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004330 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004331 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004332 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004334}
4335
4336
Harald Welte68e495b2018-02-25 00:05:57 +01004337testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004338 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004339 /* FIXME: enable / disable individual BCCH info */
4340 //ts_RSL_BCCH_INFO(si_type, info);
4341 /* expect no ERROR REPORT after either of them *
4342 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004344}
4345
Harald Welte93640c62018-02-25 16:59:33 +01004346/***********************************************************************
4347 * Low-Level Protocol Errors / ERROR REPORT
4348 ***********************************************************************/
4349
Harald Welte01d982c2018-02-25 01:31:40 +01004350private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4351 timer T := 5.0;
4352 T.start;
4353 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004354 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004355 setverdict(pass);
4356 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004357 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004358 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004359 }
4360 [] RSL_CCHAN.receive {
4361 repeat;
4362 }
4363 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004365 }
4366 }
4367}
4368
4369/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4370testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004371 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004372 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4373 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004374 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004375
4376 f_exp_err_rep(RSL_ERR_PROTO);
4377}
4378
4379/* Provoke a mandatory IE error and match on ERROR REPORT */
4380testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004381 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004382
4383 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4384 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004385 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004386
4387 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4388}
4389
4390/* Provoke an IE content error and match on ERROR REPORT */
4391testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004392 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004393 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4394 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004395 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004396
4397 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4398}
4399
Harald Welteee25aae2019-05-19 14:32:37 +02004400/* attempt to activate channel with wrong RSL Message Discriminator IE */
4401function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4402 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4403 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4404 RSL.send(rsl);
4405 f_rslem_unregister(0, g_chan_nr);
4406}
4407testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4408 var ConnHdlr vc_conn;
4409 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4410
Harald Welte10474062019-05-30 16:48:17 +02004411 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004412
4413 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4414 vc_conn.done;
4415 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4416
4417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4418}
4419
4420/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004421private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004422 var template (value) RSL_Message rsl_tx;
4423 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4424 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4425 RSL.send(rsl_tx);
4426 f_rslem_unregister(0, g_chan_nr);
4427}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004428private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004429 var template (value) RSL_Message rsl_tx;
4430 /* we first have to activate the dedicated channel */
4431 f_rsl_chan_act(g_pars.chan_mode);
4432 /* ... to then send an invalid RLL message */
4433 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4434 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4435 RSL.send(rsl_tx);
4436 f_rslem_unregister(0, g_chan_nr);
4437}
4438testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4439 var ConnHdlr vc_conn;
4440 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4441 var template (value) RSL_Message rsl_tx;
4442
Harald Welte10474062019-05-30 16:48:17 +02004443 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004444
4445 /* Common Channel with wrong message type */
4446 RSL_CCHAN.clear;
4447 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4448 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004449 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004450 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4451
4452 /* TRX Management */
4453 RSL_CCHAN.clear;
4454 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4455 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004456 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004457 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4458
4459 /* Dedicated Channel */
4460 RSL_CCHAN.clear;
4461 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4462 vc_conn.done;
4463 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4464
4465 /* RLL */
4466 RSL_CCHAN.clear;
4467 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4468 vc_conn.done;
4469 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4470}
4471
4472/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004473private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004474 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4475 f_rslem_unregister(0, g_chan_nr);
4476}
4477testcase TC_err_rep_wrong_sequence() runs on test_CT {
4478 var ConnHdlr vc_conn;
4479 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4480
Harald Welte10474062019-05-30 16:48:17 +02004481 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004482
4483 RSL_CCHAN.clear;
4484 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4485 vc_conn.done;
4486 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4487}
4488
Harald Welte93640c62018-02-25 16:59:33 +01004489/***********************************************************************
4490 * IPA CRCX/MDCX/DLCS media stream handling
4491 ***********************************************************************/
4492
Harald Weltea871a382018-02-25 02:03:14 +01004493/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004494private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004495 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4496 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004497}
4498testcase TC_ipa_dlcx_not_active() runs on test_CT {
4499 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004500 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004501 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4502 vc_conn.done;
4503}
Harald Welte68e495b2018-02-25 00:05:57 +01004504
Harald Weltea3f1df92018-02-25 12:49:55 +01004505/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004506private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004507 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4508 "IPA CRCX ACK");
4509 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4510 "IPA CRCX NACK");
4511}
4512testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4513 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004514 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004515 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4516 vc_conn.done;
4517}
4518
4519/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004520private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004521 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4522 "IPA CRCX ACK");
4523 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4524 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4525 var uint7_t rtp_pt2 := f_rnd_int(127);
4526 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4527 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4528 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4529 "IPA MDCX ACK");
4530 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4531 "IPA DLCX ACK");
4532}
4533testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4534 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004535 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004536 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4537 vc_conn.done;
4538}
4539
Harald Welte3ae11da2018-02-25 13:36:06 +01004540/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004541private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004542 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4543 "IPA CRCX ACK");
4544 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4545 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4546 var uint7_t rtp_pt2 := f_rnd_int(127);
4547 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4548 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4549 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4550 "IPA MDCX ACK");
4551 /* Second MDCX */
4552 remote_ip := f_rnd_int(c_UINT32_MAX);
4553 remote_port := f_rnd_int(c_UINT16_MAX);
4554 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4555 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4556 "IPA MDCX ACK");
4557 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4558 "IPA DLCX ACK");
4559}
4560testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4561 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004562 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004563 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4564 vc_conn.done;
4565}
4566
Harald Welte9912eb52018-02-25 13:30:15 +01004567/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004568private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004569 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4570 "IPA CRCX NACK");
4571}
4572testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4573 var ConnHdlrPars pars;
4574 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004575 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004576
4577 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4578 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4579 vc_conn.done;
4580
4581 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4582 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4583 vc_conn.done;
4584}
4585
Harald Weltea3f1df92018-02-25 12:49:55 +01004586
Harald Welte883340c2018-02-28 18:59:29 +01004587/***********************************************************************
4588 * PCU Socket related tests
4589 ***********************************************************************/
4590
Harald Welte07bd2d22019-05-25 11:03:30 +02004591/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004592friend 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 +01004593runs on test_CT {
4594 timer T := 3.0;
4595
4596 /* we don't expect any RTS.req before PDCH are active */
4597 T.start;
4598 alt {
4599 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004601 }
4602 [] PCU.receive { repeat; }
4603 [] T.timeout { }
4604 }
4605
4606 /* Send PDCH activate request for known PDCH timeslot */
4607 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4608
4609 /* we now expect RTS.req for this timeslot (only) */
4610 T.start;
4611 alt {
4612 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4613 setverdict(pass);
4614 }
4615 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4616 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004618 }
4619 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004621 }
4622 [] PCU.receive { repeat; }
4623 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004624 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004625 }
4626 [not exp_success] T.timeout {
4627 setverdict(pass);
4628 }
4629 }
4630}
4631
Harald Welte07bd2d22019-05-25 11:03:30 +02004632/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004633friend 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 +01004634runs on test_CT {
4635 timer T := 3.0;
4636
4637 /* Send PDCH activate request for known PDCH timeslot */
4638 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 +02004639 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4640 * when it will actually have been executed in the BTS */
4641 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004642 PCU.clear;
4643 /* we now expect no RTS.req for this timeslot */
4644 T.start;
4645 alt {
4646 [] 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 +02004647 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004648 }
4649 [] PCU.receive { repeat; }
4650 [] T.timeout {
4651 setverdict(pass);
4652 }
4653 }
4654}
4655
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004656friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004657 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004658 map(self:PCU, system:PCU);
4659 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01004660 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4661}
4662
Harald Welte883340c2018-02-28 18:59:29 +01004663/* PDCH activation via PCU socket; check for presence of RTS.req */
4664testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004665 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004666
Harald Welte883340c2018-02-28 18:59:29 +01004667 f_TC_pcu_act_req(0, 0, 7, true);
4668}
4669
4670/* PDCH activation via PCU socket on non-PDCU timeslot */
4671testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004672 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004673
Harald Welte883340c2018-02-28 18:59:29 +01004674 f_TC_pcu_act_req(0, 0, 1, false);
4675}
4676
4677/* PDCH activation via PCU socket on wrong BTS */
4678testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004679 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004680
Harald Welte883340c2018-02-28 18:59:29 +01004681 f_TC_pcu_act_req(23, 0, 7, false);
4682}
4683
4684/* PDCH activation via PCU socket on wrong TRX */
4685testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004686 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004687
Harald Welte883340c2018-02-28 18:59:29 +01004688 f_TC_pcu_act_req(0, 23, 7, false);
4689}
4690
4691/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4692testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004693 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004694
Harald Welte883340c2018-02-28 18:59:29 +01004695 /* Activate PDCH */
4696 f_TC_pcu_act_req(0, 0, 7, true);
4697 f_sleep(1.0);
4698 /* and De-Activate again */
4699 f_TC_pcu_deact_req(0, 0, 7);
4700}
4701
4702/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4703testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004704 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004705
Harald Welte883340c2018-02-28 18:59:29 +01004706 f_TC_pcu_deact_req(0, 0, 1);
4707}
4708
4709/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01004710function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01004711 var PCUIF_send_data sd;
4712 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004713 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01004714
4715 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01004716 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01004717
Harald Welte883340c2018-02-28 18:59:29 +01004718 T.start;
4719 alt {
4720 [] 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 +01004721 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01004722 setverdict(pass);
4723 } else {
4724 repeat;
4725 }
4726 }
4727 [] PCU.receive { repeat; }
4728 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01004729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01004730 }
4731 }
4732}
4733
Philipp Maier94c08482021-02-01 17:36:05 +01004734/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
4735testcase TC_pcu_ver_si1() runs on test_CT {
4736 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
4737 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
4738}
4739
4740/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
4741testcase TC_pcu_ver_si3() runs on test_CT {
4742 const octetstring si3 := '49012223242526272929AABBCC'O;
4743 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
4744}
4745
4746/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4747testcase TC_pcu_ver_si13() runs on test_CT {
4748 const octetstring si13 := '01010203040506070909'O;
4749 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
4750}
4751
Harald Welte883340c2018-02-28 18:59:29 +01004752private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4753
4754/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004755friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004756 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4757runs on test_CT
4758{
4759 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4760 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4761}
4762
4763/* 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 +02004764friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4765 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004766runs on test_CT
4767{
4768 var PCUIF_send_data sd;
4769
4770 timer T := 3.0;
4771 T.start;
4772 alt {
4773 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4774 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4775 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4776 sd.data.u.rts_req.fn, sapi, data);
4777 }
4778 [] PCU.receive { repeat; }
4779 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004780 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004781 }
4782 }
4783}
4784
4785/* Send DATA.req on invalid BTS */
4786testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004787 var TfiUsfArr tua := f_TfiUsfArrInit();
4788 var octetstring data := '0000'O & f_rnd_octstring(21);
4789
4790 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004791
Harald Welte883340c2018-02-28 18:59:29 +01004792 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004793 f_TfiUsfArrSet(tua, 7, 0);
4794 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4795 f_sleep(1.0);
4796
4797 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004798}
4799
4800/* Send DATA.req on invalid TRX */
4801testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004802 var TfiUsfArr tua := f_TfiUsfArrInit();
4803 var octetstring data := '0000'O & f_rnd_octstring(21);
4804
4805 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004806
Harald Welte883340c2018-02-28 18:59:29 +01004807 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004808 f_TfiUsfArrSet(tua, 7, 0);
4809 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4810 f_sleep(1.0);
4811
4812 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004813}
4814
4815/* Send DATA.req on invalid timeslot */
4816testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004817 var TfiUsfArr tua := f_TfiUsfArrInit();
4818 var octetstring data := '0000'O & f_rnd_octstring(21);
4819
4820 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004821
Harald Welte883340c2018-02-28 18:59:29 +01004822 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004823 f_TfiUsfArrSet(tua, 7, 0);
4824 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4825 f_sleep(1.0);
4826
4827 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004828}
4829
4830/* Send DATA.req on timeslot that hasn't been activated */
4831testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004832 var TfiUsfArr tua := f_TfiUsfArrInit();
4833 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004834
Harald Welte7162a612019-05-26 12:56:09 +02004835 f_virtphy_common();
4836
4837 f_TfiUsfArrSet(tua, 7, 0);
4838 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4839 f_sleep(1.0);
4840
4841 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004842}
4843
Harald Weltead033dc2019-05-25 17:28:16 +02004844private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004845 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4846 boolean wait_rts := true)
4847runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004848 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004849 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004850
4851 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004852 if (wait_rts) {
4853 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4854 } else {
4855 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4856 }
Harald Weltead033dc2019-05-25 17:28:16 +02004857
4858 T.start;
4859 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004860 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004861 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4862 setverdict(pass);
4863 }
Harald Welte7162a612019-05-26 12:56:09 +02004864 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4865 setverdict(fail, "Received unexpected ", rx_dl);
4866 }
Harald Weltead033dc2019-05-25 17:28:16 +02004867 [] L1CTL.receive {
4868 repeat;
4869 }
Harald Welte7162a612019-05-26 12:56:09 +02004870 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004871 setverdict(fail, "Timeout waiting for ", data);
4872 }
Harald Welte7162a612019-05-26 12:56:09 +02004873 [not expect_data] T.timeout {
4874 setverdict(pass);
4875 }
Harald Weltead033dc2019-05-25 17:28:16 +02004876 }
4877}
4878
4879private function f_disable_dynamic_ts() runs on test_CT
4880{
4881 f_init_vty_bsc();
4882 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4883 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4884 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4885 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004886 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02004887}
4888
4889private function f_virtphy_common() runs on test_CT {
4890 f_disable_dynamic_ts();
4891 f_init_l1ctl();
4892 f_l1_tune(L1CTL);
4893}
4894
4895testcase TC_pcu_data_req_pdtch() runs on test_CT {
4896 var TfiUsfArr tua := f_TfiUsfArrInit();
4897 var octetstring data := '0000'O & f_rnd_octstring(21);
4898
4899 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004900
Harald Welte883340c2018-02-28 18:59:29 +01004901 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004902 f_TfiUsfArrSet(tua, 7, 0);
4903 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4904 f_sleep(1.0);
4905
4906 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004907}
4908
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004909/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004910testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004911 var TfiUsfArr tua := f_TfiUsfArrInit();
4912 var octetstring data := '0000'O & f_rnd_octstring(21);
4913
4914 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004915
Harald Welte883340c2018-02-28 18:59:29 +01004916 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004917 f_TfiUsfArrSet(tua, 7, 0);
4918 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4919 f_sleep(1.0);
4920
4921 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004922}
4923
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004924private function f_TC_pcu_ptcch_ul(uint16_t ra)
4925runs on test_CT {
4926 var template PCUIF_Message pcu_rach_ind;
4927 var PCUIF_send_data sd;
4928 var GsmFrameNumber fn;
4929 timer T;
4930
4931 /* Send an Access Burst on PTCCH/U over the Um-interface */
4932 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4933 chan_nr := ts_RslChanNr_PDCH(7),
4934 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4935
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004936 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4937 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004938
4939 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4940 T.start(52.0 * 4.615 / 1000.0);
4941 alt {
4942 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4943 log("Rx an Access Burst on the PCU interface: ", sd.data);
4944 setverdict(pass);
4945 T.stop;
4946 }
4947 [] PCU.receive { repeat; }
4948 [] T.timeout {
4949 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4950 /* Keep going, that's not the end of the world */
4951 }
4952 }
4953}
4954
4955testcase TC_pcu_ptcch() runs on test_CT {
4956 var L1ctlDlMessage dl;
4957 var octetstring data;
4958 timer T;
4959
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004960 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004961 f_init_l1ctl();
4962 f_l1_tune(L1CTL);
4963
4964 /* Activate PDCH channel on TS7 */
4965 f_TC_pcu_act_req(0, 0, 7, true);
4966
4967 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004968 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004969 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004970 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004971 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004972
4973 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4974 for (var integer i := 0; i < 16; i := i + 1) {
4975 log("Sending an Access Burst towards the L1CTL interface");
4976 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4977 }
4978
4979 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4980 data := f_rnd_octstring(23);
4981
4982 /* Verify PTCCH/D: send a random data block, make sure it's received */
4983 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4984 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4985
4986 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4987 * let's give it more time in case if we miss the beginning. */
4988 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4989 alt {
4990 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4991 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4992 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4993 frame := data)) -> value dl {
4994 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4995 setverdict(pass);
4996 T.stop;
4997 }
4998 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4999 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
5000 link_id := tr_RslLinkID_OSMO_PTCCH(?),
5001 l2_data := data)) -> value dl {
5002 log("Rx PTCCH/D data block on L1CTL: ", dl);
5003 setverdict(pass);
5004 T.stop;
5005 }
5006 [] L1CTL.receive { repeat; }
5007 [] T.timeout {
5008 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
5009 }
5010 }
5011}
5012
Harald Welte883340c2018-02-28 18:59:29 +01005013/* Send AGCH from PCU; check it appears on Um side */
5014testcase TC_pcu_data_req_agch() runs on test_CT {
5015 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005016 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005017 f_init_l1ctl();
5018 f_l1_tune(L1CTL);
5019
5020 f_TC_pcu_act_req(0, 0, 7, true);
5021 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5022
5023 T.start;
5024 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005025 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005026 setverdict(pass);
5027 }
5028 [] L1CTL.receive { repeat; }
5029 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005031 }
5032 }
5033}
5034
Harald Welte928622b2019-05-26 13:22:59 +02005035/* Send AGCH from PCU; check it appears on Um side */
5036testcase TC_pcu_data_req_pch() runs on test_CT {
5037 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005038 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005039 f_init_l1ctl();
5040 f_l1_tune(L1CTL);
5041
5042 f_TC_pcu_act_req(0, 0, 7, true);
5043 /* three characters prefix: last 3 digits of IMSI as ASCII */
5044 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5045
5046 T.start;
5047 alt {
5048 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5049 setverdict(pass);
5050 }
5051 [] L1CTL.receive { repeat; }
5052 [] T.timeout {
5053 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5054 }
5055 }
5056}
5057
Harald Welte883340c2018-02-28 18:59:29 +01005058/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5059testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5060 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005061 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005062 f_init_l1ctl();
5063 f_l1_tune(L1CTL);
5064
5065 /* append 3 last imsi digits so BTS can compute pagng group */
5066 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5067
5068 timer T := 0.5;
5069 T.start;
5070 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005071 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005072 /* TODO: verify paging group */
5073 setverdict(pass);
5074 }
5075 [] L1CTL.receive { repeat; }
5076 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005078 }
5079 }
5080}
5081
5082/* Send RACH from Um side, expect it to show up on PCU socket */
5083testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005084 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005085 f_init_l1ctl();
5086 f_l1_tune(L1CTL);
5087
5088 var GsmFrameNumber fn_last := 0;
5089 for (var integer i := 0; i < 1000; i := i+1) {
5090 var OCT1 ra := f_rnd_ra_ps();
5091 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5092 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005094 }
5095 fn_last := fn;
5096
5097 timer T := 2.0;
5098 T.start;
5099 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005100 [] 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 +01005101 T.stop;
5102 }
5103 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005105 }
5106 [] PCU.receive { repeat; }
5107 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005109 }
5110 }
5111 }
5112 setverdict(pass);
5113}
5114
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005115/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5116 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5117testcase TC_pcu_ext_rach_content() runs on test_CT {
5118 var template PCUIF_Message pcu_rach_ind;
5119 var GsmFrameNumber fn_last := 0;
5120 var L1ctlRachSynchSeq synch_seq;
5121 var PCUIF_BurstType pcu_bt;
5122 var GsmFrameNumber fn;
5123 var BIT11 ra11;
5124
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005125 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005126 f_init_l1ctl();
5127 f_l1_tune(L1CTL);
5128
5129 for (var integer i := 0; i < 1000; i := i+1) {
5130 /* We need to test both TS1 & TS2 */
5131 if (i rem 2 == 0) {
5132 synch_seq := RACH_SYNCH_SEQ_TS1;
5133 pcu_bt := BURST_TYPE_1;
5134 } else {
5135 synch_seq := RACH_SYNCH_SEQ_TS2;
5136 pcu_bt := BURST_TYPE_2;
5137 }
5138
5139 ra11 := f_rnd_ra11_ps();
5140 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5141 if (fn == fn_last) {
5142 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5143 "Two RACH in same FN?!?");
5144 }
5145 fn_last := fn;
5146
5147 /* Compose the expected message */
5148 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005149 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005150 ra := bit2int(ra11),
5151 is_11bit := 1,
5152 burst_type := pcu_bt,
5153 fn := fn);
5154
5155 timer T := 2.0;
5156 T.start;
5157 alt {
5158 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5159 T.stop;
5160 }
5161 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5162 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5163 }
5164 [] PCU.receive { repeat; }
5165 [] T.timeout {
5166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5167 }
5168 }
5169 }
5170 setverdict(pass);
5171}
5172
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005173private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5174runs on test_CT {
5175 var template PCUIF_send_data sdt;
5176 var PCUIF_send_data sd;
5177 var int16_t lqual_cb;
5178 timer T := 1.0;
5179
5180 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5181 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5182
5183 /* Send a random PDTCH frame over Um */
5184 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5185 '0000'O & f_rnd_octstring(21)));
5186
5187 T.start;
5188 alt {
5189 /* If expected link quality is above the threshold */
5190 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5191 lqual_cb := sd.data.u.data_ind.lqual_cb;
5192 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5193
5194 /* Make sure the actual link quality matches the expected value */
5195 if (not match(lqual_cb, lqual_cb_exp)) {
5196 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5197 "expected value ", lqual_cb_exp));
5198 } else {
5199 setverdict(pass);
5200 }
5201 }
5202 /* If expected link quality is below the threshold */
5203 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5204 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5205 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5206 }
5207 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5208 [] PCU.receive { repeat; }
5209 [lqual_cb_exp < thresh] T.timeout {
5210 log("Rx nothing, as expected");
5211 setverdict(pass);
5212 }
5213 [lqual_cb_exp >= thresh] T.timeout {
5214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5215 "Timeout waiting for PCUIF_DATA.ind");
5216 }
5217 }
5218}
5219
5220/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5221testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005222 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005223 PCU.clear;
5224
5225 f_init_l1ctl();
5226 f_l1_tune(L1CTL);
5227
5228 /* Activate a PDCH channel on TS7 */
5229 f_TC_pcu_act_req(0, 0, 7, true);
5230
5231 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005232 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005233 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005234 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005235 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005236
5237 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5238 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5239 var TrxcMessage ret;
5240
5241 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5242 valueof(ts_TRXC_FAKE_CI(i)));
5243
5244 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5245 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5246 }
5247}
5248
Harald Welte883340c2018-02-28 18:59:29 +01005249/* Send PAGING via RSL, expect it to shw up on PCU socket */
5250testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005251 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005252
5253 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005254 var MobileIdentityLV mi_lv;
5255 var octetstring mi_lv_enc;
5256 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005257 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005258
Harald Welte883340c2018-02-28 18:59:29 +01005259 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005260 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005261 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005262 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005263 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005264
5265 /* Fancy encoding for PCUIF */
5266 mi_lv := valueof(ts_MI_LV(mi));
5267 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5268 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005269
5270 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005271 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005272 T.start;
5273 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005274 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005275 }
5276 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005277 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005278 }
5279 [] PCU.receive { repeat; }
5280 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005282 }
5283 }
5284 }
5285 setverdict(pass);
5286}
5287
Harald Welted66c9b82019-05-25 09:03:15 +02005288/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5289testcase TC_pcu_time_ind() runs on test_CT {
5290 var PCUIF_send_data pcu_sd;
5291 var integer num_time_ind := 0;
5292 var integer first_fn, last_fn;
5293 var float test_duration := 5.0;
5294 timer T;
5295
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005296 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005297 f_TC_pcu_act_req(0, 0, 7, true);
5298
5299 PCU.clear;
5300 T.start(test_duration);
5301 alt {
5302 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5303 num_time_ind := num_time_ind + 1;
5304 if (not isbound(first_fn)) {
5305 first_fn := pcu_sd.data.u.time_ind.fn;
5306 }
5307 last_fn := pcu_sd.data.u.time_ind.fn;
5308 repeat;
5309 }
5310 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5311 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5312 repeat;
5313 }
5314 [] PCU.receive {
5315 repeat;
5316 }
5317 [] T.timeout {}
5318 }
5319 var integer fn_expired := last_fn - first_fn;
5320 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5321
5322 /* verify the number of frames expired matches our expectation */
5323 const float c_GSM_FN_DURATION_MS := 4.61538;
5324 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005325 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005326 if (not match(fn_expired, t_fn_expected)) {
5327 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5328 }
5329
5330 /* There are three TIME.ind in every fn MOD 13 */
5331 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5332 /* Add some tolerance */
5333 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5334 if (not match(num_time_ind, t_time_ind_exp)) {
5335 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5336 }
5337
5338 setverdict(pass);
5339}
5340
Harald Welte4832c862019-05-25 14:57:18 +02005341/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5342testcase TC_pcu_rts_req() runs on test_CT {
5343 var PCUIF_send_data pcu_sd;
5344 var integer first_fn, last_fn;
5345 var integer num_rts_pdtch := 0;
5346 var integer num_rts_ptcch := 0;
5347 var float test_duration := 5.0;
5348 timer T;
5349
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005350 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005351 f_TC_pcu_act_req(0, 0, 7, true);
5352
5353 PCU.clear;
5354 T.start(test_duration);
5355 alt {
5356 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5357 -> value pcu_sd {
5358 num_rts_pdtch := num_rts_pdtch + 1;
5359 if (not isbound(first_fn)) {
5360 first_fn := pcu_sd.data.u.rts_req.fn;
5361 }
5362 last_fn := pcu_sd.data.u.rts_req.fn;
5363 repeat;
5364 }
5365 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5366 -> value pcu_sd {
5367 num_rts_ptcch := num_rts_ptcch + 1;
5368 if (not isbound(first_fn)) {
5369 first_fn := pcu_sd.data.u.rts_req.fn;
5370 }
5371 last_fn := pcu_sd.data.u.rts_req.fn;
5372 repeat;
5373 }
5374 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5375 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5376 repeat;
5377 }
5378 [] PCU.receive {
5379 repeat;
5380 }
5381 [] T.timeout {}
5382 }
5383 var integer fn_expired := last_fn - first_fn;
5384 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5385 ", num_rts_ptcch=", num_rts_ptcch);
5386
5387 /* verify the number of frames expired matches our expectation */
5388 const float c_GSM_FN_DURATION_MS := 4.61538;
5389 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005390 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005391 if (not match(fn_expired, t_fn_expected)) {
5392 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5393 }
5394
5395 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5396 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5397 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5398 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5399 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5400 t_ptcch_exp);
5401 }
5402
5403 /* We have 12 PDTCH blocks every 52-multiframe */
5404 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5405 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5406 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5407 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5408 t_pdtch_exp);
5409 }
5410
5411 setverdict(pass);
5412}
5413
Harald Welte07bd2d22019-05-25 11:03:30 +02005414/* test for generating Abis side OML ALERT from the PCU */
5415testcase TC_pcu_oml_alert() runs on test_CT {
5416 var PCUIF_send_data pcu_sd;
5417 var integer num_time_ind := 0;
5418 var integer first_fn, last_fn;
5419 var float test_duration := 5.0;
5420 timer T;
5421
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005422 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005423 f_TC_pcu_act_req(0, 0, 7, true);
5424
5425 /* re-connect CTRL port from BTS to BSC */
5426 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005427 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005428
5429 /* Send that OML Alert */
5430 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5431
5432 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5433 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5434 setverdict(pass);
5435}
5436
Harald Welteeaa9a862019-05-26 23:01:08 +02005437/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5438private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5439 var PCUIF_Message first_info;
5440 var integer pcu_conn_id := -1;
5441 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5442 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5443 var OCT4 tlli := '01020304'O;
5444 var OCT1 cause := '23'O;
5445 timer T := 5.0;
5446
5447 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5448
5449 f_l1_tune(L1CTL);
5450 RSL.clear;
5451
5452 f_est_dchan();
5453 L1CTL.clear;
5454
5455 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5456
5457 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5458 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5459 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5460
5461 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5462 T.start;
5463 alt {
5464 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5465 setverdict(pass);
5466 }
5467 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5468 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5469 }
5470 [] PCU.receive {
5471 repeat;
5472 }
5473 [] T.timeout {
5474 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5475 }
5476 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005477
5478 /* release the channel */
5479 f_rsl_chan_deact();
5480 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5481 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005482}
5483testcase TC_pcu_rr_suspend() runs on test_CT {
5484 var ConnHdlrPars pars;
5485 var ConnHdlr vc_conn;
5486
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005487 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005488
5489 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5490 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5491 vc_conn.done;
5492}
Harald Welte07bd2d22019-05-25 11:03:30 +02005493
Harald Weltea2e0e942019-05-27 18:12:53 +02005494/* Ensure that PCUIF socket can accept only a single connection */
5495testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005496 var boolean connected := false;
5497 var UD_connect_result cr;
5498 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005499 timer T := 5.0;
5500
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005501 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5502 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5503
Harald Weltea2e0e942019-05-27 18:12:53 +02005504 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005505 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005506
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005507 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005508 PCU.send(UD_connect:{mp_pcu_socket, -1});
5509 T.start;
5510 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005511 /* the IUT will first accept() the new connection, and close() it immediately */
5512 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5513 log("BTS has accept()ed connection");
5514 connected := true;
5515 cid := cr.id;
5516 repeat;
5517 }
5518 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5519 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005520 setverdict(pass);
5521 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005522 /* ignore other messages related to the first connection */
5523 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005524 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005525 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005526 }
5527 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005528
Harald Weltea2e0e942019-05-27 18:12:53 +02005529 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5530}
5531
Harald Weltec8effb72019-05-27 18:23:04 +02005532/* Ensure that PCUIF socket can disconnect + reconnect */
5533testcase TC_pcu_socket_reconnect() runs on test_CT {
5534 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005535 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005536
5537 f_sleep(1.0);
5538
5539 f_pcuif_close(PCU, g_pcu_conn_id);
5540 g_pcu_conn_id := -1;
5541
5542 f_sleep(1.0);
5543
5544 /* re-connect */
5545 PCU.clear;
5546 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5547 setverdict(pass);
5548
5549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5550}
5551
Harald Weltebe030482019-05-27 22:29:35 +02005552/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005553private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5554runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005555 var L1ctlDlMessage l1_dl;
5556 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005557 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005558 timer T := 5.0;
5559 T.start;
5560 alt {
5561 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005562 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5563 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005564 repeat;
5565 }
5566 }
5567 [] pt.receive {
5568 repeat;
5569 }
5570 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5572 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005573 }
5574 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005575 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005576}
5577
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005578/* Check if GPRS Indicator is present in RR System Information of a given type */
5579private function f_si_has_gprs_indicator(RrMessageType si_type)
5580runs on test_CT return boolean {
5581 var SystemInformation si := f_get_si(L1CTL, si_type);
5582
5583 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005584 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005585 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005586 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005587 }
5588
5589 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5590 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005591}
5592
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005593/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5594private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5595runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005596 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02005597 f_init_l1ctl();
5598 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005599 f_sleep(2.0);
5600 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005601
5602 if (f_si_has_gprs_indicator(si_type)) {
5603 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005604 } else {
5605 setverdict(pass);
5606 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005607
Harald Weltebe030482019-05-27 22:29:35 +02005608 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5609}
5610
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005611testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5612 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5613}
Harald Weltebe030482019-05-27 22:29:35 +02005614
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005615testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5616 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5617}
5618
5619/* Ensure that GPRS capability is advertised after PCU socket connect */
5620private function f_TC_pcu_socket_connect(RrMessageType si_type)
5621runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005622 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005623 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005624 f_init_l1ctl();
5625 f_l1_tune(L1CTL);
5626
5627 f_sleep(2.0);
5628 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005629
5630 if (not f_si_has_gprs_indicator(si_type)) {
5631 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005632 } else {
5633 setverdict(pass);
5634 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005635
Harald Weltebe030482019-05-27 22:29:35 +02005636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5637}
5638
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005639testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5640 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5641}
Harald Weltebe030482019-05-27 22:29:35 +02005642
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005643testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5644 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5645}
5646
5647/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5648private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5649runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005650 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005651 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005652 f_init_l1ctl();
5653 f_l1_tune(L1CTL);
5654
5655 f_pcuif_close(PCU, g_pcu_conn_id);
5656 g_pcu_conn_id := -1;
5657
5658 f_sleep(1.0);
5659
5660 /* re-connect */
5661 PCU.clear;
5662 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5663
5664 f_sleep(2.0);
5665 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005666
5667 if (f_si_has_gprs_indicator(si_type)) {
5668 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005669 } else {
5670 setverdict(pass);
5671 }
5672
5673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5674}
5675
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005676testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5677 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5678}
5679
5680testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5681 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5682}
5683
Oliver Smithf5239c72019-08-28 10:01:25 +02005684/* 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) */
5685testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5686 var SystemInformation si3 := valueof(ts_SI3_default);
5687
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005688 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02005689
Harald Welte76220222020-10-11 20:32:44 +02005690 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5691 * information */
5692 timer T := 2.0;
5693 T.start;
5694 alt {
5695 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5696 [] T.timeout {}
5697 }
5698
Oliver Smithf5239c72019-08-28 10:01:25 +02005699 /* Verify cell_id */
5700 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5701 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5702 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005703 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5704 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5705 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005706 }
5707
5708 /* Verify LAC */
5709 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5710 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5711 if (lac_si3 != lac_pcu) {
5712 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5713 }
5714
5715 setverdict(pass);
5716}
Harald Welted66c9b82019-05-25 09:03:15 +02005717
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005718/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5719testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5720 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005721 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005722
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005723 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005724
5725 info_ind := g_pcu_last_info.u.info_ind;
5726
5727 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5728 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005729 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005730 /* Skip inactive timeslots */
5731 continue;
5732 }
5733
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005734 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005735 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005736 else
5737 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005738
5739 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005740 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005741 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005742 hsn := fhp.maio_hsn.hsn,
5743 maio := fhp.maio_hsn.maio,
5744 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005745 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005746 } else {
5747 tr_ts := tr_PCUIF_InfoTrxTsH0;
5748 }
5749
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005750 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005751 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5752 if (not match(ts, tr_ts)) {
5753 setverdict(fail, "Hopping parameters do not match: ",
5754 "received ", ts, " vs expected ", tr_ts);
5755 } else {
5756 setverdict(pass);
5757 }
5758 }
5759 }
5760}
5761
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005762/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02005763testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5764 f_init_vty_bsc();
5765 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5766 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5767
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005768 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02005769
5770 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005771 var template PCUIF_RemoteAddr tr_remote_addr := {
5772 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01005773 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005774 };
Alexander Couzens5283f552020-07-28 15:39:04 +02005775
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005776 if (not match(remote_addr, tr_remote_addr)) {
5777 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02005778 }
5779
5780 setverdict(pass);
5781}
5782
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005783/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02005784testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5785 f_init_vty_bsc();
5786 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5787
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005788 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02005789
5790 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005791 var template PCUIF_RemoteAddr tr_remote_addr := {
5792 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
5793 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
5794 };
Alexander Couzens5283f552020-07-28 15:39:04 +02005795
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005796 if (not match(remote_addr, tr_remote_addr)) {
5797 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02005798 }
5799
5800 setverdict(pass);
5801}
5802
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005803/* Verify coding of two NSVCs in the INFO.ind message */
5804testcase TC_pcu_socket_two_nsvc() runs on test_CT {
5805 f_init_vty_bsc();
5806
5807 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
5808 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
5809 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5810 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
5811
5812 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
5813 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
5814 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
5815 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
5816
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005817 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005818
5819 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
5820 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
5821 var template PCUIF_RemoteAddr tr_remote_addr := {
5822 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01005823 addr := {
5824 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
5825 f_inet6_addr("fd00::ca:ff:ee")
5826 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005827 };
5828
5829 if (not match(info_ind.nsvci, { 1234, 5678 }))
5830 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
5831 if (not match(remote_addr, tr_remote_addr))
5832 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
5833 if (not match(info_ind.local_port, { 1234, 5678 }))
5834 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
5835 if (not match(info_ind.remote_port, { 1234, 5678 }))
5836 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
5837
5838 setverdict(pass);
5839}
5840
Harald Welte3d04ae62018-04-04 20:29:05 +02005841/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005842 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005843 ***********************************************************************/
5844
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005845private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5846 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005847runs on ConnHdlr {
5848 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005849
5850 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005851 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005852 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5853 repeat;
5854 }
5855 }
5856}
5857
5858private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5859runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005860 /* Expect BTS to immediately acknowledge activation as PDCH */
5861 PCU.clear;
5862 f_rsl_chan_act(g_pars.chan_mode);
5863 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005864 timer T_wait := 2.0;
5865 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005866 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005867 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005868 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005869 [] T_wait.timeout {
5870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5871 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5872 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005873 }
5874 /* try to activate this PDCH from the PCU point of view */
5875 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5876 /* FIXME: is there a response? */
5877}
5878
5879private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5880runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005881 /* Send RSL CHAN REL (deactivate) */
5882 PCU.clear;
5883 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5884 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005885 timer T_wait := 2.0;
5886 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005887 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005888 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005889 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005890 [] T_wait.timeout {
5891 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5892 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5893 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005894 }
5895 /* Emulate PCU asking BTS to deactivate PDCH */
5896 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5897 alt {
5898 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5899 setverdict(pass);
5900 }
5901 [] RSL.receive { repeat; }
5902 }
5903}
5904
5905/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005906private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005907 var PCUIF_Message first_info;
5908 var integer ts_nr := g_chan_nr.tn;
5909 var integer trx_nr := 0;
5910 var integer bts_nr := 0;
5911 var integer pcu_conn_id := -1;
5912
5913 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5914
5915 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5916 f_sleep(3.0);
5917 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5918 setverdict(pass);
5919}
5920testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5921 var ConnHdlrPars pars;
5922 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005923 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005924
5925 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5926 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5927 vc_conn.done;
5928}
5929
5930/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005931private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005932 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005933 var integer pcu_conn_id := -1;
5934
5935 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5936
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005937 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5938 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5939 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005940 setverdict(pass);
5941}
5942testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5943 var ConnHdlrPars pars;
5944 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005945 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005946
5947 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5948 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5949 vc_conn.done;
5950}
5951
5952/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005953private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005954 var PCUIF_Message first_info;
5955 var integer ts_nr := g_chan_nr.tn;
5956 var integer trx_nr := 0;
5957 var integer bts_nr := 0;
5958 var integer pcu_conn_id := -1;
5959
5960 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5961
5962 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005963 /* Send a second Chan Activ and expect it to be NACKed */
5964 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5965 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005966 setverdict(pass);
5967}
5968testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5969 var ConnHdlrPars pars;
5970 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005971 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005972
5973 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5974 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5975 vc_conn.done;
5976}
5977
5978/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005979private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005980 var PCUIF_Message first_info;
5981 var integer ts_nr := g_chan_nr.tn;
5982 var integer trx_nr := 0;
5983 var integer bts_nr := 0;
5984 var integer pcu_conn_id := -1;
5985 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5986
5987 /* register for the TCH/F channel number */
5988 f_rslem_register(0, chan_nr);
5989
5990 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5991
5992 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5993 "RSL CHAN ACT");
5994 setverdict(pass);
5995}
5996testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5997 var ConnHdlrPars pars;
5998 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005999 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006000
6001 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6002 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
6003 vc_conn.done;
6004}
6005
6006/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006007private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02006008 var PCUIF_Message first_info;
6009 var integer ts_nr := g_chan_nr.tn;
6010 var integer trx_nr := 0;
6011 var integer bts_nr := 0;
6012 var integer pcu_conn_id := -1;
6013 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6014 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6015
6016 /* register for the TCH/H channel numbers */
6017 f_rslem_register(0, chan_nr[0]);
6018 f_rslem_register(0, chan_nr[1]);
6019
6020 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6021
6022 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6023 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6024 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6025 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6026 setverdict(pass);
6027}
6028testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6029 var ConnHdlrPars pars;
6030 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006031 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006032
6033 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6034 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6035 vc_conn.done;
6036}
6037
Harald Welte9bbbfb52018-04-05 09:33:19 +02006038/***********************************************************************
6039 * IPA Style Dynamic Timeslot Support
6040 ***********************************************************************/
6041
6042private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6043runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006044 /* Expect BTS to immediately acknowledge activation as PDCH */
6045 PCU.clear;
6046 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6047 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006048 timer T_wait := 2.0;
6049 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006050 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006051 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006052 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006053 [] T_wait.timeout {
6054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6055 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6056 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006057 }
6058 /* try to activate this PDCH from the PCU point of view */
6059 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6060 /* FIXME: is there a response? */
6061
6062 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6063}
6064
6065private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6066runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006067 /* Send RSL CHAN REL (deactivate) */
6068 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6069 PCU.clear;
6070 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006071 timer T_wait := 2.0;
6072 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006073 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006074 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006075 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006076 [] T_wait.timeout {
6077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6078 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6079 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006080 }
6081 /* Emulate PCU asking BTS to deactivate PDCH */
6082 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6083 alt {
6084 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6085 setverdict(pass);
6086 }
6087 [] RSL.receive { repeat; }
6088 }
6089}
6090
6091/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006092private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006093 var PCUIF_Message first_info;
6094 var integer ts_nr := g_chan_nr.tn;
6095 var integer trx_nr := 0;
6096 var integer bts_nr := 0;
6097 var integer pcu_conn_id := -1;
6098
6099 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6100
6101 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6102 f_sleep(3.0);
6103 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6104
6105 setverdict(pass);
6106
6107}
6108testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6109 var ConnHdlrPars pars;
6110 var ConnHdlr vc_conn;
6111 f_init();
6112
6113 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6114 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6115 vc_conn.done;
6116}
6117
6118/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006119private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006120 var PCUIF_Message first_info;
6121 var integer ts_nr := g_chan_nr.tn;
6122 var integer trx_nr := 0;
6123 var integer bts_nr := 0;
6124 var integer pcu_conn_id := -1;
6125
6126 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6127
6128 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6129 "RSL CHAN ACT");
6130 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6131 "RF CHAN REL", true);
6132 setverdict(pass);
6133}
6134testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6135 var ConnHdlrPars pars;
6136 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006137 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006138
6139 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6140 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6141 vc_conn.done;
6142}
6143
6144/* 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 +07006145private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006146 var PCUIF_Message first_info;
6147 var integer ts_nr := g_chan_nr.tn;
6148 var integer trx_nr := 0;
6149 var integer bts_nr := 0;
6150 var integer pcu_conn_id := -1;
6151
6152 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6153
6154 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6155 "RSL CHAN ACT");
6156
6157 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6158 alt {
6159 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6160 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006161 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006162 }
6163 [] RSL.receive { repeat; }
6164 }
6165
6166 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6167 "RF CHAN REL", true);
6168 setverdict(pass);
6169}
6170testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6171 var ConnHdlrPars pars;
6172 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006173 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006174
6175 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6176 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6177 vc_conn.done;
6178}
6179
6180/* 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 +07006181private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006182 var PCUIF_Message first_info;
6183 var integer ts_nr := g_chan_nr.tn;
6184 var integer trx_nr := 0;
6185 var integer bts_nr := 0;
6186 var integer pcu_conn_id := -1;
6187
6188 /* register for the TCH/F channel number */
6189 f_rslem_register(0, g_chan_nr);
6190
6191 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6192
6193 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6194
6195 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6196 "RSL CHAN ACT");
6197
6198 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6199
6200 setverdict(pass);
6201}
6202testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6203 var ConnHdlrPars pars;
6204 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006205 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006206
6207 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6208 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6209 vc_conn.done;
6210}
6211
6212
Harald Welte0472ab42018-03-12 15:02:26 +01006213/***********************************************************************
6214 * LAPDm / RLL related
6215 ***********************************************************************/
6216
6217private function f_tx_lapdm(template (value) LapdmFrame l,
6218 template (value) RslLinkId link_id) runs on ConnHdlr {
6219 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006220 var template (value) SacchL1Header l1h;
6221
6222 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006223 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006224 /* Compose dummy L1 header */
6225 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6226 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 +02006227 } else {
6228 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006229 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 +01006230 }
Harald Welte0472ab42018-03-12 15:02:26 +01006231}
6232
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006233friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006234 uint3_t sapi,
6235 RslLinkId link_id,
6236 octetstring l3,
6237 boolean exp
6238}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006239friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006240friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6241 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006242 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006243 sapi := sapi,
6244 link_id := id,
6245 l3 := l3,
6246 exp := exp
6247}
6248
6249/* execute the same callback function with a set of different parameters (tcs) on a
6250 * variety of logical channels */
6251private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6252 var ConnHdlrPars pars;
6253 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006254 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006255
6256 /* test on each of the channels we have */
6257 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6258 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6259
6260 /* test each of the test cases on the current channel */
6261 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6262 pars.spec.rll := tcs[j];
6263 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6264 vc_conn := f_start_handler(fn, pars);
6265 vc_conn.done;
6266 }
6267 }
6268
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006269 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006270}
6271
6272/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6273private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6274 var RllTestCase tc := g_pars.spec.rll;
6275 timer T := 3.0;
6276
6277 f_l1_tune(L1CTL);
6278 RSL.clear;
6279
6280 /* activate the logical channel */
6281 f_est_dchan();
6282 L1CTL.clear;
6283
6284 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6285 T.start;
6286 alt {
6287 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6288 if (tc.exp) {
6289 setverdict(pass);
6290 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006291 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006292 }
6293 }
6294 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6295 if (tc.exp) {
6296 setverdict(pass);
6297 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006299 }
6300 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006301 /* We also expect to receive the measurements */
6302 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006303 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006304 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006305 }
6306 [not tc.exp] T.timeout {
6307 setverdict(pass);
6308 }
6309 }
6310
6311 f_rsl_chan_deact();
6312 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6313 f_rslem_unregister(0, g_chan_nr);
6314}
6315testcase TC_rll_est_ind() runs on test_CT {
6316 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006317 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006318 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006319 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006320 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006321 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006322 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6323 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006324 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006325 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006326 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006327 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006328 };
6329 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6330}
6331
6332/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6333private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6334 var RllTestCase tc := g_pars.spec.rll;
6335 var L1ctlDlMessage dl;
6336 timer T := 3.0;
6337
6338 f_l1_tune(L1CTL);
6339 RSL.clear;
6340
6341 /* activate the logical channel */
6342 f_est_dchan();
6343 L1CTL.clear;
6344
6345 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6346 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6347 T.start;
6348 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006349 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006350 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006351 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006352 }
6353 }
6354
6355 f_rsl_chan_deact();
6356 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6357 f_rslem_unregister(0, g_chan_nr);
6358}
6359testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6360 var RllTestCases tcs := {
6361 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006362 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006363 };
6364 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6365}
6366testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6367 var RllTestCases tcs := {
6368 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006369 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006370 }
6371 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6372}
6373
6374/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006375friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006376 var L1ctlDlMessage dl;
6377 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6378 var LapdmFrame lapdm;
6379 var octetstring l2 := dl.payload.data_ind.payload;
6380 if (dl.dl_info.link_id.c == SACCH) {
6381 /* remove L1 header */
6382 l2 := substr(l2, 2, lengthof(l2)-2);
6383 }
6384 if (ischosen(exp.ab)) {
6385 lapdm.ab := dec_LapdmFrameAB(l2);
6386 } else if (ischosen(exp.b4)) {
6387 lapdm.b4 := dec_LapdmFrameB4(l2);
6388 } else if (ischosen(exp.bbis)) {
6389 lapdm.bbis := dec_LapdmFrameBbis(l2);
6390 }
6391 log("Rx LAPDm ", lapdm);
6392 if (match(lapdm, exp)) {
6393 setverdict(pass);
6394 } else {
6395 repeat;
6396 }
6397 }
6398 [] L1CTL.receive { repeat; }
6399}
6400private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6401 timer T := t;
6402 T.start;
6403 alt {
6404 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006406 }
6407 [] as_l1_exp_lapdm(exp);
6408 }
6409}
6410
6411/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6412private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6413 /* send SABM from MS -> BTS */
6414 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6415 /* expect RLL EST IND on Abis */
6416 alt {
6417 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6418 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6419 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006420 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006421 }
6422 [] RSL.receive { repeat; }
6423 }
6424 /* expect UA from BTS -> MS */
6425 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6426}
6427
6428/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6429private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6430 var RllTestCase tc := g_pars.spec.rll;
6431
6432 f_l1_tune(L1CTL);
6433 RSL.clear;
6434
6435 /* activate the logical channel */
6436 f_est_dchan();
6437 L1CTL.clear;
6438
6439 /* first establish the link-layer */
6440 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6441
6442 /* then send the DISC */
6443 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6444 /* ... and expect the REL IND on the RSL side */
6445 alt {
6446 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6447 setverdict(pass);
6448 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006449 /* We also expect to receive the measurements */
6450 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006451 }
6452
6453 /* release the channel */
6454 f_rsl_chan_deact();
6455 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6456 f_rslem_unregister(0, g_chan_nr);
6457}
6458testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6459 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006460 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006461 };
6462 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6463}
6464
6465testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6466 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006467 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006468 };
6469 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6470}
6471testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6472 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006473 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006474 };
6475 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6476}
6477testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6478 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006479 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006480 };
6481 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6482}
6483
6484/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6485private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6486 var RllTestCase tc := g_pars.spec.rll;
6487 f_l1_tune(L1CTL);
6488 RSL.clear;
6489
6490 /* activate the logical channel */
6491 f_est_dchan();
6492 L1CTL.clear;
6493
6494 /* first establish the link-layer */
6495 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6496
6497 /* then send the REL REQ via RSL */
6498 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6499 /* ... and expect the DISC on the Um side */
6500 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006501 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006502 /* FIXME: send a UA in resposne to the DISC */
6503 }
6504 }
6505
6506 /* release the channel */
6507 f_rsl_chan_deact();
6508 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6509 f_rslem_unregister(0, g_chan_nr);
6510}
6511testcase TC_rll_rel_req() runs on test_CT {
6512 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006513 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
6514 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
6515 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
6516 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006517 };
6518 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6519}
6520
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006521/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006522testcase TC_rll_data_req() runs on test_CT {
6523}
6524
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006525/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006526testcase TC_rll_data_ind() runs on test_CT {
6527}
6528
6529/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6530private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6531 var RllTestCase tc := g_pars.spec.rll;
6532
6533 f_l1_tune(L1CTL);
6534 RSL.clear;
6535
6536 f_est_dchan();
6537 L1CTL.clear;
6538
6539 /* Send UNITDATA REQ on RSL side */
6540 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6541 /* Expect it to arrive on the other side */
6542 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006543 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006544 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006545 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006546 }
6547
6548 /* release the channel */
6549 f_rsl_chan_deact();
6550 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6551 f_rslem_unregister(0, g_chan_nr);
6552}
6553testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6554 var octetstring l3 := f_rnd_octstring(15);
6555 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006556 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6557 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006558 };
6559 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6560}
6561testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6562 var octetstring l3 := f_rnd_octstring(19);
6563 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006564 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6565 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006566 };
6567 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6568}
6569
6570/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6571private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6572 var RllTestCase tc := g_pars.spec.rll;
6573
6574 f_l1_tune(L1CTL);
6575 RSL.clear;
6576
6577 f_est_dchan();
6578 L1CTL.clear;
6579
6580 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006581 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006582 /* Expdct RLL UNITDATA IND on RSL side */
6583 alt {
6584 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6585 setverdict(pass);
6586 }
6587 [] RSL.receive { repeat; }
6588 }
6589
6590 /* release the channel */
6591 f_rsl_chan_deact();
6592 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6593 f_rslem_unregister(0, g_chan_nr);
6594}
6595testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006596 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006597 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006598 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6599 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006600 };
6601 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6602}
6603testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6604 var octetstring l3 := f_rnd_octstring(18);
6605 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006606 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6607 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006608 };
6609 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6610}
6611
Harald Weltee613f962018-04-18 22:38:16 +02006612/***********************************************************************
6613 * Encryption Related
6614 ***********************************************************************/
6615
6616/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006617private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006618 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6619 if (link_id.c == SACCH) {
6620 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6621 } else {
6622 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6623 }
6624}
6625
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006626/* Expect (or not expect) other kinds of messages */
6627private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6628 [exp_any] RSL.receive { repeat; }
6629 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006631 }
6632}
6633
Harald Weltee613f962018-04-18 22:38:16 +02006634/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006635private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006636 RslLinkId link_id,
6637 octetstring l3,
6638 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006639 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006640) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006641 timer T := 3.0;
6642 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6643 T.start;
6644 /* Expect RLL UNITDATA IND on RSL side */
6645 alt {
6646 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6647 setverdict(pass);
6648 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006649 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006650 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006651 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006652 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006653 }
Harald Weltee613f962018-04-18 22:38:16 +02006654 }
6655}
6656
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006657/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6658private function f_data_mo(
6659 RslLinkId link_id,
6660 boolean p, uint3_t nr, uint3_t ns,
6661 octetstring l3,
6662 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006663 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006664) runs on ConnHdlr {
6665 timer T := 3.0;
6666 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6667 T.start;
6668 /* Expect RLL DATA IND on RSL side */
6669 alt {
6670 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6671 setverdict(pass);
6672 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006673 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006674 [] as_rsl_any_ind(exp_any);
6675 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006676 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006677 }
6678 }
6679}
6680
Harald Weltee613f962018-04-18 22:38:16 +02006681/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006682private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006683 f_l1_tune(L1CTL);
6684 f_est_dchan(true);
6685
6686 /* now we actually need to transmit some data both ways to check if the encryption works */
6687 var L1ctlDlMessage dl;
6688
Stefan Sperling603d98e2018-07-25 16:47:28 +02006689 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006690 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6691
6692 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6693 f_unitdata_mt(link_id, l3);
6694
6695 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6696 f_unitdata_mo(link_id, l3);
6697
6698 /* release the channel */
6699 f_rsl_chan_deact();
6700 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6701 f_rslem_unregister(0, g_chan_nr);
6702}
6703testcase TC_chan_act_a51() runs on test_CT {
6704 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6705 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6706 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6707}
6708testcase TC_chan_act_a52() runs on test_CT {
6709 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6710 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6711 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6712}
6713testcase TC_chan_act_a53() runs on test_CT {
6714 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6715 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6716 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6717}
Eric Wildb9260392021-05-15 19:48:22 +02006718testcase TC_chan_act_a54() runs on test_CT {
6719 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6720 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
6721 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6722}
Harald Weltee613f962018-04-18 22:38:16 +02006723
Eric Wildf1827a72019-05-28 17:37:35 +02006724/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6725 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 +07006726private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006727 f_l1_tune(L1CTL);
6728 f_est_dchan(true);
6729
6730 /* now we actually need to transmit some data both ways to check if the encryption works */
6731 var L1ctlDlMessage dl;
6732
6733 var octetstring l3 := f_rnd_octstring(20);
6734 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6735
6736 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6737 f_unitdata_mt(link_id, l3);
6738
6739 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6740 f_unitdata_mo(link_id, l3);
6741
6742 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006743 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006744
6745 /* modify key to break proper encryption */
6746 g_pars.encr.key := f_rnd_octstring(8);
6747 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6748 rsl.ies := rsl.ies & { ei };
6749 RSL.send(rsl);
6750
6751 timer T0 := 1.0;
6752 T0.start;
6753 /* Expect RSL MODIFY ACK */
6754 alt {
6755 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6756 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6758 }
6759 [] T0.timeout {
6760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6761 }
6762 }
6763
6764 var octetstring l3msg := f_rnd_octstring(15);
6765 timer T1 := 3.0;
6766 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6767 due to broken encryption */
6768 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6769 T1.start;
6770 alt {
6771 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6772 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6773 }
6774 [] T1.timeout {
6775 setverdict(pass);
6776 }
6777 }
6778
6779 /* release the channel */
6780 f_rsl_chan_deact();
6781 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6782 f_rslem_unregister(0, g_chan_nr);
6783}
6784testcase TC_rsl_modify_encr() runs on test_CT {
6785 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6786 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6787 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6788}
Harald Weltee613f962018-04-18 22:38:16 +02006789
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02006790/* Verify RF RESource INDication messages (periodically sent over the RSL) */
6791private function f_TC_rsl_rf_resource_ind(template RSL_ResourceInfo info)
6792runs on test_CT {
6793 const IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
6794 var ASP_RSL_Unitdata ud;
6795 timer T;
6796
6797 /* Intave is 6 SACCH periods by default */
6798 var float Tval := int2float(6 * 480) / 1000.0 + 0.5;
6799
6800 T.start(Tval);
6801 alt {
6802 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(info), sid)) {
6803 setverdict(pass);
6804 }
6805 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND(?), sid)) -> value ud {
6806 setverdict(fail, "RF RESource INDication mismatch: ", ud.rsl);
6807 }
6808 [] RSL_CCHAN.receive { repeat; }
6809 [] T.timeout {
6810 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6811 "Timeout waiting for RF RESource INDication");
6812 }
6813 }
6814}
6815testcase TC_rsl_rf_resource_ind() runs on test_CT {
6816 var RSL_ResourceInfo info := { };
6817
6818 f_init(trx_nr := 0);
6819
6820 f_init_l1ctl();
6821 f_l1_tune(L1CTL);
6822
6823 /* g_AllChannels contains all logical channels */
6824 for (var integer i := 0; i < lengthof(g_AllChannels); i := i + 1) {
6825 var RslChannelNr chan_nr := g_AllChannels[i];
6826
6827 /* FIXME: osmo-bts does not report for Osmocom style dynamic timeslots */
6828 if (mp_trx_pars[0].ts[chan_nr.tn].config == GSM_PCHAN_TCHH_TCHF_PDCH)
6829 { continue; }
6830
6831 info := info & { valueof(ts_RSL_ResourceInfoItem(chan_nr, mp_interf_band)) };
6832 }
6833
6834 /* Align to the first interference report */
6835 f_TC_rsl_rf_resource_ind(?);
6836
6837 /* Test 4 consecutive messages */
6838 for (var integer i := 0; i < 4; i := i + 1) {
6839 f_TC_rsl_rf_resource_ind(info);
6840 }
6841
6842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6843}
6844
Harald Weltee613f962018-04-18 22:38:16 +02006845/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006846private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006847 /* L3 payload doesn't matter, as it is passed transparently */
6848 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6849 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6850 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6851
6852 f_l1_tune(L1CTL);
6853
6854 /* first establish a dedicated channel in the clear */
6855 f_est_dchan(false);
6856
6857 /* Establish ABM */
6858 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6859
6860 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6861 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6862 /* expect the L3 to arrive still unencrypted on the MS side */
6863 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6864
6865 /* configure L1 to apply ciphering */
6866 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6867 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6868
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006869 /* send first ciphered I-frame in response and expect it on RSL */
6870 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006871
6872 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6873 * and hence enable encryption also on the downlink */
6874
6875 /* expect bi-directional communication work in encrypted mode */
6876 f_unitdata_mo(link_id, f_rnd_octstring(15));
6877 f_unitdata_mt(link_id, f_rnd_octstring(15));
6878
6879 /* release the channel */
6880 f_rsl_chan_deact();
6881 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6882 f_rslem_unregister(0, g_chan_nr);
6883}
6884testcase TC_encr_cmd_a51() runs on test_CT {
6885 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6886 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6887 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6888}
6889testcase TC_encr_cmd_a52() runs on test_CT {
6890 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6891 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6892 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6893}
6894testcase TC_encr_cmd_a53() runs on test_CT {
6895 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6896 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6897 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6898}
Eric Wildb9260392021-05-15 19:48:22 +02006899testcase TC_encr_cmd_a54() runs on test_CT {
6900 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6901 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
6902 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6903}
Harald Weltee613f962018-04-18 22:38:16 +02006904
6905private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6906 var LapdmFrame lf;
6907 var octetstring reenc;
6908
6909 /* decode the LAPDm frame */
6910 if (ischosen(exp_match.ab)) {
6911 lf.ab := dec_LapdmFrameAB(enc);
6912 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006914 }
6915
6916 /* check if decoder result matches expectation */
6917 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006919 } else {
6920 log(name, ": matched");
6921 setverdict(pass);
6922 }
6923
6924 /* test if re-encoded frame equals original input */
6925 reenc := enc_LapdmFrame(lf);
6926 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006927 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006928 } else {
6929 setverdict(pass);
6930 }
6931}
6932
6933testcase TC_lapdm_selftest() runs on test_CT {
6934 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6935 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6936 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6937 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6938 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6939 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6940 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6941}
6942
Stefan Sperling4880be42018-08-07 18:12:59 +02006943/***********************************************************************
6944 * DTX Related (see GSM 05.08, section 8.3)
6945 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006946private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006947 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02006948 var GsmFrameNumber first_fn;
6949 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006950 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006951 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006952 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6953 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006954 const integer frame_dtx_tchf_mod := 104;
6955 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6956 * which operates in terms of blocks rather than frames. */
6957 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6958 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006959 timer T := 5.0;
6960
6961 f_l1_tune(L1CTL);
6962 RSL.clear;
6963 L1CTL.clear;
6964
6965 /* activate TCHF signalling channel */
6966 f_est_dchan(false);
6967
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006968 /* A template for matching dummy LAPDm func=UA frames */
6969 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
6970 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
6971 l2_data := f_pad_oct('030301'O, 23, '2B'O));
6972
Stefan Sperling4880be42018-08-07 18:12:59 +02006973 T.start;
6974 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006975 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02006976 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02006977
6978 if (is_first_frame) {
6979 is_first_frame := false;
6980 first_fn := dl.dl_info.frame_nr;
6981 }
6982
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006983 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006984 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006985 T.stop;
6986 f_rsl_chan_deact();
6987 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006988
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006989 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
6990 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006991
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006992 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006993 setverdict(fail, "Not enough fill frames received: ",
6994 nfill_frames, " out of ", expected_fill_frames);
6995 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006996 } else {
6997 setverdict(pass);
6998 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006999 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007000 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
7001 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
7002 * we should only see the subset of frames numbers which correspond to a block boundary.
7003 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
7004 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
7005 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007006 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007007 repeat;
7008 }
7009 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007010 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
7011 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
7012 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007013 f_rsl_chan_deact();
7014 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02007015 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007016 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007017 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007018 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007019 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007020
7021 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007022 /* TCH/F: we expect 24 fill frames for every 104 frames. */
7023 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007024 /* TCH/H: we expect 2 fill frames for every 104 frames. */
7025 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
7026 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007027 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
7028 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07007029 case else {
7030 /* This shall not happen, just to be sure */
7031 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7032 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007033 }
7034
7035 f_rsl_chan_deact();
7036 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02007037
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07007038 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02007039 setverdict(pass);
7040 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07007041 setverdict(fail, "Not enough fill frames received: ",
7042 nfill_frames, " out of ", expected_fill_frames);
7043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02007044 }
7045 } else {
7046 repeat;
7047 }
7048 }
7049 }
7050 [] L1CTL.receive { repeat; }
7051 [] T.timeout {
7052 f_rsl_chan_deact();
7053 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02007054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02007055 }
7056 }
7057}
7058
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07007059private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007060 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02007061 var ConnHdlr vc_conn;
7062 var ConnHdlrPars pars;
7063 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02007064 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007065 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007066 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007067 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007068 if (dtxd) {
7069 if (i >= 4) { /* DTX is only allowed on TCH/F */
7070 break;
7071 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007072 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007073 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007074 vc_conn.done;
7075 }
7076}
7077
7078/* Verify that L2 fill frames are sent on TCH in signaling mode if
7079 * there is nothing to transmit while DTX is disabled on downlink. */
7080testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7081 f_tch_sign_l2_fill_frame(false);
7082}
7083
7084/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7085 * there is nothing to transmit while DTX is enabled on downlink. */
7086testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7087 f_tch_sign_l2_fill_frame(true);
7088}
Harald Welte0472ab42018-03-12 15:02:26 +01007089
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007090testcase TC_chopped_ipa_ping() runs on test_CT {
7091 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7092}
7093
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007094testcase TC_chopped_ipa_payload() runs on test_CT {
7095 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7096}
7097
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007098
7099/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7100 * Return value: Measurement Report to be sent (encoded octetstring). */
7101type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7102 runs on ConnHdlr return octetstring;
7103
7104private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7105runs on ConnHdlr {
7106 var L1ctlDlMessage l1_dl;
7107 var SacchL1Header l1h;
7108 var octetstring l2;
7109
7110 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7111 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7112 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7113 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7114
7115 /* Pass it to the user specified call-back function */
7116 l2 := cb.apply(l1h, num_blocks);
7117 /* Send a Measurement Report generated by the call-back */
7118 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7119 l1_dl.dl_info.link_id,
7120 l1h, l2));
7121
7122 /* Shall we keep going? */
7123 num_blocks := num_blocks - 1;
7124 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7125 if (num_blocks > 0) { repeat; }
7126 }
7127 [] L1CTL.receive { repeat; }
7128}
7129
7130private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7131runs on ConnHdlr return octetstring {
7132 /* Command the L1 to apply received parameters */
7133 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7134
7135 /* Dummy measurement report (the results are invalid) */
7136 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7137}
7138
7139private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7140runs on ConnHdlr return octetstring {
7141 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7142 setverdict(fail, "Unexpected MS Power level change: ",
7143 g_pars.l1_pars.ms_power_level, " -> ",
7144 l1h.ms_power_lvl);
7145 }
7146
7147 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7148}
7149
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007150private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7151runs on ConnHdlr return octetstring {
7152 /* UL RSSI oscillation driven by SACCH block number */
7153 if (num_blocks rem 2 == 0) {
7154 f_trxc_fake_rssi(-100);
7155 } else {
7156 f_trxc_fake_rssi(-50);
7157 }
7158
7159 /* Make sure that MS power level remains constant */
7160 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7161}
7162
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007163/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7164private function f_TC_ms_pwr_ctrl_constant(charstring id)
7165runs on ConnHdlr {
7166 var integer num_blocks := 8;
7167 timer T := int2float(num_blocks);
7168
7169 f_l1_tune(L1CTL);
7170 RSL.clear;
7171
7172 /* These IEs are needed for autonomous MS power control */
7173 var template (value) RSL_IE_List ies := {
7174 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7175 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7176 }),
7177 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7178 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7179 })
7180 };
7181
7182 /* Ensure that 'rx-current' equals 'rx-target' */
7183 f_trxc_fake_rssi(mp_uplink_power_target);
7184
7185 /* Establish a dedicated channel */
7186 f_est_dchan(more_ies := valueof(ies));
7187
7188 L1CTL.clear;
7189 T.start;
7190 alt {
7191 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7192 [] T.timeout {
7193 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7194 num_blocks, " were not handled");
7195 }
7196 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007197
7198 /* Release the channel */
7199 f_rsl_chan_deact();
7200 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007201}
7202testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7203 var ConnHdlr vc_conn;
7204 var ConnHdlrPars pars;
7205
7206 f_init();
7207
7208 /* Explicitly configure the Uplink power target (in dBm) */
7209 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7210
7211 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7212 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7213 log(testcasename(), ": starting on ", pars.chan_nr);
7214
7215 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7216 pars, trxc_comp := true);
7217 vc_conn.done;
7218 }
7219
7220 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7221 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7222}
7223
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007224/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7225private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7226runs on ConnHdlr {
7227 var integer num_blocks := 16;
7228 timer T := int2float(num_blocks);
7229
7230 f_l1_tune(L1CTL);
7231 RSL.clear;
7232
7233 /* These IEs are needed for autonomous MS power control */
7234 var template (value) RSL_IE_List ies := {
7235 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7236 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7237 }),
7238 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7239 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7240 })
7241 };
7242
7243 /* Ensure that 'rx-current' equals 'rx-target' */
7244 f_trxc_fake_rssi(mp_uplink_power_target);
7245
7246 /* Establish a dedicated channel */
7247 f_est_dchan(more_ies := valueof(ies));
7248
7249 L1CTL.clear;
7250 T.start;
7251 alt {
7252 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7253 [] T.timeout {
7254 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7255 num_blocks, " were not handled");
7256 }
7257 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007258
7259 /* Release the channel */
7260 f_rsl_chan_deact();
7261 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007262}
7263testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7264 var ConnHdlr vc_conn;
7265 var ConnHdlrPars pars;
7266
7267 f_init();
7268
7269 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7270 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7271 /* Explicitly configure the Uplink power range (target and delte) */
7272 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7273 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7274
7275 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7276 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7277 log(testcasename(), ": starting on ", pars.chan_nr);
7278
7279 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7280 pars, trxc_comp := true);
7281 vc_conn.done;
7282 }
7283
7284 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7285 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7286}
7287
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007288private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7289 var template L1ctlDlMessage tr_bad_frame;
7290 var L1ctlDlMessage l1_dl;
7291 timer T := 8.0;
7292
7293 f_l1_tune(L1CTL);
7294 RSL.clear;
7295
7296 f_est_dchan();
7297
7298 /* There may be a few errors right after the channel activation */
7299 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7300 L1CTL.clear;
7301
7302 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7303 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7304 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7305 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7306 tr_bad_frame.payload := ?;
7307
7308 T.start;
7309 alt {
7310 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7311 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7312 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7313 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7314 }
7315 [] as_l1_sacch();
7316 [] L1CTL.receive { repeat; }
7317 [] T.timeout {
7318 /* We're done, break the loop */
7319 setverdict(pass);
7320 }
7321 }
7322
7323 f_rsl_chan_deact();
7324 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7325}
7326testcase TC_speech_no_rtp_tchf() runs on test_CT {
7327 var ConnHdlr vc_conn;
7328 var ConnHdlrPars pars;
7329
7330 f_init();
7331
7332 /* TS1, TCH/F, V1 (FR codec) */
7333 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7334 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7335 vc_conn.done;
7336}
7337testcase TC_speech_no_rtp_tchh() runs on test_CT {
7338 var ConnHdlr vc_conn;
7339 var ConnHdlrPars pars;
7340
7341 f_init();
7342
7343 /* TS5, TCH/H, V1 (HR codec) */
7344 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7345 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7346 vc_conn.done;
7347}
7348
Harald Welte0472ab42018-03-12 15:02:26 +01007349/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7350/* protocol error as per 44.006 */
7351/* link layer failure (repetition of I-frame N200 times without ACK */
7352/* repetition of SABM or DISC N200 times without ACK */
7353/* receptiom of SABM in multi-frame established state */
7354
7355
Harald Welte68e495b2018-02-25 00:05:57 +01007356/* TODO Areas:
7357
7358* channel activation
7359** with BS_Power / MS_Power, bypassing power control loop
7360** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007361** with timing advance from initial activation on
7362* mode modify
7363** encryption
7364** multirate
7365* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007366** unsupported algorithm
7367* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007368* BS Power Control
7369* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007370* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007371* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007372** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007373* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007374** DATA_IND from BTS->PCU
7375** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007376
7377*/
Harald Welte70767382018-02-21 12:16:40 +01007378
7379control {
7380 execute( TC_chan_act_stress() );
7381 execute( TC_chan_act_react() );
7382 execute( TC_chan_deact_not_active() );
7383 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007384 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007385 execute( TC_sacch_filling() );
7386 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007387 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007388 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007389 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007390 execute( TC_sacch_chan_act_ho_async() );
7391 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007392 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007393 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007394 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007395 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007396 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007397 execute( TC_rach_load_idle_thresh0() );
7398 execute( TC_rach_load_idle_below_thresh() );
7399 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007400 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02007401 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007402 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02007403 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07007404 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01007405 execute( TC_meas_res_sign_tchf() );
7406 execute( TC_meas_res_sign_tchh() );
7407 execute( TC_meas_res_sign_sdcch4() );
7408 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007409 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007410 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007411 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007412 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007413 execute( TC_rsl_bs_pwr_static_ass() );
7414 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007415 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007416 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007417 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007418 execute( TC_rsl_ms_pwr_dyn_up() );
7419 execute( TC_rsl_ms_pwr_dyn_down() );
7420 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7421 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007422 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007423 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007424 execute( TC_rsl_modify_encr() );
Vadim Yanitskiy98c4a1a2021-06-04 18:46:06 +02007425 execute( TC_rsl_rf_resource_ind() );
Harald Welte70767382018-02-21 12:16:40 +01007426 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007427 execute( TC_paging_imsi_80percent() );
7428 execute( TC_paging_tmsi_80percent() );
7429 execute( TC_paging_imsi_200percent() );
7430 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007431 execute( TC_rsl_protocol_error() );
7432 execute( TC_rsl_mand_ie_error() );
7433 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007434 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007435 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007436 execute( TC_si_sched_2bis() );
7437 execute( TC_si_sched_2ter() );
7438 execute( TC_si_sched_2ter_2bis() );
7439 execute( TC_si_sched_2quater() );
7440 execute( TC_si_sched_13() );
7441 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007442 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007443 execute( TC_ipa_crcx_twice_not_active() );
7444 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007445 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007446 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007447
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007448 if (mp_pcu_socket != "") {
7449 execute( TC_pcu_act_req() );
7450 execute( TC_pcu_act_req_wrong_ts() );
7451 execute( TC_pcu_act_req_wrong_bts() );
7452 execute( TC_pcu_act_req_wrong_trx() );
7453 execute( TC_pcu_deact_req() );
7454 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01007455 execute( TC_pcu_ver_si1() );
7456 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007457 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007458 if (mp_l1_supports_gprs) {
7459 execute( TC_pcu_data_req_pdtch() );
7460 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007461 execute( TC_pcu_data_req_wrong_bts() );
7462 execute( TC_pcu_data_req_wrong_trx() );
7463 execute( TC_pcu_data_req_wrong_ts() );
7464 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007465 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007466 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007467 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007468 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007469 execute( TC_pcu_data_req_imm_ass_pch() );
7470 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007471 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007472 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007473 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007474 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007475 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007476 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007477 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007478 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007479 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007480 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007481 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007482 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007483 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007484 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007485 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007486 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007487 execute( TC_dyn_osmo_pdch_act_deact() );
7488 execute( TC_dyn_osmo_pdch_double_act() );
7489 execute( TC_dyn_ipa_pdch_act_deact() );
7490 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01007491 execute( TC_pcu_info_ind_fh_params() );
7492 execute( TC_pcu_socket_nsvc_ipv4() );
7493 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01007494 execute( TC_pcu_socket_two_nsvc() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007495 } else {
7496 log("PCU socket path not available, skipping PCU tests");
7497 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007498
Harald Welte3d04ae62018-04-04 20:29:05 +02007499 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007500 execute( TC_dyn_osmo_pdch_tchf_act() );
7501 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007502 execute( TC_dyn_ipa_pdch_tchf_act() );
7503 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007504
7505 execute( TC_rll_est_ind() );
7506 execute( TC_rll_est_req_DCCH_3() );
7507 execute( TC_rll_est_req_ACCH_3() );
7508 execute( TC_rll_rel_ind_DCCH_0() );
7509 execute( TC_rll_rel_ind_DCCH_3() );
7510 execute( TC_rll_rel_ind_ACCH_0() );
7511 execute( TC_rll_rel_ind_ACCH_3() );
7512 execute( TC_rll_rel_req() );
7513 execute( TC_rll_unit_data_req_DCCH() );
7514 execute( TC_rll_unit_data_req_ACCH() );
7515 execute( TC_rll_unit_data_ind_DCCH() );
7516 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007517
7518 execute( TC_chan_act_a51() );
7519 execute( TC_chan_act_a52() );
7520 execute( TC_chan_act_a53() );
7521 execute( TC_encr_cmd_a51() );
7522 execute( TC_encr_cmd_a52() );
7523 execute( TC_encr_cmd_a53() );
7524
Harald Welteee25aae2019-05-19 14:32:37 +02007525 execute( TC_err_rep_wrong_mdisc() );
7526 execute( TC_err_rep_wrong_msg_type() );
7527 execute( TC_err_rep_wrong_sequence() );
7528
Harald Weltee613f962018-04-18 22:38:16 +02007529 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007530
7531 execute( TC_tch_sign_l2_fill_frame() );
7532 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007533
7534 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007535 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007536
7537 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007538 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007539
7540 execute( TC_speech_no_rtp_tchf() );
7541 execute( TC_speech_no_rtp_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007542}
7543
7544
7545}