blob: fc714fe19d6d9dba71c0a9f8e3eddfb28283f338 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Alexander Couzens5283f552020-07-28 15:39:04 +020038import from Native_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020040import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010041
42import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010043import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010044import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020045import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010046import from RSL_Emulation all;
47
48import from IPL4asp_Types all;
49import from TRXC_Types all;
50import from TRXC_CodecPort all;
51import from TRXC_CodecPort_CtrlFunct all;
52
Harald Welte883340c2018-02-28 18:59:29 +010053import from PCUIF_Types all;
54import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020055import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010056
Harald Welte7484fc42018-02-24 14:09:45 +010057import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010058import from MobileL3_RRM_Types all;
59import from MobileL3_Types all;
60import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020061import from L3_Common all;
62import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010063
Harald Welte8da48242018-02-27 20:41:32 +010064import from Osmocom_VTY_Functions all;
65import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020066import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010067
Harald Welte505cf9b2018-09-15 17:47:23 +030068friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020069friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020070friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010071friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030072
Harald Welte70767382018-02-21 12:16:40 +010073/* The tests assume a BTS with the following timeslot configuration:
74 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020075 * TS1 : TCH/F
76 * TS2 : TCH/F
77 * TS3 : TCH/F_PDCH (IPA Style)
78 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010079 * TS5 : TCH/H
80 * TS6 : SDCCH/8
81 * TS7 : PDCH
82 */
83
84modulepar {
85 charstring mp_rsl_ip := "127.0.0.2";
86 integer mp_rsl_port := 3003;
87 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +070088 integer mp_trx1_arfcn := 873;
89 integer mp_trx2_arfcn := 875;
90 integer mp_trx3_arfcn := 877;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070091 charstring mp_bts_trxc_ip := "127.0.0.1";
92 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010093 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020094 charstring mp_ctrl_ip := "127.0.0.1";
95 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020096 charstring mp_bsc_ctrl_ip := "127.0.0.1";
97 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020098 integer mp_tolerance_rxqual := 1;
99 integer mp_tolerance_rxlev := 3;
100 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200101 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200102 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200103 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200104 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
105 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 +0200106 integer mp_ms_actual_ta_exp := 0;
107 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700108 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700109 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100110 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200111 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200112 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200113 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
114 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700115 /* how many transceivers do we expect to connect */
116 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700117 /* frequency hopping status */
118 boolean mp_freq_hop_enabled := false;
119 /* frequency hopping parameters */
120 FreqHopConfig mp_fh_config;
Harald Welte70767382018-02-21 12:16:40 +0100121}
122
Harald Welte629cc6b2018-03-11 17:19:05 +0100123type record of RslChannelNr ChannelNrs;
124
Harald Welte70767382018-02-21 12:16:40 +0100125type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100126 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100127 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100128 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100129 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100130 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100131 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100132
133 /* L1CTL port (for classic tests) */
134 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100135
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700136 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700137 port TRXC_CODEC_PT BTS_TRXC;
138 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100139
Harald Weltef50e3ae2018-09-10 10:27:56 +0200140 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100141 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200142 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100143
Harald Welte883340c2018-02-28 18:59:29 +0100144 /* PCU Interface of BTS */
145 port PCUIF_CODEC_PT PCU;
146 var integer g_pcu_conn_id;
147 /* Last PCU INFO IND we received */
148 var PCUIF_Message g_pcu_last_info;
149
Harald Welte48494ca2018-02-25 16:59:50 +0100150 /* SI configuration */
151 var SystemInformationConfig si_cfg := {
152 bcch_extended := false,
153 si1_present := false,
154 si2bis_present := false,
155 si2ter_present := false,
156 si2quater_present := false,
157 si7_present := false,
158 si8_present := false,
159 si9_present := false,
160 si13_present := false,
161 si13alt_present := false,
162 si15_present := false,
163 si16_present := false,
164 si17_present := false,
165 si2n_present := false,
166 si21_present := false,
167 si22_present := false
168 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100169
170 /* all logical channels available on the BTS */
171 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100172 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100173}
174
175/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200176type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100177 port L1CTL_PT L1CTL;
178
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700179 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700180 port TRXC_CODEC_PT BTS_TRXC;
181 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100182
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200183 /* port to be initialized optionally to access BSC VTY */
184 port TELNETasp_PT BSCVTY;
185
Harald Welte70767382018-02-21 12:16:40 +0100186 timer g_Tguard;
187 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
188
189 var ConnHdlrPars g_pars;
190 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100191 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200192
193 /* PCU Interface of BTS */
194 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100195}
196
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700197private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700198 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200199 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700200 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200201 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700202 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200203 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700204 timer T;
205
Harald Welte70767382018-02-21 12:16:40 +0100206 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
207 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
208
209 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
210 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
211 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
212
213 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
214 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700215
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700216 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700217 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700218 T.start(mp_ipa_up_timeout);
219 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700220 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700221 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
222 /* Make sure that all transceivers use unique stream ID */
223 if (trx_mask[enum2int(ev.sid)] == '1'B) {
224 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
225 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
226 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700227
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700228 trx_mask[enum2int(ev.sid)] := '1'B;
229 trx_count := trx_count + 1;
230
231 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200232 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700233 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200234 /* This message (RF RESource INDication) is sent by the IUT itself */
235 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
236 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
238 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
239 }
240 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
242 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
243 }
244
245 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
246 rfind_count := rfind_count + 1;
247 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
248 if (rfind_count < mp_transceiver_num) { repeat; }
249 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700250 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
251 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
252 [] T.timeout {
253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
254 "Timeout waiting for RSL bring up");
255 }
256 }
Harald Welte70767382018-02-21 12:16:40 +0100257}
258
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700259friend type record FreqHopPars {
260 /* Whether frequency hopping is in use */
261 boolean enabled,
262 /* Mobile Allocation Index Offset / Hopping Sequence Number */
263 MaioHsn maio_hsn,
264 /* MA bitmap to be indicated in RR Immediate Assignment */
265 MobileAllocationLV ma_map,
266 /* The actual Mobile Allocation (ARFCN list) to be used */
267 L1ctlMA ma
268};
269
Harald Welte70767382018-02-21 12:16:40 +0100270type record ConnHdlrPars {
271 RslChannelNr chan_nr,
272 RSL_IE_ChannelMode chan_mode,
273 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100274 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200275 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200276 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700277 BtsBand bts0_band optional,
278
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700279 /* Frequency hopping parameters */
280 FreqHopPars fhp
281};
Harald Welte0472ab42018-03-12 15:02:26 +0100282
283/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700284private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100285 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100286}
287
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700288private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100289 max_retrans := RACH_MAX_RETRANS_7,
290 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100291 cell_barr_access := false,
292 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100293 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100294};
295
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700296private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100297 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200298 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100299 acs := '0'B,
300 neci := true,
301 rxlev_access_min := 0
302}
303
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700304private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100305 mcc_mnc := '262F42'H,
306 lac := 42
307}
308
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700309private template (value) GPRSIndicator ts_GPRSIndicator_def := {
310 ra_colour := 0,
311 si13_pos := '0'B
312}
313
314private template (value) SI3RestOctets ts_SI3RestOctets_def
315modifies ts_SI3RestOctets := {
316 gprs_ind := {
317 presence := CSN1_H,
318 ind := ts_GPRSIndicator_def
319 }
320}
321
322private template (value) SI4RestOctets ts_SI4RestOctets_def
323modifies ts_SI4RestOctets := {
324 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700325 presence := CSN1_H,
326 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700327 }
328}
329
Harald Welte7484fc42018-02-24 14:09:45 +0100330/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700331private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100332 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100333 payload := {
334 si3 := {
335 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100336 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100337 ctrl_chan_desc := {
338 msc_r99 := true,
339 att := true,
340 bs_ag_blks_res := 1,
341 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100342 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100343 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
344 spare := '00'B,
345 bs_pa_mfrms := 0, /* 2 multiframes */
346 t3212 := 1 /* 6 minutes */
347 },
Harald Welte82ccef72018-02-25 16:17:33 +0100348 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100349 dn_ind := false,
350 pwrc := false,
351 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100352 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100353 },
Harald Weltef10153f2018-02-25 16:34:05 +0100354 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100355 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200356 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100357 }
358 }
359}
Harald Welte70767382018-02-21 12:16:40 +0100360
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700361private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100362 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100363 payload := {
364 si2 := {
365 bcch_freq_list := '00000000000000000000000000000000'O,
366 ncc_permitted := '11111111'B,
367 rach_control := ts_RachCtrl_default
368 }
369 }
370}
371
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700372private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100373 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100374 payload := {
375 si4 := {
376 lai := ts_LAI_default,
377 cell_sel_par := ts_CellSelPar_default,
378 rach_control := ts_RachCtrl_default,
379 cbch_chan_desc := omit,
380 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200381 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100382 }
383 }
384}
385
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700386private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100387runs on test_CT {
388 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700389 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100390}
391
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700392private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100393runs on test_CT {
394 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
395 log("Setting ", rsl_si_type, ": ", si_dec);
396 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
397}
398
Harald Welte505cf9b2018-09-15 17:47:23 +0300399friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100400 map(self:BTSVTY, system:BTSVTY);
401 f_vty_set_prompts(BTSVTY);
402 f_vty_transceive(BTSVTY, "enable");
403}
404
Harald Welte505cf9b2018-09-15 17:47:23 +0300405friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200406 map(self:BSCVTY, system:BSCVTY);
407 f_vty_set_prompts(BSCVTY, "OsmoBSC");
408 f_vty_transceive(BSCVTY, "enable");
409}
410
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200411friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
412 map(self:BSCVTY, system:BSCVTY);
413 f_vty_set_prompts(BSCVTY, "OsmoBSC");
414 f_vty_transceive(BSCVTY, "enable");
415}
416
Harald Welte883340c2018-02-28 18:59:29 +0100417/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200418private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
419 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100420 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200421 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
422 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100423 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200424 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100426 }
427}
428
Harald Weltef26de0b2018-04-04 20:28:05 +0200429private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
430 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100431 timer T := 2.0;
432 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100433 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200434 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100435 return;
436 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200437 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100438
439 T.start;
440 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200441 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100442 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100444 }
445 }
446}
447
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700448private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
449 out integer trxc_conn_id) {
450 var Result res;
451
452 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
453 "", -1, -1, { udp := {} }, {});
454 if (not ispresent(res.connId)) {
455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
456 "Could not connect to the control (TRXC) interface " &
457 "of FakeTRX, check your configuration");
458 }
459 trxc_conn_id := res.connId;
460}
461
Harald Welte70767382018-02-21 12:16:40 +0100462/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700463friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200464 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100465 g_AllChannels := {
466 /* TS 1..4: TCH/F */
467 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
468 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
469 /* TS 5: TCH/H */
470 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
471 /* TS 0: SDCCH/4 */
472 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
473 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
474 /* TS 6: SDCCH/8 */
475 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
476 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
477 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
478 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
479 };
480
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200481 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700482 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200483 g_AllChanTypes := {
484 /* TS 1..4: TCH/F */
485 valueof(ts_RslChanNr_Bm(1)),
486 /* TS 5: TCH/H */
487 valueof(ts_RslChanNr_Lm(5,1)),
488 /* TS 0: SDCCH/4 */
489 valueof(ts_RslChanNr_SDCCH4(0,2)),
490 /* TS 6: SDCCH/8 */
491 valueof(ts_RslChanNr_SDCCH8(6,4))
492 };
493 } else {
494 g_AllChanTypes := {
495 /* TS 1..4: TCH/F */
496 valueof(ts_RslChanNr_Bm(1)),
497 /* TS 0: SDCCH/4 */
498 valueof(ts_RslChanNr_SDCCH4(0,2)),
499 /* TS 6: SDCCH/8 */
500 valueof(ts_RslChanNr_SDCCH8(6,4))
501 };
502 }
Harald Welte70767382018-02-21 12:16:40 +0100503 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100504 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100505 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200506 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100507
508 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100509 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
510 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
511 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
512 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100513
Harald Weltef26de0b2018-04-04 20:28:05 +0200514 map(self:PCU, system:PCU);
515 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100516
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700517 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100518 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700519
520 /* Init TRXC interface to FakeTRX */
521 map(self:BTS_TRXC, system:BTS_TRXC);
522 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
523
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700524 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700525 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 +0700526 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700527 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
528 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100529 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200530
531 /* Wait some extra time to make sure the BTS emits a stable carrier.
532 * (this is only relevant when running the tests with a physical BTS.) */
533 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100534}
535
Harald Welte68e495b2018-02-25 00:05:57 +0100536/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700537friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100538 map(self:L1CTL, system:L1CTL);
539 f_connect_reset(L1CTL);
540}
541
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700542private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100543
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700544private type record length(8) of FreqHopGroups FreqHopConfig;
545
546private type record of FreqHopGroup FreqHopGroups;
547private type record FreqHopGroup {
548 uint6_t hsn,
549 FreqHopGroupItems trx_maio
550};
551
552private type record of FreqHopGroupItem FreqHopGroupItems;
553private type record FreqHopGroupItem {
554 uint8_t trx_nr,
555 uint6_t maio
556};
557
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700558friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
559 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700560{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700561 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700562 var integer i, j;
563
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700564 fhp.enabled := false;
565
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700566 for (i := 0; i < lengthof(groups); i := i + 1) {
567 var FreqHopGroup g := groups[i];
568 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
569 var FreqHopGroupItem gi := g.trx_maio[j];
570 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700571 fhp.maio_hsn.maio := gi.maio;
572 fhp.maio_hsn.hsn := g.hsn;
573 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700574 break;
575 }
576 }
577
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700578 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700579 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700580 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
581 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
582 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700583
584 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700585 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
586 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700587 fhp.ma := fhp.ma & { l1ctl_ma_def[gi.trx_nr] };
588 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700589 }
590
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700591 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700592 break; /* We're done */
593 }
594 }
595}
596
Harald Welte70767382018-02-21 12:16:40 +0100597/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700598friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
599 boolean pcu_comp := false,
600 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100601runs on test_CT return ConnHdlr {
602 var charstring id := testcasename();
603 var ConnHdlr vc_conn;
604
605 vc_conn := ConnHdlr.create(id);
606 /* connect to RSL Emulation main component */
607 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
608 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700609
610 /* The ConnHdlr component may want to talk to some ports directly,
611 * so we disconnect it from the test_CT and connect it to the component.
612 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200613 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200614 unmap(self:PCU, system:PCU);
615 map(vc_conn:PCU, system:PCU);
616 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700617 if (trxc_comp) {
618 unmap(self:BTS_TRXC, system:BTS_TRXC);
619 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
620 }
Harald Welte70767382018-02-21 12:16:40 +0100621
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700622 /* Obtain frequency hopping parameters for a given timeslot */
623 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700624 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700625 }
626
Harald Welte70767382018-02-21 12:16:40 +0100627 vc_conn.start(f_handler_init(fn, id, pars));
628 return vc_conn;
629}
630
Harald Welte70767382018-02-21 12:16:40 +0100631private altstep as_Tguard() runs on ConnHdlr {
632 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200633 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100634 }
635}
636
Harald Welte990a3612019-05-27 14:02:13 +0200637friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
638 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100639}
640
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700641private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100642 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700643 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100644}
645
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700646private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100647 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700648 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100649}
650
651/* first function started in ConnHdlr component */
652private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
653runs on ConnHdlr {
654 g_pars := pars;
655 g_chan_nr := pars.chan_nr;
656
657 map(self:L1CTL, system:L1CTL);
658 f_connect_reset(L1CTL);
659
Harald Welted48c0c72019-06-05 10:01:15 +0200660 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700661 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100662 }
Harald Welte70767382018-02-21 12:16:40 +0100663
664 g_Tguard.start(pars.t_guard);
665 activate(as_Tguard());
666
667 f_rslem_register(0, pars.chan_nr);
668
669 /* call the user-supplied test case function */
670 fn.apply(id);
671}
672
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700673private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
674 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200675runs on ConnHdlr return RSL_Message {
676 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100677 timer T := 3.0;
678 RSL.send(tx);
679 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100680 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200681 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100682 T.stop;
683 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100684 }
Harald Welte1eba3742018-02-25 12:48:14 +0100685 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100687 }
Harald Welte21240e62018-03-11 21:43:35 +0100688 [not ignore_other] as_l1_sacch();
689 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700690 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700691 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100692 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100694 }
Harald Welte21240e62018-03-11 21:43:35 +0100695 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100696 }
Harald Welteb1726c92018-03-30 11:56:38 +0200697 return rx;
698}
699
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700700friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
701 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200702runs on ConnHdlr {
703 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100704}
705
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700706friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
707 boolean encr_enable := false,
708 RSL_IE_List more_ies := {},
709 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
710runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200711 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200712 if (encr_enable) {
713 /* append encryption related IEs, if requested */
714 var RSL_IE_EncryptionInfo encr_info;
715 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
716 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
717encr_info})) };
718 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200719 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200720 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100721}
722
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700723friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100724 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 +0100725 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100726}
727
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700728/* Default Mobile Allocation to be used for frequency hopping */
729private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
730 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
731
Harald Welte2f2b2b72019-05-31 22:24:57 +0200732friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100733 template RSL_IE_ChannelMode chan_mode,
734 float t_guard := 20.0) := {
735 chan_nr := valueof(chan_nr),
736 chan_mode := valueof(chan_mode),
737 t_guard := t_guard,
738 l1_pars := {
739 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100740 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100741 meas_ul := {
742 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200743 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100744 rxqual := 0
745 },
746 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200747 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100748 rxqual := 0
749 }
750 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200751 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100752 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200753 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200754 ms_actual_ta := mp_ms_actual_ta_exp,
755 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100756 },
Harald Weltee613f962018-04-18 22:38:16 +0200757 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200758 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700759 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700760 fhp := {
761 enabled := false,
762 maio_hsn := ts_HsnMaio(0, 0),
763 ma_map := c_MA_null,
764 ma := l1ctl_ma_def
765 }
Harald Welte70767382018-02-21 12:16:40 +0100766}
767
Harald Welte93640c62018-02-25 16:59:33 +0100768/***********************************************************************
769 * Channel Activation / Deactivation
770 ***********************************************************************/
771
Harald Welte70767382018-02-21 12:16:40 +0100772/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700773private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100774 for (var integer i := 0; i < 500; i := i+1) {
775 f_rsl_chan_act(g_pars.chan_mode);
776 f_rsl_chan_deact();
777 }
778 setverdict(pass);
779}
780testcase TC_chan_act_stress() runs on test_CT {
781 var ConnHdlr vc_conn;
782 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200783 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100784 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
785 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100787}
788
789/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700790private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100791 f_rsl_chan_act(g_pars.chan_mode);
792 /* attempt to activate the same lchan again -> expect reject */
793 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
794 alt {
795 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100797 }
798 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
799 setverdict(pass);
800 }
801 }
802 f_rsl_chan_deact();
803}
804testcase TC_chan_act_react() runs on test_CT {
805 var ConnHdlr vc_conn;
806 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100807 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100808 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
809 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200810 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100811}
812
813/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700814private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100815 timer T := 3.0;
816 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
817 T.start;
818 alt {
819 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
820 setverdict(pass);
821 }
822 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100824 }
825 }
826}
827testcase TC_chan_deact_not_active() runs on test_CT {
828 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100829 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100830 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
831 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100833}
834
835/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700836private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100837 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
838 alt {
839 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200840 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100841 }
842 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
843 setverdict(pass);
844 }
845 }
846}
847private type record WrongChanNrCase {
848 RslChannelNr chan_nr,
849 charstring description
850}
851private type record of WrongChanNrCase WrongChanNrCases;
852private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
853 chan_nr := chan_nr,
854 description := desc
855}
856
857testcase TC_chan_act_wrong_nr() runs on test_CT {
858 var ConnHdlr vc_conn;
859 var ConnHdlrPars pars;
860
Harald Welte294b0a22018-03-10 23:26:48 +0100861 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100862
863 var WrongChanNrCases wrong := {
864 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
865 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
866 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
867 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
868 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
869 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
870 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
871 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
872 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
873 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
874 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
875 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
876 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
877 };
878
879 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
880 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
881 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
882 vc_conn.done;
883 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200884 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100885}
886
Harald Weltee613f962018-04-18 22:38:16 +0200887/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200888friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200889 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200890 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200891
892 /* test on each of the channels we have */
893 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
894 pars.chan_nr := valueof(g_AllChanTypes[i]);
895
896 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
897 vc_conn := f_start_handler(fn, pars);
898 vc_conn.done;
899 }
900
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200902}
903
Harald Welte93640c62018-02-25 16:59:33 +0100904/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100905 * SACCH handling
906 ***********************************************************************/
907
908private function f_exp_sacch(boolean exp) runs on ConnHdlr {
909 timer T_sacch := 3.0;
910 T_sacch.start;
911 alt {
912 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100914 }
915 [not exp] T_sacch.timeout {
916 setverdict(pass);
917 }
918 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
919 setverdict(pass);
920 }
921 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200922 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100923 }
924 [] L1CTL.receive { repeat; }
925 [] RSL.receive { repeat; }
926 }
927}
928
929/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
930private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
931 f_l1_tune(L1CTL);
932 RSL.clear;
933
934 /* activate the logical channel */
935 f_est_dchan();
936 L1CTL.clear;
937
938 /* check that SACCH actually are received as expected */
939 f_exp_sacch(true);
940
941 /* deactivate SACCH on the logical channel */
942 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
943 f_sleep(1.0);
944 L1CTL.clear;
945
946 /* check that no SACCH are received anymore */
947 f_exp_sacch(false);
948
949 /* release the channel */
950 f_rsl_chan_deact();
951 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
952}
953testcase TC_deact_sacch() runs on test_CT {
954 var ConnHdlr vc_conn;
955 var ConnHdlrPars pars;
956 f_init();
957 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
958 //for (var integer i := 0; i < 1; i := i+1) {
959 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
960 log(testcasename(), ": Starting for ", g_AllChannels[i]);
961 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
962 vc_conn.done;
963 }
964 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200965 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100966}
967
Harald Welte55700662018-03-12 13:15:43 +0100968/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100969private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
970 var L1ctlDlMessage dl;
971 /* check that the specified SI5 value is actually sent */
972 timer T_sacch := 3.0;
973 L1CTL.clear;
974 T_sacch.start;
975 alt {
976 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
977 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
978 if (match(l3, l3_exp)) {
979 setverdict(pass);
980 } else {
981 repeat;
982 }
983 }
984 [] L1CTL.receive { repeat; }
985 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100987 }
988 }
989}
990
Harald Welte55700662018-03-12 13:15:43 +0100991/* verify that given SACCH payload is not present */
992private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
993 var L1ctlDlMessage dl;
994 /* check that the specified SI5 value is actually sent */
995 timer T_sacch := 3.0;
996 L1CTL.clear;
997 T_sacch.start;
998 alt {
999 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1000 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1001 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001003 } else {
1004 repeat;
1005 }
1006 }
1007 [] L1CTL.receive { repeat; }
1008 [] T_sacch.timeout {
1009 setverdict(pass);
1010 }
1011 }
1012}
1013
Harald Welte629cc6b2018-03-11 17:19:05 +01001014/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001015private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1016 /* Set a known default SACCH filling for SI5 */
1017 var octetstring si5 := f_rnd_octstring(19);
1018 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1019
1020 f_l1_tune(L1CTL);
1021 RSL.clear;
1022
1023 /* activate the logical channel */
1024 f_est_dchan();
1025
1026 /* check that the specified SI5 value is actually sent */
1027 f_sacch_present(si5);
1028
1029 /* release the channel */
1030 RSL.clear;
1031 f_rsl_chan_deact();
1032 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1033}
1034testcase TC_sacch_filling() runs on test_CT {
1035 var ConnHdlr vc_conn;
1036 var ConnHdlrPars pars;
1037 f_init();
1038 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1039 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1040 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1041 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1042 vc_conn.done;
1043 }
1044 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001045 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001046}
1047
Harald Welte629cc6b2018-03-11 17:19:05 +01001048/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001049private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1050 /* Set a known default SACCH filling for SI5 */
1051 var octetstring si5 := f_rnd_octstring(19);
1052 var octetstring si5_diff := f_rnd_octstring(19);
1053 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1054
1055 f_l1_tune(L1CTL);
1056 RSL.clear;
1057
1058 log("Activating channel, expecting standard SI5");
1059 /* activate the logical channel */
1060 f_est_dchan();
1061 /* check that the specified SI5 value is actually sent */
1062 f_sacch_present(si5);
1063
1064 /* set channel-specific different SI5 */
1065 log("Setting channel specific SACCH INFO, expecting it");
1066 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1067 /* check that the specified lchan-specific value is now used */
1068 f_sacch_present(si5_diff);
1069
1070 /* deactivate the channel and re-activate it, this should result in default SI5 */
1071 log("De-activating and re-activating channel, expecting standard SI5");
1072 f_rsl_chan_deact();
1073 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1074 /* Verify that the TRX-wide default SACCH filling is present again */
1075 f_sacch_present(si5);
1076
1077 /* release the channel */
1078 RSL.clear;
1079 f_rsl_chan_deact();
1080 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1081}
1082testcase TC_sacch_info_mod() runs on test_CT {
1083 var ConnHdlr vc_conn;
1084 var ConnHdlrPars pars;
1085 f_init();
1086 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1087 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1088 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1089 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1090 vc_conn.done;
1091 }
1092 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001094}
1095
Harald Welte075d84c2018-03-12 13:07:24 +01001096/* Test SACCH scheduling of multiple different SI message types */
1097private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1098 var octetstring si5 := f_rnd_octstring(19);
1099 var octetstring si5bis := f_rnd_octstring(19);
1100 var octetstring si5ter := f_rnd_octstring(19);
1101 var octetstring si6 := f_rnd_octstring(19);
1102
1103 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1104 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1105 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1106 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1107
1108 f_l1_tune(L1CTL);
1109 RSL.clear;
1110
1111 /* activate the logical channel */
1112 f_est_dchan();
1113 L1CTL.clear;
1114
1115 /* check that SACCH actually are received as expected */
1116 f_sacch_present(si5);
1117 f_sacch_present(si5bis);
1118 f_sacch_present(si5ter);
1119 f_sacch_present(si6);
1120
1121 /* release the channel */
1122 f_rsl_chan_deact();
1123 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1124}
1125testcase TC_sacch_multi() runs on test_CT {
1126 var ConnHdlr vc_conn;
1127 var ConnHdlrPars pars;
1128 f_init();
1129 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1130 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1131 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1132 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1133 vc_conn.done;
1134 }
1135 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001136 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001137}
1138
Harald Welte55700662018-03-12 13:15:43 +01001139/* Test if SACH information is modified as expected */
1140private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1141 var octetstring si5 := f_rnd_octstring(19);
1142 var octetstring si6 := f_rnd_octstring(19);
1143
1144 /* First, configure both SI5 and SI6 to be transmitted */
1145 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1146 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1147
1148 f_l1_tune(L1CTL);
1149 RSL.clear;
1150
1151 /* activate the logical channel */
1152 f_est_dchan();
1153 L1CTL.clear;
1154
1155 /* check that SACCH actually are received as expected */
1156 f_sacch_present(si5);
1157 f_sacch_present(si6);
1158
1159 /* disable SI6 */
1160 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1161
1162 /* check that SI5 is still transmitted */
1163 f_sacch_present(si5);
1164 /* check if SI6 is now gone */
1165 f_sacch_missing(si6);
1166
1167 /* release the channel */
1168 f_rsl_chan_deact();
1169 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1170}
1171testcase TC_sacch_multi_chg() runs on test_CT {
1172 var ConnHdlr vc_conn;
1173 var ConnHdlrPars pars;
1174 f_init();
1175 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1176 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1177 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1178 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1179 vc_conn.done;
1180 }
1181 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001183}
1184
Harald Weltec8d363c2019-05-19 20:36:48 +02001185/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1186private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1187 var octetstring si5 := f_rnd_octstring(19);
1188 var octetstring si6 := f_rnd_octstring(19);
1189 var octetstring si5_specific := f_rnd_octstring(19);
1190 var octetstring si6_specific := f_rnd_octstring(19);
1191
1192 /* First, configure both SI5 and SI6 to be transmitted */
1193 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1194 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1195
1196 f_l1_tune(L1CTL);
1197 RSL.clear;
1198
1199 /* activate channel with different SACCH filling */
1200 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1201 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1202 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1203 }));
1204 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1205 RSL_IE_Body:{sacch_info := sacch_info})) };
1206 f_est_dchan(more_ies := addl_ies);
1207
1208 /* check that SACCH actually are received as expected */
1209 f_sacch_present(si5_specific);
1210 f_sacch_present(si6_specific);
1211
1212 /* release the channel */
1213 f_rsl_chan_deact();
1214 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1215}
1216testcase TC_sacch_chan_act() runs on test_CT {
1217 var ConnHdlr vc_conn;
1218 var ConnHdlrPars pars;
1219 f_init();
1220
1221 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1222 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1223 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1224 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1225 vc_conn.done;
1226 }
1227 /* TODO: do the above in parallel, rather than sequentially? */
1228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1229}
1230
Harald Welte8b01c792019-05-19 22:51:25 +02001231/* verify that SACCH DL transmission is started only if MS power IE present
1232 * see section 4.1.3 of 3GPP TS 48.058 */
1233private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1234 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001235 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001236
1237 f_l1_tune(L1CTL);
1238 RSL.clear;
1239
1240 /* Step 1: Activate ASYNC HO channel without MS power IE */
1241
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001242 var integer ho_ref := oct2int(f_rnd_octstring(1));
1243 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1244 RSL_IE_Body:{ handover_ref := ho_ref }));
1245 var RSL_IE_List addl_ies := {
1246 ho_ref_ie
1247 };
1248
Harald Welte8b01c792019-05-19 22:51:25 +02001249 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001250 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 +02001251 /* don't perform immediate assignment here, as we're testing non-IA case */
1252 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001253 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001254
1255 /* Verify that no DL SACCH is being received */
1256 f_sacch_missing(?);
1257
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001258 /* Send handover Access Burst and expect SACCH to start */
1259 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1260
1261 f_sacch_present(si5);
1262
Harald Welte8b01c792019-05-19 22:51:25 +02001263 f_rsl_chan_deact();
1264 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1265
1266
1267 /* Step 2: Activate ASYNC HO channel with MS power IE */
1268
1269 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001270 addl_ies := {
1271 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001272 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1273 };
1274 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1275 /* don't perform immediate assignment here, as we're testing non-IA case */
1276 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001277 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001278
1279 /* Verify that DL SACCH is being received */
1280 f_sacch_present(si5);
1281
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001282 /* Send handover Access Burst and expect SACCH to remain present */
1283 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1284
1285 f_sacch_present(si5);
1286
Harald Welte8b01c792019-05-19 22:51:25 +02001287 f_rsl_chan_deact();
1288 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1289}
1290testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1291 var ConnHdlr vc_conn;
1292 var ConnHdlrPars pars;
1293 f_init();
1294
1295 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1296 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1297 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1298 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1299 vc_conn.done;
1300 }
1301 /* TODO: do the above in parallel, rather than sequentially? */
1302 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1303}
1304
1305/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1306 * see section 4.1.4 of 3GPP TS 48.058 */
1307private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1308 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001309 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1310
Harald Welte8b01c792019-05-19 22:51:25 +02001311 var RSL_IE_List addl_ies;
1312
1313 f_l1_tune(L1CTL);
1314 RSL.clear;
1315
1316 /* Step 1: Activate SYNC HO channel without MS power IE */
1317
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001318 var integer ho_ref := oct2int(f_rnd_octstring(1));
1319 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1320 RSL_IE_Body:{ handover_ref := ho_ref }));
1321 addl_ies := {
1322 ho_ref_ie
1323 };
1324
Harald Welte8b01c792019-05-19 22:51:25 +02001325 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001326 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 +02001327 /* don't perform immediate assignment here, as we're testing non-IA case */
1328 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001329 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001330
1331 /* Verify that no DL SACCH is being received */
1332 f_sacch_missing(?);
1333
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001334 /* Send handover Access Burst and expect SACCH to start */
1335 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1336
1337 f_sacch_present(si5);
1338
Harald Welte8b01c792019-05-19 22:51:25 +02001339 f_rsl_chan_deact();
1340 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1341
1342
1343 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1344
1345 /* Activate channel on BTS side */
1346 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001347 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001348 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1349 };
1350 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1351 /* don't perform immediate assignment here, as we're testing non-IA case */
1352 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001353 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001354
1355 /* Verify that no DL SACCH is being received */
1356 f_sacch_missing(?);
1357
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001358 /* Send handover Access Burst and expect SACCH to start */
1359 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1360
1361 f_sacch_present(si5);
1362
Harald Welte8b01c792019-05-19 22:51:25 +02001363 f_rsl_chan_deact();
1364 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1365
1366
1367 /* Step 2b: Activate SYNC HO channel with TA IE */
1368
1369 /* Activate channel on BTS side */
1370 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001371 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001372 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1373 };
1374 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1375 /* don't perform immediate assignment here, as we're testing non-IA case */
1376 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001377 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001378
1379 /* Verify that no DL SACCH is being received */
1380 f_sacch_missing(?);
1381
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001382 /* Send handover Access Burst and expect SACCH to start */
1383 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1384
1385 f_sacch_present(si5);
1386
Harald Welte8b01c792019-05-19 22:51:25 +02001387 f_rsl_chan_deact();
1388 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1389
1390
1391 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1392
1393 /* Activate channel on BTS side */
1394 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001395 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001396 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1397 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1398 };
1399 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1400 /* don't perform immediate assignment here, as we're testing non-IA case */
1401 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001402 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001403
1404 /* Verify that DL SACCH is being received */
1405 f_sacch_present(si5);
1406
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001407 /* Send handover Access Burst and expect SACCH to remain present */
1408 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1409
1410 f_sacch_present(si5);
1411
Harald Welte8b01c792019-05-19 22:51:25 +02001412 f_rsl_chan_deact();
1413 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1414}
1415testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1416 var ConnHdlr vc_conn;
1417 var ConnHdlrPars pars;
1418 f_init();
1419
1420 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1421 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1422 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1423 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1424 vc_conn.done;
1425 }
1426 /* TODO: do the above in parallel, rather than sequentially? */
1427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1428}
Harald Welte629cc6b2018-03-11 17:19:05 +01001429
1430
1431/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001432 * RACH Handling
1433 ***********************************************************************/
1434
Harald Welte8c24c2b2018-02-26 08:31:31 +01001435/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001436private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001437 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001438 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001439 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001440
Harald Welte8c24c2b2018-02-26 08:31:31 +01001441 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001442 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001443 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001444 var OCT1 ra := f_rnd_ra_emerg();
1445 if (emerg == true) {
1446 ra := f_rnd_ra_emerg();
1447 } else {
1448 ra := f_rnd_ra_cs();
1449 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001450 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1451 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001452 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001453 }
1454 fn_last := fn;
1455
1456 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001457 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001458 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001459 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001460 T.stop;
1461 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001462 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001464 }
1465 [] RSL_CCHAN.receive { repeat; }
1466 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001467 test_failed := true;
1468 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001469 }
1470 }
1471 }
Maxba06feb2019-03-05 10:52:46 +01001472 if (test_failed) {
1473 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001474 }
Maxba06feb2019-03-05 10:52:46 +01001475 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001477}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001478
Philipp Maier16ade782020-07-08 21:36:00 +02001479/* Normal variant */
1480testcase TC_rach_content() runs on test_CT {
1481 f_TC_rach_content(emerg := false);
1482}
1483
1484/* Emergency call variant */
1485testcase TC_rach_content_emerg() runs on test_CT {
1486 f_TC_rach_content(emerg := true);
1487}
1488
Harald Welte8c24c2b2018-02-26 08:31:31 +01001489/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1490testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001491 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001492 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001493 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001494 f_l1_tune(L1CTL);
1495
1496 var GsmFrameNumber fn_last := 0;
1497 for (var integer i := 0; i < 1000; i := i+1) {
1498 var OCT1 ra := f_rnd_ra_cs();
1499 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1500 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001502 }
1503 fn_last := fn;
1504 }
1505 var integer rsl_chrqd := 0;
1506 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001507 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001508 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001509 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001510 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001511 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001512 repeat;
1513 }
1514 [] RSL_CCHAN.receive { repeat; }
1515 [] T.timeout { }
1516 }
1517 if (rsl_chrqd == 1000) {
1518 setverdict(pass);
1519 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001520 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001521 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001523}
1524
Harald Welte3453ab42019-05-24 21:19:58 +02001525private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1526 var charstring bts_str := "bts " & int2str(bts_nr);
1527 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1528}
1529
1530/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1531private template integer tr_rach_slots_per_interval := (90 .. 130);
1532
1533/* Expect 0 RACH load on an idle BTS that has just started up */
1534testcase TC_rach_load_idle_thresh0() runs on test_CT {
1535 var ASP_RSL_Unitdata rx_ud;
1536
1537 f_init_vty_bsc();
1538 /* send load indications even at 0% load */
1539 f_vty_load_ind_thresh(0);
1540 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1541 f_sleep(2.0);
1542
1543 f_init();
1544
Harald Weltee37f9a52020-10-11 20:45:23 +02001545 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1546 alt {
1547 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1548 [] RSL_CCHAN.receive { repeat }
1549 }
1550
Harald Welte3453ab42019-05-24 21:19:58 +02001551 timer T := 5.0;
1552 T.start;
1553 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001554 [] 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 +02001555 setverdict(pass);
1556 repeat;
1557 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001558 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001559 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1560 repeat;
1561 }
1562 [] RSL_CCHAN.receive {
1563 repeat;
1564 }
1565 [] T.timeout { }
1566 }
1567
1568 f_vty_load_ind_thresh(10);
1569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1570}
1571
1572/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1573testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1574 var ASP_RSL_Unitdata rx_ud;
1575
1576 f_init_vty_bsc();
1577 f_init();
1578
1579 timer T := 5.0;
1580 T.start;
1581 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001582 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001583 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1584 repeat;
1585 }
1586 [] RSL_CCHAN.receive {
1587 repeat;
1588 }
1589 [] T.timeout {
1590 setverdict(pass);
1591 }
1592 }
1593
1594 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1595}
1596
1597/* Expect 0 RACH load on an idle BTS that has just started up */
1598testcase TC_rach_load_count() runs on test_CT {
1599 var ASP_RSL_Unitdata rx_ud;
1600 var integer load_access_count := 0;
1601
1602 f_init_vty_bsc();
1603 /* send load indications even at 0% load */
1604 f_vty_load_ind_thresh(0);
1605 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1606 f_sleep(2.0);
1607 f_init();
1608
1609 f_init_l1ctl();
1610 f_sleep(1.0);
1611 f_l1_tune(L1CTL);
1612
Harald Welte52ae1682020-10-11 20:45:55 +02001613 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1614 alt {
1615 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1616 [] RSL_CCHAN.receive { repeat }
1617 }
1618
Harald Welte3453ab42019-05-24 21:19:58 +02001619 var GsmFrameNumber fn_last := 0;
1620 for (var integer i := 0; i < 1000; i := i+1) {
1621 var OCT1 ra := f_rnd_ra_cs();
1622 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1623 if (fn == fn_last) {
1624 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1625 }
1626 fn_last := fn;
1627 }
1628
1629 timer T := 5.0;
1630 T.start;
1631 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001632 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001633 -> value rx_ud {
1634 var RSL_IE_Body ie;
1635 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1636 load_access_count := load_access_count + ie.rach_load.access_count;
1637 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1638 setverdict(fail, "Access count cannot be < Busy count");
1639 }
1640 repeat;
1641 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001642 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001643 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1644 repeat;
1645 }
1646 [] RSL_CCHAN.receive {
1647 repeat;
1648 }
1649 [] T.timeout { }
1650 }
1651 if (load_access_count == 1000) {
1652 setverdict(pass);
1653 } else {
1654 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1655 }
1656
1657 f_vty_load_ind_thresh(10);
1658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1659}
1660
Harald Welte54a2a2d2018-02-26 09:14:05 +01001661private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001662 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001663 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001664 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001665 f_sleep(0.5);
1666
1667 /* Transmit RACH request + wait for confirmation */
1668 var OCT1 ra := f_rnd_ra_cs();
1669 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1670
1671 /* Check for expected result */
1672 timer T := 1.5;
1673 T.start;
1674 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001675 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001676 setverdict(pass);
1677 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001678 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001679 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001680 }
1681 [] RSL_CCHAN.receive { repeat; }
1682 [not expect_pass] T.timeout {
1683 setverdict(pass);
1684 }
1685 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001687 }
1688 }
1689}
1690
1691/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1692testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001693 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001694 f_init_l1ctl();
1695 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001696 f_sleep(1.0);
1697
1698 /* default max-ta is 63 (full range of GSM timing advance */
1699
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001700 /* We allow early arrival up to 2 symbols */
1701 f_rach_toffs(-1*256, true);
1702 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001703 f_rach_toffs(-10*256, false);
1704
1705 /* 0 / 32 / 63 bits is legal / permitted */
1706 f_rach_toffs(0, true);
1707 f_rach_toffs(32*256, true);
1708 f_rach_toffs(63*256, true);
1709
1710 /* more than 63 bits is not legal / permitted */
1711 f_rach_toffs(64*256, false);
1712 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001713 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001714}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001715
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001716private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001717 var GsmFrameNumber fn;
1718 var RSL_Message rm;
1719
1720 f_l1_tune(L1CTL);
1721 RSL.clear;
1722
1723 /* Generate a random Handover Reference */
1724 var integer ho_ref := oct2int(f_rnd_octstring(1));
1725
1726 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1727 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1728 RSL_IE_Body:{ handover_ref := ho_ref }));
1729
1730 /* Activate a channel on the BTS side (no encryption) */
1731 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1732 act_type := t_RSL_IE_ActType_HO_SYNC);
1733
1734 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1735 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001736 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001737
1738 /* Send handover Access Burst */
1739 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1740
1741 /* TODO: test mismatching Handover Reference, and missing IE */
1742
1743 /* Wait for handover detection */
1744 timer T := 3.0;
1745 T.start;
1746 alt {
1747 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1748 log("Handover RACH has been detected: ", rm);
1749 setverdict(pass);
1750 }
1751 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1753 log2str("RSL_CHAN_RQD was not expected: ", rm));
1754 }
1755 [] RSL.receive { repeat; }
1756 [] T.timeout {
1757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1758 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1759 }
1760 }
1761
1762 /* Release the channel */
1763 f_rsl_chan_deact();
1764 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1765}
1766
1767/* Test handover RACH detection */
1768testcase TC_ho_rach() runs on test_CT {
1769 var ConnHdlrPars pars;
1770 var ConnHdlr vc_conn;
1771
1772 f_init();
1773
1774 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1775 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1776 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1777 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1778 vc_conn.done;
1779 }
1780
1781 /* TODO: do the above in parallel, rather than sequentially? */
1782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1783}
1784
Harald Welte93640c62018-02-25 16:59:33 +01001785/***********************************************************************
1786 * Measurement Processing / Reporting
1787 ***********************************************************************/
1788
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001789private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001790 spare := '0'B,
1791 lpd := 0,
1792 sapi := sapi,
1793 c_r := c_r,
1794 ea := true
1795}
1796
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001797private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001798 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001799 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001800 len := 0, /* overwritten */
1801 m := false,
1802 el := 1,
1803 payload := pl
1804}
1805
1806/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001807private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001808 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001809 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001810 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001811 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, mp_rxlev_exp, mp_rxlev_exp, 0, 0, omit));
Harald Welted879bd92018-03-12 15:01:23 +01001812 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001813 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001814
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001815 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1816 g_pars.l1_pars.ms_power_level, false,
1817 g_pars.l1_pars.ms_actual_ta);
1818
1819 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1820 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1821
1822 log("Sending Measurement Report: ", l1h, l2);
1823 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001824 repeat;
1825 }
1826}
1827
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07001828/* handle incoming downlink SACCH, decode the L1 header into the given record */
1829private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
1830 boolean do_apply := true)
1831runs on ConnHdlr
1832{
1833 var L1ctlDlMessage l1_dl;
1834
1835 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1836 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
1837 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
1838 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
1839
1840 if (do_apply) {
1841 /* Update TA and MS power to follow what BTS requests */
1842 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
1843 }
1844 }
1845}
1846
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001847private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001848 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001849 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001850 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1851 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001852 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1853 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001854 repeat;
1855 }
1856}
1857
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001858private altstep as_l1_tch_loop() runs on ConnHdlr {
1859 var L1ctlDlMessage l1_dl;
1860 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1861 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001862
1863 /* occasionaly inject FACCH frames into the uplink */
1864 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1865 var octetstring pl := '010301'O;
1866 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1867 f_pad_oct(pl, 23, '2B'O)));
1868 } else {
1869 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1870 l1_dl.payload.traffic_ind.data));
1871 }
1872
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001873 repeat;
1874 }
1875}
1876
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001877private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001878 uint6_t rxlev,
1879 uint3_t rxqual
1880}
1881
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001882private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001883 MeasElem full,
1884 MeasElem sub
1885}
1886
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001887private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001888 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001889 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001890 MeasElemFS meas_ul,
1891 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001892 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001893 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02001894 uint8_t ms_actual_ta,
1895 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01001896}
1897
1898/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1899private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1900 return 63 + (toffs256s/256);
1901}
1902
Harald Welted5684392018-03-10 18:22:04 +01001903private function f_max(integer a, integer b) return integer {
1904 if (a > b) {
1905 return a;
1906 } else {
1907 return b;
1908 }
1909}
1910
1911private function f_min(integer a, integer b) return integer {
1912 if (a < b) {
1913 return a;
1914 } else {
1915 return b;
1916 }
1917}
1918
1919/* compute negative tolerance val-tolerance, ensure >= min */
1920private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1921 val := val - tolerance;
1922 return f_max(val, min);
1923}
1924
1925/* compute positive tolerance val+tolerance, ensure <= max */
1926private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1927 val := val + tolerance;
1928 return f_min(val, max);
1929}
1930
1931/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1932private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1933return template integer {
1934 var template integer ret;
1935 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1936 return ret;
1937}
1938
1939
Harald Welte70767382018-02-21 12:16:40 +01001940/* build a template for matching measurement results against */
1941private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1942 var ConnL1Pars l1p := g_pars.l1_pars;
1943 var template RSL_IE_UplinkMeas ul_meas := {
1944 len := 3,
1945 rfu := '0'B,
1946 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001947 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001948 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001949 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001950 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001951 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1952 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001953 supp_meas_info := omit
1954 };
Harald Welte685d5982018-02-27 20:42:05 +01001955 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001956 ul_meas.len := (3+8);
1957 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001958 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001959 toa256_min := ?,
1960 toa256_max := ?,
1961 toa256_std_dev := ?
1962 }
Harald Welte685d5982018-02-27 20:42:05 +01001963 }
Harald Welte70767382018-02-21 12:16:40 +01001964 var template RSL_IE_BS_Power bs_power := {
1965 reserved := 0,
1966 epc := false,
1967 fpc := false,
1968 power_level := l1p.bs_power_level
1969 };
1970 var template RSL_IE_L1Info l1_info := {
1971 ms_power_lvl := l1p.ms_power_level,
1972 fpc := false,
1973 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001974 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001975 };
1976 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001977 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001978 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1979 ?, t_toffs);
1980}
1981
Philipp Maierdd841d32019-12-17 14:44:54 +01001982/* build a template for matching measurement results that do not contain any
1983 * MS related measurement (l1_info, l3_info and ms timing offset). */
1984private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1985 var ConnL1Pars l1p := g_pars.l1_pars;
1986 var template RSL_IE_UplinkMeas ul_meas := {
1987 len := 3,
1988 rfu := '0'B,
1989 dtx_d := l1p.dtx_enabled,
1990 rxlev_f_u := ?,
1991 reserved1 := '00'B,
1992 rxlev_s_u := ?,
1993 reserved2 := '00'B,
1994 rxq_f_u := ?,
1995 rxq_s_u := ?,
1996 supp_meas_info := omit
1997 };
1998 if (l1p.toa256_enabled) {
1999 ul_meas.len := (3+8);
2000 ul_meas.supp_meas_info := {
2001 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2002 toa256_min := ?,
2003 toa256_max := ?,
2004 toa256_std_dev := ?
2005 }
2006 }
2007 var template RSL_IE_BS_Power bs_power := {
2008 reserved := 0,
2009 epc := false,
2010 fpc := false,
2011 power_level := l1p.bs_power_level
2012 };
2013
2014 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2015}
2016
Harald Welte70767382018-02-21 12:16:40 +01002017/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002018private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002019 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002020 var boolean chan_est := false;
2021
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002022 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002023
2024 /* Receive osmocom specific measurement reports. This is the normal
2025 * case. Here we verify that the measurement reports we sent are
2026 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002027 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2028 /* increment counter of next to-be-expected meas rep */
2029 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2030 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002031 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002032
2033 /* The following two cases may only happen in the beginning
2034 * of the channel establishment phase. Once we have received
2035 * the "our" measurement report the first time, the channel
2036 * is established and empty or hardcoded TRXCON reports must
2037 * not occur anymore. */
2038 chan_est := true;
2039
2040 repeat;
2041 }
2042
2043 /* When the BTS has established the channel, the MS might need slightly
2044 * more time to establish the channel and actually start sending. The
2045 * result is then a measurement report that just lacks the measurement
2046 * information of the MS. This is normal and we tolerate this behavior. */
2047 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2048 /* increment counter of next to-be-expected meas rep */
2049 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2050 /* Re-start the timer expecting the next MEAS RES */
2051 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002052 repeat;
2053 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002054
2055 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2056 * measurements if the TTCN3 side does not supply measurement input in
2057 * time. In those cases TRXCON will either use a cached measurement
2058 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2059 * report the templates above will not match. We tolerate this
2060 * behavior, but only once. */
2061 [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 +01002062 /* increment counter of next to-be-expected meas rep */
2063 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2064 if (g_first_meas_res) {
2065 g_first_meas_res := false;
2066 repeat;
2067 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002069 }
Harald Welte70767382018-02-21 12:16:40 +01002070 }
2071 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002073 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002074 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002075 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002076 }
2077}
2078
Harald Weltee613f962018-04-18 22:38:16 +02002079private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2080 select (rsl_alg_id) {
2081 case (RSL_ALG_ID_A5_0) { return 0; }
2082 case (RSL_ALG_ID_A5_1) { return 1; }
2083 case (RSL_ALG_ID_A5_2) { return 2; }
2084 case (RSL_ALG_ID_A5_3) { return 3; }
2085 case (RSL_ALG_ID_A5_4) { return 4; }
2086 case (RSL_ALG_ID_A5_5) { return 5; }
2087 case (RSL_ALG_ID_A5_6) { return 6; }
2088 case (RSL_ALG_ID_A5_7) { return 7; }
2089 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2091 /* Make compiler happy by calling mtc.stop here. It is already
2092 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002093 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002094 }
2095 }
2096}
2097
2098private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2099 select (rsl_alg_id) {
2100 case (RSL_ALG_ID_A5_1) { return '000'B; }
2101 case (RSL_ALG_ID_A5_2) { return '001'B; }
2102 case (RSL_ALG_ID_A5_3) { return '010'B; }
2103 case (RSL_ALG_ID_A5_4) { return '011'B; }
2104 case (RSL_ALG_ID_A5_5) { return '100'B; }
2105 case (RSL_ALG_ID_A5_6) { return '101'B; }
2106 case (RSL_ALG_ID_A5_7) { return '110'B; }
2107 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2109 /* Make compiler happy by calling mtc.stop here. It is already
2110 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002111 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002112 }
2113 }
2114}
2115
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002116/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2117private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2118 var GsmFrameNumber fn;
2119 timer T := 8.0;
2120
2121 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2122 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2123
2124 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2125 /* Send the actual RACH */
2126 fn := f_L1CTL_RACH(L1CTL, ra);
2127
2128 T.start;
2129 alt {
2130 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2131 [] T.timeout {
2132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2133 }
2134 }
2135 T.stop
2136 return fn;
2137}
Harald Weltee613f962018-04-18 22:38:16 +02002138
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002139/* Tune to a dedicated channel: L1CTL only */
2140private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002141 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002142 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2143 7 /* TODO: mp_tsc */,
2144 mp_trx0_arfcn));
2145 } else {
2146 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2147 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002148 pars.fhp.maio_hsn.hsn,
2149 pars.fhp.maio_hsn.maio,
2150 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002151 }
2152}
2153
Harald Welte70767382018-02-21 12:16:40 +01002154/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002155private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002156 var GsmFrameNumber fn;
2157 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002158 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002159 var integer ra := 23;
2160
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002161 /* Send RACH request and wait for ChanReq */
2162 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002163
2164 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002165 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002166
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002167 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002168 if (g_pars.fhp.enabled) {
2169 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002170 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002171 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002172 }
2173
Harald Welte70767382018-02-21 12:16:40 +01002174 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002175 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 +01002176 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2177
2178 /* receive IMM.ASS on MS side */
2179 var ImmediateAssignment ia_um;
2180 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002181
2182 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2183 if (ch_desc.h != ia_um.chan_desc.h) {
2184 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2185 }
2186
Harald Welte70767382018-02-21 12:16:40 +01002187 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002188 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002189 /* enable encryption, if requested */
2190 if (encr_enable) {
2191 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2192 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2193 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002194
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002195 /* Send TCH Mode Request to the L1 if needed */
2196 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2197 var L1ctlTchMode tch_mode;
2198
2199 select (g_pars.chan_mode.coding_alg_rate) {
2200 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2201 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2202 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2203 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2204 case else {
2205 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2206 " is not supported by the L1, falling back to signalling");
2207 tch_mode := L1CTL_CHAN_MODE_SIGN;
2208 }
2209 }
2210
2211 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2212 }
2213
Harald Weltefa45e9e2018-03-10 18:59:03 +01002214 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002215}
2216
2217/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002218private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002219 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002220 RSL.clear;
2221
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002222 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002223 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002224 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002225 }
Harald Welte70767382018-02-21 12:16:40 +01002226
2227 f_est_dchan();
2228
2229 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2230 * RSL measurement reports on Abis side */
2231 timer T := 8.0;
2232 T.start;
2233 alt {
2234 [] as_l1_sacch();
2235 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002236 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002237 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002238 [] L1CTL.receive { repeat; }
2239 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002240 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002241 * of any earlier errors, so if we reach this timeout, we're good */
2242 setverdict(pass);
2243 }
2244 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002246 }
2247 }
2248 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002249 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002250}
Harald Welte0472ab42018-03-12 15:02:26 +01002251
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002252/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2253private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002254 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002255 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2256 timer Tup := 10.0;
2257 Tup.start;
2258 alt {
2259 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2260 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2261 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002262
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002263 if (rx_lvl != max_rx_lvl) {
2264 repeat;
2265 }
2266 Tup.stop;
2267 }
2268 [] L1CTL.receive { repeat; }
2269 [] Tup.timeout {
2270 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2271 log2str("Didn't reach full power ", max_rx_lvl));
2272 }
2273 }
2274 return max_rx_lvl;
2275}
2276
2277/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2278private function f_verify_ramp_up() runs on ConnHdlr {
2279 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002280 var integer initial_rx_lvl := -1;
2281 var integer last_rx_lvl := -1;
2282 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2283
2284 timer T := 2.0;
2285 alt {
2286 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2287 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2288 log("Received rx_level=", rx_lvl);
2289 if (initial_rx_lvl == -1) {
2290 initial_rx_lvl := rx_lvl;
2291 last_rx_lvl := rx_lvl;
2292
2293 /* Expect a somehow low value during first received messages */
2294 if (initial_rx_lvl >= max_rx_lvl / 2) {
2295 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2296 log2str("Detected high initial tx power during ramp up: ",
2297 initial_rx_lvl , ", full power is", max_rx_lvl));
2298 }
2299 }
2300
2301 /* received Rx level bigger than maximum allowed power by CN */
2302 if (rx_lvl > max_rx_lvl) {
2303 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2304 log2str("Detected Tx power higher than full power: ",
2305 rx_lvl , " > ", max_rx_lvl));
2306 }
2307
2308 /* Make sure it never decreases, since we are rumping up */
2309 if (last_rx_lvl > rx_lvl) {
2310 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2311 log2str("Detected Tx power decrease during ramp up: ",
2312 last_rx_lvl , " -> ", rx_lvl));
2313 }
2314
2315 if (rx_lvl == max_rx_lvl and not T.running) {
2316 /* We reached the maximum power, start timer and receive
2317 /* a few more to make sure we don't surpass it */
2318 log("Reached full power, wating a bit more until success");
2319 T.start;
2320 }
2321
2322 last_rx_lvl := rx_lvl;
2323 repeat;
2324 }
2325 [] L1CTL.receive { repeat; }
2326 [] T.timeout { }
2327 }
2328
2329 /* We didn't increase tx power during ramp up */
2330 if (initial_rx_lvl < last_rx_lvl) {
2331 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2332 } else {
2333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2334 log2str("No Tx power increase during whole ramp up: ",
2335 initial_rx_lvl , " -> ", last_rx_lvl));
2336 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002337}
2338
2339/* verify BTS ramps power down to rx_level 0 */
2340private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2341 var L1ctlDlMessage l1_dl;
2342 var integer last_rx_lvl := max_rx_lvl;
2343
2344 timer Tdown := 5.0;
2345 Tdown.start;
2346 alt {
2347 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2348 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2349 log("Received rx_level=", rx_lvl);
2350
2351 /* received Rx level bigger than maximum allowed power by CN */
2352 if (rx_lvl > max_rx_lvl) {
2353 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2354 log2str("Detected Tx power higher than full power: ",
2355 rx_lvl , " > ", max_rx_lvl));
2356 }
2357
2358 /* Make sure it never increases, since we are rumping down */
2359 if (last_rx_lvl < rx_lvl) {
2360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2361 log2str("Detected Tx power increase during ramp up: ",
2362 last_rx_lvl , " -> ", rx_lvl));
2363 }
2364
2365 last_rx_lvl := rx_lvl;
2366 if (last_rx_lvl != 0) {
2367 repeat;
2368 }
2369 /* we reached power level 0, we are done */
2370 Tdown.stop;
2371 }
2372 [] L1CTL.receive { repeat; }
2373 [] Tdown.timeout { }
2374 }
2375
2376 /* We didn't increase tx power during ramp down */
2377 if (max_rx_lvl > last_rx_lvl) {
2378 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2379 } else {
2380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2381 log2str("No Tx power decrease during whole ramp down: ",
2382 max_rx_lvl , " -> ", last_rx_lvl));
2383 }
2384}
2385
2386/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002387private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002388 f_l1_tune(L1CTL);
2389 RSL.clear;
2390
2391 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002392
2393 setverdict(pass);
2394}
2395testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2396 var ConnHdlr vc_conn;
2397 var ConnHdlrPars pars;
2398 f_init();
2399 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2400 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2401 pcu_comp := false, trxc_comp := true);
2402 vc_conn.done;
2403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2404}
2405
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002406/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002407private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002408 f_connhdlr_init_vty_bsc();
2409
2410 f_l1_tune(L1CTL);
2411 RSL.clear;
2412
2413 /* Wait until BTS is started and at full power */
2414 var integer max_rx_lvl := f_wait_ramp_up();
2415 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2416
2417 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2418 f_verify_ramp_down(max_rx_lvl);
2419
2420 setverdict(pass);
2421}
2422testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2423 var ConnHdlr vc_conn;
2424 var ConnHdlrPars pars;
2425 f_init();
2426 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2427 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2428 pcu_comp := false, trxc_comp := true);
2429 vc_conn.done;
2430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2431}
2432
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002433/* Verify Tx power:
2434 * + ramping down during ADM state UNLOCKED->LOCKED
2435 * + ramping up during ADM state LOCKED->UNLOCKED
2436 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002437private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002438 var L1ctlDlMessage l1_dl;
2439 var integer last_rx_lvl;
2440
2441 f_connhdlr_init_vty_bsc();
2442
2443 f_l1_tune(L1CTL);
2444 RSL.clear;
2445
2446 /* Wait until BTS is started and at full power */
2447 var integer max_rx_lvl := f_wait_ramp_up();
2448 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2449
2450 log("ADM STATE UNLOCKED->LOCKED");
2451 f_vty_enter_cfg_trx(BSCVTY);
2452 f_vty_transceive(BSCVTY, "rf_locked 1");
2453 last_rx_lvl := max_rx_lvl;
2454 f_verify_ramp_down(max_rx_lvl);
2455
2456 /* Let some time after we received 0dBm, then check we don't receive BCCH
2457 * anymore because scheduler has stopped after ramping down */
2458 f_sleep(2.0);
2459 L1CTL.clear;
2460 timer Tlocked := 2.0;
2461 Tlocked.start;
2462 alt {
2463 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2465 log2str("Received data_ind during rf_locked: ", l1_dl));
2466 }
2467 [] L1CTL.receive { repeat; }
2468 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2469 }
2470
2471 log("ADM STATE LOCKED->UNLOCKED");
2472 f_vty_transceive(BSCVTY, "rf_locked 0");
2473 f_verify_ramp_up();
2474 setverdict(pass);
2475}
2476testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2477 var ConnHdlr vc_conn;
2478 var ConnHdlrPars pars;
2479 f_init();
2480 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2481 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2482 pcu_comp := false, trxc_comp := true);
2483 vc_conn.done;
2484 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2485}
2486
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002487private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002488 timer T := 8.0;
2489 T.start;
2490 var RSL_Message rsl;
2491 alt {
2492 [] as_l1_sacch();
2493 [] L1CTL.receive { repeat; }
2494 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2495 if (rsl.ies[3].body.bs_power.power_level == level) {
2496 setverdict(pass)
2497 } else {
2498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2499 }
2500 }
2501 [] T.timeout {
2502 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2503 }
2504 }
2505}
2506
2507/* see if the rsl meas res contains our expeced bs power level
2508bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002509private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002510 f_l1_tune(L1CTL);
2511 RSL.clear;
2512
2513 if (mp_bts_trxc_port != -1) {
2514 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2515 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2516 }
2517
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002518 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002519 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2520 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2521
2522 f_est_dchan(more_ies :={valueof(pwr)});
2523
2524 f_check_meas_bs_power_level(pwr_var);
2525
2526 f_rsl_chan_deact();
2527 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2528}
2529
2530/* see if the rsl meas res contains our expeced bs power level
2531bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002532private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002533 f_l1_tune(L1CTL);
2534 RSL.clear;
2535
2536 if (mp_bts_trxc_port != -1) {
2537 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2538 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2539 }
2540
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002541 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002542 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2543
2544 f_est_dchan();
2545
2546 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2547
2548 f_check_meas_bs_power_level(pwr_var);
2549
2550 f_rsl_chan_deact();
2551 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2552}
2553
2554testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2555 var ConnHdlr vc_conn;
2556 var ConnHdlrPars pars;
2557 f_init();
2558 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2559 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2560 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2561 pcu_comp := false, trxc_comp := true);
2562 vc_conn.done;
2563 }
2564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2565}
2566
2567testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2568 var ConnHdlr vc_conn;
2569 var ConnHdlrPars pars;
2570 f_init();
2571 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2572 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2573 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2574 pcu_comp := false, trxc_comp := true);
2575 vc_conn.done;
2576 }
2577 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2578}
2579
Eric Wild61edb7e2019-06-03 12:38:31 +02002580/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2581second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2582These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002583private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002584 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002585 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002586
2587 f_trxc_fake_rssi(rxlev2dbm(10));
2588 f_l1_tune(L1CTL);
2589 RSL.clear;
2590
2591 var RSL_IE_List addl_ies;
2592 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2593
2594 addl_ies := {
2595 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2596 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2597 };
2598
2599 /* establish with power parameters */
2600 f_est_dchan(more_ies := addl_ies);
2601
2602 /* set a high value to ensure L1 power control level increases */
2603 f_trxc_fake_rssi(rxlev2dbm(20));
2604
2605 timer T2 := 6.0;
2606 T2.start;
2607 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002608 [] as_l1_sacch_l1h(l1h) {
2609 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002610 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002611 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002612 T2.stop;
2613 }
2614 [] L1CTL.receive { repeat; }
2615 [] T2.timeout {
2616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2617 "Power Level in L1 header has not increased sufficiently");
2618 }
2619 }
2620
2621 /* set a low value to ensure L1 power control level decreases */
2622 f_trxc_fake_rssi(rxlev2dbm(0));
2623
2624 timer T4 := 6.0;
2625 T4.start;
2626 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002627 [] as_l1_sacch_l1h(l1h) {
2628 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002629 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002630 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002631 T4.stop;
2632 setverdict(pass, "Power level in L1 decreased/increased as expected");
2633 }
2634 [] L1CTL.receive { repeat; }
2635 [] T4.timeout {
2636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2637 "Power Level in L1 header has not decreased sufficiently");
2638 }
2639 }
2640
2641 f_rsl_chan_deact();
2642 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2643
2644}
2645
2646/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002647private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002648 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002649 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002650
2651 /* set a low value to ensure power increases */
2652 f_trxc_fake_rssi(rxlev2dbm(10));
2653 f_l1_tune(L1CTL);
2654 RSL.clear;
2655
2656 var RSL_IE_List addl_ies;
2657 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2658
2659 addl_ies := {
2660 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2661 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2662 };
2663
2664 /* establish with power parameters */
2665 f_est_dchan(more_ies := addl_ies);
2666
2667 timer T1 := 10.0;
2668 T1.start;
2669 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002670 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002671 [] L1CTL.receive { repeat; }
2672 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002673 if (not isbound(l1h)) {
2674 setverdict(fail, "No SACCH blocks were received");
2675 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002676 setverdict(fail, "Power level in L1 header should not have changed");
2677 }
2678 }
2679 }
2680
2681 f_rsl_chan_deact();
2682 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2683
2684}
2685
2686/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002687private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002688 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002689 var uint5_t pwr_var := 15;
2690 var uint5_t pwr_max_var := f_get_max_power_from_band();
2691
2692 /* set a low value to ensure power increases */
2693 f_trxc_fake_rssi(rxlev2dbm(10));
2694 f_l1_tune(L1CTL);
2695 RSL.clear;
2696
2697 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2698 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2699
2700 /* establish with fixed power level */
2701 f_est_dchan(more_ies :={valueof(pwr)});
2702
2703 /* check our initial power level */
2704 f_wait_for_l1_power_level(pwr_var);
2705
2706 /* update power param to enable power loop
2707 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2708 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2709
2710 /* wait, then check that our power level was reduced */
2711 timer T1 := 10.0;
2712 T1.start;
2713 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002714 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002715 [] L1CTL.receive { repeat; }
2716 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002717 if (not isbound(l1h)) {
2718 setverdict(fail, "No SACCH blocks were received");
2719 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002720 setverdict(pass, "Power level in L1 header reduced as expected");
2721 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002722 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
2723 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02002724 }
2725 }
2726 }
2727
2728 f_rsl_chan_deact();
2729 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2730
2731}
2732
2733/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002734private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002735 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002736
2737 /* set a high value to ensure power decreases */
2738 f_trxc_fake_rssi(rxlev2dbm(50));
2739 f_l1_tune(L1CTL);
2740 RSL.clear;
2741
2742 var uint5_t pwr_var := 5;
2743 var uint5_t pwr_target_val := 15;
2744
2745 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2746 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2747
2748 /* establish with fixed power level */
2749 f_est_dchan(more_ies :={valueof(pwr)});
2750
2751 /* check our initial power level */
2752 f_wait_for_l1_power_level(pwr_var);
2753
2754 /* update power param to enable power loop
2755 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002756 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002757
2758 /* wait, then check that our power level was increased */
2759 timer T1 := 10.0;
2760 T1.start;
2761 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002762 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002763 [] L1CTL.receive { repeat; }
2764 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002765 if (not isbound(l1h)) {
2766 setverdict(fail, "No SACCH blocks were received");
2767 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
2768 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002769 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002770 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002771 }
2772 }
2773 }
2774
2775 f_rsl_chan_deact();
2776 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2777
2778}
2779
Eric Wild095024b2019-06-17 15:08:57 +02002780/* see if we change the power level without receiving power parameters, which should not happen
2781rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002782private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002783 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02002784
2785 /* set a high value to ensure power decreases */
2786 f_trxc_fake_rssi(rxlev2dbm(50));
2787 f_l1_tune(L1CTL);
2788 RSL.clear;
2789
2790 var uint5_t pwr_var := 5;
2791
2792 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2793 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2794
2795 /* establish with fixed power level */
2796 f_est_dchan(more_ies :={valueof(pwr)});
2797
2798 /* check our initial power level */
2799 f_wait_for_l1_power_level(pwr_var);
2800
2801 /* wait, then check that our power level did not change */
2802 timer T1 := 10.0;
2803 T1.start;
2804 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002805 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2806 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02002807 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2808 "BS power control should not be active unless we receive a power parameters IE!");
2809 }
2810 repeat;
2811 }
2812 [] L1CTL.receive { repeat; }
2813 [] T1.timeout { setverdict(pass); }
2814 }
2815
2816 f_rsl_chan_deact();
2817 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2818
2819}
2820
Eric Wild095024b2019-06-17 15:08:57 +02002821/* see if we change the power level without receiving power parameters, which should not happen
2822ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002823private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002824 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02002825
2826 /* set a high value to ensure power decreases */
2827 f_trxc_fake_rssi(rxlev2dbm(50));
2828 f_l1_tune(L1CTL);
2829 RSL.clear;
2830
2831 var uint5_t pwr_var := 5;
2832
2833 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2834 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2835
2836 /* establish with fixed power level */
2837 f_est_dchan(more_ies :={valueof(pwr)});
2838
2839 /* check our initial power level */
2840 f_wait_for_l1_power_level(pwr_var);
2841
2842 /* pwr control without power params IE, should NOT activate MS power control*/
2843 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2844
2845 /* wait, then check that our power level did not change */
2846 timer T1 := 10.0;
2847 T1.start;
2848 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002849 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2850 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02002851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2852 "BS power control should not be active unless we receive a power parameters IE!");
2853 }
2854 repeat;
2855 }
2856 [] L1CTL.receive { repeat; }
2857 [] T1.timeout { setverdict(pass); }
2858 }
2859
2860 f_rsl_chan_deact();
2861 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2862
2863}
2864
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002865private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002866 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002867 timer T0 := 10.0;
2868 T0.start;
2869 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002870 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2871 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002872 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2873 "Power level in L1 header != signaled (RSL) power level.");
2874 }
2875 }
2876 [] L1CTL.receive { repeat; }
2877 [] T0.timeout {
2878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2879 "Timeout waiting for initial power level");
2880 }
2881 }
2882 T0.stop;
2883}
2884
2885private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2886 var IntegerRecord min_dbm_level;
2887 var IntegerRecord max_dbm_level;
2888 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2889
2890 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2891 if (min_dbm_level[i] == level) {
2892 return true;
2893 }
2894 }
2895 return false;
2896}
2897
2898private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2899 var IntegerRecord min_dbm_level;
2900 var IntegerRecord max_dbm_level;
2901 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2902
2903 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2904 if (max_dbm_level[i] == level) {
2905 return true;
2906 }
2907 }
2908 return false;
2909}
2910
2911private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2912 var IntegerRecord min_dbm_level;
2913 var IntegerRecord max_dbm_level;
2914 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2915 return max_dbm_level[0];
2916}
2917
2918type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002919private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002920private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2921 // 45.005 4.1.1
2922 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2923 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2924 2, 1, 0};
2925 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2926 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2927 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2928 var IntegerRecord rv;
2929
2930 select(band){
2931 case (BtsBand_allGSM){
2932 rv := gsm_power;
2933 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2934 max_dbm_level := {2, 1, 0};
2935 }
2936 case("DCS1800"){
2937 rv := dcs_power;
2938 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2939 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2940 }
2941 case("PCS1900"){
2942 rv := pcs_power;
2943 min_dbm_level := {15};
2944 max_dbm_level := {30};
2945 }
Harald Welte194b6912020-10-11 21:01:55 +02002946 case else {
2947 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2948 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002949 }
2950
2951 return rv;
2952}
2953
2954private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002955 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 +02002956}
2957
2958testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2959 var ConnHdlr vc_conn;
2960 var ConnHdlrPars pars;
2961 f_init();
2962 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2963 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2964 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2965 pars.bts0_band := f_vty_get_bts0_band();
2966 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2967 vc_conn.done;
2968 }
2969 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2970 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2971}
2972
2973testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2974 var ConnHdlr vc_conn;
2975 var ConnHdlrPars pars;
2976 f_init();
2977 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2978 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2979 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2980 pars.bts0_band := f_vty_get_bts0_band();
2981 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2982 vc_conn.done;
2983 }
2984 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2986}
2987
2988testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2989 var ConnHdlr vc_conn;
2990 var ConnHdlrPars pars;
2991 f_init();
2992 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2993 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2994 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2995 pars.bts0_band := f_vty_get_bts0_band();
2996 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2997 vc_conn.done;
2998 }
2999 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3001}
3002
3003testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3004 var ConnHdlr vc_conn;
3005 var ConnHdlrPars pars;
3006 f_init();
3007 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3008 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3009 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3010 pars.bts0_band := f_vty_get_bts0_band();
3011 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3012 vc_conn.done;
3013 }
3014 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3015 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3016}
3017
Eric Wild280ccb82019-06-17 11:11:52 +02003018testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3019 var ConnHdlr vc_conn;
3020 var ConnHdlrPars pars;
3021 f_init();
3022 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3023 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3024 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3025 pars.bts0_band := f_vty_get_bts0_band();
3026 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3027 vc_conn.done;
3028 }
3029 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3031}
3032
Eric Wild095024b2019-06-17 15:08:57 +02003033testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3034 var ConnHdlr vc_conn;
3035 var ConnHdlrPars pars;
3036 f_init();
3037 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3038 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3039 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3040 pars.bts0_band := f_vty_get_bts0_band();
3041 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3042 vc_conn.done;
3043 }
3044 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3045 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3046}
3047
Philipp Maier149c3922020-10-22 17:29:36 +02003048function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003049 var template RSL_IE_ChannelMode ch_mode;
3050 var ConnHdlr vc_conn;
3051 var ConnHdlrPars pars;
3052 f_init();
3053 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3054 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3055 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003056 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003057 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3058 pcu_comp := false, trxc_comp := true);
3059 vc_conn.done;
3060 }
3061 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3062}
Philipp Maier149c3922020-10-22 17:29:36 +02003063
3064testcase TC_meas_res_speech_tchf() runs on test_CT {
3065 f_TC_meas_res_speech_tchf(false);
3066}
3067
3068testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3069 f_TC_meas_res_speech_tchf(true);
3070}
3071
3072function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003073 var template RSL_IE_ChannelMode ch_mode;
3074 var ConnHdlr vc_conn;
3075 var ConnHdlrPars pars;
3076 f_init();
3077 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3078 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3079 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003080 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003081 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3082 pcu_comp := false, trxc_comp := true);
3083 vc_conn.done;
3084 }
3085 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3086}
Philipp Maier149c3922020-10-22 17:29:36 +02003087
3088testcase TC_meas_res_speech_tchh() runs on test_CT {
3089 f_TC_meas_res_speech_tchh(false)
3090}
3091
3092testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3093 f_TC_meas_res_speech_tchh(true)
3094}
3095
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003096testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3097 var template RSL_IE_ChannelMode ch_mode;
3098 var ConnHdlr vc_conn;
3099 var ConnHdlrPars pars;
3100 f_init();
3101 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3102 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3103 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3104 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3105 pars.l1_pars.toa256_enabled := true;
3106 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3107 pcu_comp := false, trxc_comp := true);
3108 vc_conn.done;
3109 }
3110 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3111}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003112
Harald Welte70767382018-02-21 12:16:40 +01003113testcase TC_meas_res_sign_tchf() runs on test_CT {
3114 var ConnHdlr vc_conn;
3115 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003116 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003117 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003118 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003119 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3120 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003121 vc_conn.done;
3122 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003123 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003124}
3125testcase TC_meas_res_sign_tchh() runs on test_CT {
3126 var ConnHdlr vc_conn;
3127 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003128 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003129 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003130 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003131 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3132 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003133 vc_conn.done;
3134 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003136}
3137testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3138 var ConnHdlr vc_conn;
3139 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003140 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003141 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3142 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003143 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3144 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003145 vc_conn.done;
3146 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003148}
3149testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3150 var ConnHdlr vc_conn;
3151 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003152 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003153 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3154 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003155 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3156 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003157 vc_conn.done;
3158 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003159 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003160}
Harald Welte685d5982018-02-27 20:42:05 +01003161testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3162 var ConnHdlr vc_conn;
3163 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003164 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003165 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3166 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003167 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003168 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003169 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3170 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003171 vc_conn.done;
3172 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003174}
3175
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003176/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3177 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003178private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003179 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003180 var RSL_IE_MS_Power ms_power;
3181 var RSL_Message rsl;
3182 var uint5_t power_level := 0;
3183
3184 f_l1_tune(L1CTL);
3185 RSL.clear;
3186
3187 f_est_dchan();
3188
3189 ms_power.reserved := 0;
3190 ms_power.fpc_epc := false;
3191
3192 /* Send the first power control command. This will disable any BTS/TRX
3193 * internal power control and switch the MS (which is not in scope of
3194 * this test) to a constant power level. We start with a power level
3195 * of 0 */
3196 ms_power.power_level := power_level;
3197 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3198 RSL.send(rsl);
3199
3200 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003201 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3202 if (l1h.ms_power_lvl != power_level) {
3203 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3204 "match the signaled (RSL) power level := ", power_level);
3205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003206 }
3207
3208 /* Signal a new power level via RSL for the next turn. */
3209 if (power_level < 31) {
3210 power_level := power_level + 1;
3211 ms_power.power_level := power_level;
3212 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3213 RSL.send(rsl);
3214 repeat;
3215 }
3216
3217 }
3218
3219 /* Ignore all other blocks */
3220 [] L1CTL.receive { repeat; }
3221
3222 }
3223
3224 f_rsl_chan_deact();
3225 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3226
3227 setverdict(pass);
3228}
3229
3230testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3231 var ConnHdlr vc_conn;
3232 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003233 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003234
3235 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3236 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3237 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3238 vc_conn.done;
3239 }
3240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3241}
Harald Welte70767382018-02-21 12:16:40 +01003242
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003243/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003244TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003245private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003246 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003247 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003248
3249 f_l1_tune(L1CTL);
3250 RSL.clear;
3251
3252 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003253 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003254
3255 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3256
3257
3258 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003259 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3260 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003261 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3262 }
3263
3264 }
3265
3266 /* Ignore all other blocks */
3267 [] L1CTL.receive { repeat; }
3268
3269 }
3270
3271 f_rsl_chan_deact();
3272 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3273
3274 setverdict(pass);
3275}
3276
3277testcase TC_rsl_chan_initial_ta() runs on test_CT {
3278 var ConnHdlr vc_conn;
3279 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003280 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003281 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003282 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3283 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003284 vc_conn.done;
3285 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3286}
3287
Eric Wilde57e1a62019-05-28 13:30:55 +02003288/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003289private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003290 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003291 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003292
3293 var RSL_IE_MS_Power ms_power;
3294 ms_power.reserved := 0;
3295 ms_power.fpc_epc := false;
3296 ms_power.power_level := ms_power_level;
3297
3298 f_l1_tune(L1CTL);
3299 RSL.clear;
3300
3301 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3302
3303 timer T := 1.0;
3304 T.start;
3305 alt {
3306 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003307 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3308 if (l1h.ms_power_lvl != ms_power_level) {
3309 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3310 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003311 }
3312 }
3313 /* Ignore all other blocks */
3314 [] L1CTL.receive { repeat; }
3315 [] T.timeout {
3316 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3317 }
3318 }
3319
3320 f_rsl_chan_deact();
3321 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3322 setverdict(pass);
3323}
3324
3325testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3326 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3327 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3328}
3329
Harald Welte0472ab42018-03-12 15:02:26 +01003330/* 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 +01003331private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003332 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003333 RSL.clear;
3334
3335 f_est_dchan();
3336 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003337 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003338
3339 timer T := 40.0;
3340 T.start;
3341 alt {
3342 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3343 setverdict(pass)
3344 }
3345 [] RSL.receive { repeat };
3346 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003348 }
3349 }
3350 f_rsl_chan_deact();
3351}
3352testcase TC_conn_fail_crit() runs on test_CT {
3353 var ConnHdlr vc_conn;
3354 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003355 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003356 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3357 pars.t_guard := 60.0;
3358 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3359 vc_conn.done;
3360}
3361
Harald Welte93640c62018-02-25 16:59:33 +01003362/***********************************************************************
3363 * Paging
3364 ***********************************************************************/
3365
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003366private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003367 if (tmsi == 'FFFFFFFF'O) {
3368 return true;
3369 } else {
3370 return false;
3371 }
3372}
Harald Welte70767382018-02-21 12:16:40 +01003373
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003374private type record allowedFn { integer frame_nr }
3375private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3376private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3377private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3378private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3379private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3380private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3381private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3382private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3383private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003384{
3385 var integer frame_nr_51;
3386 frame_nr_51 := frame_nr mod 51
3387
3388 var allowedFn fn_check;
3389 fn_check.frame_nr := frame_nr_51;
3390
3391 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003393 return;
3394 }
3395
3396 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3397 return;
3398 }
3399 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3400 return;
3401 }
3402 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3403 return;
3404 }
3405 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3406 return;
3407 }
3408 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3409 return;
3410 }
3411 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3412 return;
3413 }
3414 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3415 return;
3416 }
3417 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3418 return;
3419 }
3420
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003422 return;
3423}
3424
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003425private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3426 inout integer num_paging_rcv_ids,
3427 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003428runs on test_CT {
3429 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003430 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003431 repeat;
3432 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003433 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003434 var octetstring without_plen :=
3435 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3436 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003437
3438 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3439
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003440 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3441 /* Ignore empty RR Paging Request (PCH filling) messages.
3442 * TODO: does it make sense to count them? */
3443 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003444 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3445 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003446 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003447 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3448 }
3449 } else if (match(rr, tr_PAGING_REQ2)) {
3450 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3451 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3452 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3453 }
3454 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3455 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3456 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003457 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003458 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3459 }
3460 } else if (match(rr, tr_PAGING_REQ3)) {
3461 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3462 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3463 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3464 }
3465 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3466 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3467 }
3468 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3469 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3470 }
3471 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3472 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3473 }
3474 }
3475 repeat;
3476 }
3477}
3478
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003479private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003480 boolean combined_ccch,
3481 integer bs_ag_blks_res,
3482 float load_factor,
3483 boolean exp_load_ind,
3484 boolean exp_overload,
3485 boolean use_tmsi
3486}
3487
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003488private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003489 integer num_paging_sent,
3490 integer num_paging_rcv_msgs,
3491 integer num_paging_rcv_ids,
3492 integer num_overload
3493}
3494
Harald Welte68e495b2018-02-25 00:05:57 +01003495/* Helper function for paging related testing */
3496private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003497 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003498 f_init_l1ctl();
3499 f_l1_tune(L1CTL);
3500
3501 var PagingTestState st := {
3502 num_paging_sent := 0,
3503 num_paging_rcv_msgs := 0,
3504 num_paging_rcv_ids := 0,
3505 num_overload := 0
3506 };
3507
3508 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3509 var float max_pch_imsi_per_sec;
3510 if (cfg.use_tmsi) {
3511 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3512 } else {
3513 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3514 }
3515 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3516 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003517 var float time_total := 20.0;
3518 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3519 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003520
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003521 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3522 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003523
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003524 timer T_itv := 0.0;
3525 T_itv.start;
3526 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003527 alt {
3528 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003529 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003530 st.num_overload := st.num_overload + 1;
3531 repeat;
3532 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003533 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003534 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003535 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003536 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003537 log("Rx LOAD_IND");
3538 /* FIXME: analyze/verify interval + contents */
3539 repeat;
3540 }
3541 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003542 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003543 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003544 [] T_itv.timeout {
3545 /* Send paging cmds based on elapsed time */
3546 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3547 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003548 var MobileIdentityV mi;
3549
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003550 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003551 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003552 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003553 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003554 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003555 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003556
3557 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003558 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 +02003559
3560 st.num_paging_sent := st.num_paging_sent + 1;
3561 }
3562 if (st.num_paging_sent < pkt_total) {
3563 /* Wait for interval to next PAGING COMMAND */
3564 var float time_now := T_total.read;
3565 var float next_sched := int2float(st.num_paging_sent)*interval;
3566 if (next_sched > time_now) {
3567 T_itv.start(next_sched - time_now);
3568 } else {
3569 T_itv.start(0.0);
3570 }
3571 } else {
3572 /* We are done, no need to keep counting */
3573 T_total.stop;
3574 }
3575 }
3576 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003577 }
3578 }
3579
3580 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3581 timer T_wait := 18.0;
3582 T_wait.start;
3583 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003584 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003585 [] L1CTL.receive { repeat; }
3586 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003587 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3588 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003589 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003591 }
Harald Welte68e495b2018-02-25 00:05:57 +01003592 }
3593
3594 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3595 " rcvd_ids=", st.num_paging_rcv_ids);
3596 return st;
3597}
3598
3599/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3600 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3601 * - that CCCH LOAD IND (PCH) are being generated
3602 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3603testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003604 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003605 var PagingTestCfg cfg := {
3606 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003607 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003608 load_factor := 0.8,
3609 exp_load_ind := true,
3610 exp_overload := false,
3611 use_tmsi := false
3612 };
3613 var PagingTestState st := f_TC_paging(cfg);
3614 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3616 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003617 } else {
3618 setverdict(pass);
3619 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003621}
3622
3623/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3624 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3625 * - that CCCH LOAD IND (PCH) are being generated
3626 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3627testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003628 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003629 var PagingTestCfg cfg := {
3630 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003631 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003632 load_factor := 0.8,
3633 exp_load_ind := true,
3634 exp_overload := false,
3635 use_tmsi := true
3636 };
3637 var PagingTestState st := f_TC_paging(cfg);
3638 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003639 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3640 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003641 } else {
3642 setverdict(pass);
3643 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003645}
3646
3647/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3648 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3649 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3650 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3651testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003652 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003653 var PagingTestCfg cfg := {
3654 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003655 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003656 load_factor := 2.0,
3657 exp_load_ind := true,
3658 exp_overload := true,
3659 use_tmsi := false
3660 };
3661 var PagingTestState st := f_TC_paging(cfg);
3662 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3663 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003664 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003665 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003666 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 +01003667 } else {
3668 setverdict(pass);
3669 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003670 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003671}
3672
3673/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3674 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3675 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3676 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3677testcase TC_paging_tmsi_200percent() 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 := 2.0,
3683 exp_load_ind := true,
3684 exp_overload := true,
3685 use_tmsi := true
3686 };
3687 var PagingTestState st := f_TC_paging(cfg);
3688 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3689 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003690 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003691 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003692 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 +01003693 } else {
3694 setverdict(pass);
3695 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003696 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003697}
3698
3699
Harald Welte93640c62018-02-25 16:59:33 +01003700/***********************************************************************
3701 * Immediate Assignment / AGCH
3702 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003703private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003704 len := 0,
3705 ma := ''B
3706}
Harald Welte93640c62018-02-25 16:59:33 +01003707
Harald Weltee8d750e2018-06-10 21:41:35 +02003708private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3709 return int2str(num_tx) & " sent, "
3710 & int2str(num_rx) & " received, "
3711 & int2str(num_del) & " deleted";
3712}
3713
3714private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3715 var L1ctlDlMessage l1_dl;
3716 timer T := 10.0;
3717 var integer num_tx := 0;
3718 var integer num_rx := 0;
3719 var integer num_del := 0;
3720 var charstring res_str;
3721 var float rx_ratio;
3722
Harald Welte10474062019-05-30 16:48:17 +02003723 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003724 f_init_l1ctl();
3725 f_l1_tune(L1CTL);
3726
3727 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003728 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003729 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3730 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003731 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003732 num_tx := num_tx+1;
3733 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003734 }
3735 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003736 T.start;
3737 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003738 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003739 num_del := num_del+1;
3740 repeat;
3741 }
3742 [] RSL_CCHAN.receive {
3743 repeat;
3744 }
3745 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003746 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3747 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3748 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003749 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003750 } else {
3751 num_rx := num_rx+1;
3752 }
3753 repeat;
3754 }
3755 [] L1CTL.receive { repeat; }
3756 [] T.timeout { }
3757 }
3758 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3759 log("AGCH test: " & res_str);
3760 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003762 }
3763 rx_ratio := int2float(num_rx) / int2float(num_tx);
3764 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003765 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 +02003766 } else {
3767 setverdict(pass);
3768 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003770}
3771
Harald Weltee8d750e2018-06-10 21:41:35 +02003772/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3773testcase TC_imm_ass_1000_20ms() runs on test_CT {
3774 f_TC_imm_ass(1000, 0.02, 0.25);
3775}
3776
3777/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3778testcase TC_imm_ass_200_0ms() runs on test_CT {
3779 f_TC_imm_ass(200, 0.0, 0.05);
3780}
3781
3782/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3783testcase TC_imm_ass_200_76ms() runs on test_CT {
3784 f_TC_imm_ass(150, 0.076, 1.00);
3785}
3786
3787
3788
Harald Welte48494ca2018-02-25 16:59:50 +01003789/***********************************************************************
3790 * BCCH
3791 ***********************************************************************/
3792
3793/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003794private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003795 GsmFrameNumber frame_number,
3796 SystemInformation si
3797}
3798
3799/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003800private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003801
3802/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003803private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003804
3805/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003806private function f_si_vecslot_contains(SystemInformationVector arr,
3807 RrMessageType key,
3808 boolean bcch_ext := false)
3809return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003810 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3811 var integer fn_mod51 := arr[i].frame_number mod 51;
3812 if (not bcch_ext and fn_mod51 == 2 or
3813 bcch_ext and fn_mod51 == 6) {
3814 if (arr[i].si.header.message_type == key) {
3815 return true;
3816 }
3817 }
3818 }
3819 return false;
3820}
3821
3822/* 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 +07003823private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3824 integer tc, RrMessageType key,
3825 boolean ext_bcch := false)
3826{
Harald Welte48494ca2018-02-25 16:59:50 +01003827 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003829 }
3830}
3831
3832/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003833private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3834 RrMessageType key)
3835return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003836 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3837 if (f_si_vecslot_contains(arr[tc], key) or
3838 f_si_vecslot_contains(arr[tc], key, true)) {
3839 return true;
3840 }
3841 }
3842 return false;
3843}
3844
3845/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003846private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3847 RrMessageType key,
3848 boolean bcch_ext := false,
3849 integer n := 1, integer m := 4)
3850return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003851 var integer count := 0;
3852 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003853 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3854 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003855 }
3856 for (var integer i:= 0; i < m; i := i + 1) {
3857 var integer fn_mod51 := arr[i].frame_number mod 51;
3858 if (not bcch_ext and fn_mod51 == 2 or
3859 bcch_ext and fn_mod51 == 6) {
3860 if (arr[i].si.header.message_type == key) {
3861 count := count + 1;
3862 }
3863 }
3864 }
3865 if (count >= n) {
3866 return true;
3867 } else {
3868 return false;
3869 }
3870}
3871
3872/* 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 +07003873private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3874 integer tc, RrMessageType key,
3875 boolean ext_bcch := false,
3876 integer n, integer m)
3877{
Harald Welte48494ca2018-02-25 16:59:50 +01003878 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003879 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003880 }
3881}
3882
3883/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003884private function f_si_vecslot_contains_only(SystemInformationVector arr,
3885 RrMessageType key,
3886 boolean bcch_ext := false)
3887return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003888 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3889 var integer fn_mod51 := arr[i].frame_number mod 51;
3890 if (not bcch_ext and fn_mod51 == 2 or
3891 bcch_ext and fn_mod51 == 6) {
3892 if (arr[i].si.header.message_type != key) {
3893 return false;
3894 }
3895 }
3896 }
3897 return true;
3898}
3899
3900/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003901private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3902 integer tc, RrMessageType key,
3903 boolean ext_bcch := false)
3904{
Harald Welte48494ca2018-02-25 16:59:50 +01003905 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003906 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003907 }
3908}
3909
3910/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003911private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003912 boolean bcch_extended,
3913 boolean si1_present,
3914 boolean si2bis_present,
3915 boolean si2ter_present,
3916 boolean si2quater_present,
3917 boolean si7_present,
3918 boolean si8_present,
3919 boolean si9_present,
3920 boolean si13_present,
3921 boolean si13alt_present,
3922 boolean si15_present,
3923 boolean si16_present,
3924 boolean si17_present,
3925 boolean si2n_present,
3926 boolean si21_present,
3927 boolean si22_present
3928}
3929
3930/* 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 +07003931private function f_validate_si_scheduling(SystemInformationConfig cfg,
3932 SystemInformationVectorPerTc si_per_tc)
3933{
Harald Welte48494ca2018-02-25 16:59:50 +01003934 var integer i;
3935 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3936 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003937 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003938 }
3939 }
3940 if (cfg.si1_present) {
3941 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3942 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3943 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3944 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3945 /* make sure *ALL* contain SI1 */
3946 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3947 }
3948 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3949 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3950 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3951 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3952 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3953 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3954
3955 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3956 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3957 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3958 * consecutive occurrences of TC = 4. */
3959 if (cfg.si2bis_present and not cfg.si2ter_present) {
3960 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3961 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3962 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3963 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3964 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3965 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3966 }
3967
3968 if (cfg.si7_present or cfg.si8_present) {
3969 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3970 * if System Information type 4 does not contain all information needed for cell
3971 * selection and reselection. */
3972 if (not cfg.bcch_extended) {
3973 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3974 }
3975 if (cfg.si7_present) {
3976 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3977 }
3978 if (cfg.si8_present) {
3979 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3980 }
3981 }
3982
3983 if (cfg.si2quater_present) {
3984 /* iii) System information type 2 quater is sent if needed, as determined by the system
3985 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3986 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3987 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3988 * within any of 4 consecutive occurrences of TC = 5. */
3989 if (not (cfg.bcch_extended)) {
3990 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3991 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3992 } else {
3993 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3994 }
3995 } else {
3996 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3997 }
3998 }
3999 if (cfg.si9_present) {
4000 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4001 * in system information type 3 as defined in 3GPP TS 44.018. */
4002 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4003 }
4004 if (cfg.si13_present) {
4005 /* vii) System Information type 13 is only related to the GPRS service. System Information
4006 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4007 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4008 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4009 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4010 * within any of 4 consecutive occurrences of TC=4. */
4011 if (not cfg.bcch_extended) {
4012 log("not-bccch-extended");
4013 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4014 } else {
4015 log("bccch-extended");
4016 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4017 }
4018 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004020 }
4021 }
4022 if (cfg.si16_present or cfg.si17_present) {
4023 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4024 * should not be sent in a cell where network sharing is used (see rule xv). */
4025 if (cfg.si22_present) {
4026 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4027 }
4028 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004030 }
4031 if (not cfg.bcch_extended) {
4032 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4033 }
4034 if (cfg.si16_present) {
4035 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4036 }
4037 if (cfg.si17_present) {
4038 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4039 }
4040 }
4041
4042 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4043 * broadcast information. The frequency with which they are sent is determined by the
4044 * system operator. System Information type 9 identifies the scheduling of System
4045 * Information type 18 and 20 messages. */
4046
4047 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4048 * Information Type 19 is present, then its scheduling shall be indicated in System
4049 * Information Type 9. */
4050
4051 if (cfg.si15_present) {
4052 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4053 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4054 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4055 * 4 consecutive occurrences of TC = 1. */
4056 if (not cfg.bcch_extended) {
4057 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4058 } else {
4059 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4060 }
4061 }
4062 if (cfg.si13alt_present) {
4063 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4064 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4065 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4066 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4067 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4068 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4069 * of TC = 4. */
4070 if (cfg.si13_present) {
4071 testcase.stop("Error: Cannot have SI13alt and SI13");
4072 }
4073 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004075 }
4076 if (not cfg.bcch_extended) {
4077 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4078 } else {
4079 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4080 }
4081 }
4082 if (cfg.si2n_present) {
4083 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4084 * as determined by the system operator. In the case that the message is sent on the
4085 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4086 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4087 * consecutive occurrences of TC = 4. */
4088 if (not cfg.bcch_extended) {
4089 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4090 } else {
4091 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4092 }
4093 }
4094 if (cfg.si21_present) {
4095 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4096 * determined by the system operator. If Extended Access Barring is in use in the cell
4097 * then this message is sent at least once within any of 4 consecutive occurrences of
4098 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4099 * cell then this message shall only be sent on BCCH Ext. */
4100 if (not cfg.bcch_extended) {
4101 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4102 } else {
4103 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4104 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004105 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004106 }
4107 }
4108 }
4109 if (cfg.si22_present) {
4110 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4111 * should not be sent in a cell where SoLSA is used (see rule viii). System
4112 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4113 * =2 and TC=6. */
4114 if (cfg.si16_present or cfg.si17_present) {
4115 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4116 }
4117 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4118 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004120 }
4121 if (not cfg.bcch_extended) {
4122 testcase.stop("Error: SI22 requires BCCH Extd!");
4123 } else {
4124 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4125 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4126 }
4127 }
4128}
4129
4130/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004131private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4132return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004133 timer T := duration;
4134 var SystemInformationVectorPerTc si_per_tc;
4135 var L1ctlDlMessage l1_dl;
4136
4137 /* initialize all per-TC vectors empty */
4138 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4139 si_per_tc[i] := {};
4140 }
4141
4142 /* flush all previous L1 queued msgs */
4143 pt.clear;
4144
4145 T.start;
4146 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004147 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004148 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4149 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4150 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004151 repeat;
4152 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004153
Harald Welte48494ca2018-02-25 16:59:50 +01004154 var integer tc := f_gsm_compute_tc(sig.frame_number);
4155 log("SI received at TC=", tc, ": ", sig.si);
4156 /* append to the per-TC bucket */
4157 si_per_tc[tc] := si_per_tc[tc] & { sig };
4158 repeat;
4159 }
4160 [] pt.receive { repeat; }
4161 [] T.timeout { }
4162 }
4163
4164 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4165 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4166 }
4167 log("si_per_tc=", si_per_tc);
4168 return si_per_tc;
4169}
4170
4171/* helper function: Set given SI via RSL + validate scheduling.
4172 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004173private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004174 var SystemInformationVectorPerTc si_per_tc;
4175 f_init_l1ctl();
4176 f_l1_tune(L1CTL);
4177
4178 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004179 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004180 f_validate_si_scheduling(si_cfg, si_per_tc);
4181
4182 setverdict(pass);
4183}
4184
4185testcase TC_si_sched_default() runs on test_CT {
4186 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004187 /* 2+3+4 are mandatory and set in f_init() */
4188 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004190}
4191
4192testcase TC_si_sched_1() runs on test_CT {
4193 f_init();
4194 si_cfg.si1_present := true;
4195 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004196 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004197 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004198}
4199
4200testcase TC_si_sched_2bis() runs on test_CT {
4201 f_init();
4202 si_cfg.si2bis_present := true;
4203 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4204 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004206}
4207
4208testcase TC_si_sched_2ter() runs on test_CT {
4209 f_init();
4210 si_cfg.si2ter_present := true;
4211 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4212 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004213 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004214}
4215
4216testcase TC_si_sched_2ter_2bis() runs on test_CT {
4217 f_init();
4218 si_cfg.si2bis_present := true;
4219 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4220 si_cfg.si2ter_present := true;
4221 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4222 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004223 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004224}
4225
4226testcase TC_si_sched_2quater() runs on test_CT {
4227 f_init();
4228 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004229 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004230 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004231 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004232}
4233
4234testcase TC_si_sched_13() runs on test_CT {
4235 f_init();
4236 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004237 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004238 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004240}
4241
4242testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4243 f_init();
4244 si_cfg.si2bis_present := true;
4245 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4246 si_cfg.si2ter_present := true;
4247 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4248 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004249 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004250 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004251 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004252 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004254}
4255
4256
Harald Welte68e495b2018-02-25 00:05:57 +01004257testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004258 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004259 /* FIXME: enable / disable individual BCCH info */
4260 //ts_RSL_BCCH_INFO(si_type, info);
4261 /* expect no ERROR REPORT after either of them *
4262 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004263 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004264}
4265
Harald Welte93640c62018-02-25 16:59:33 +01004266/***********************************************************************
4267 * Low-Level Protocol Errors / ERROR REPORT
4268 ***********************************************************************/
4269
Harald Welte01d982c2018-02-25 01:31:40 +01004270private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4271 timer T := 5.0;
4272 T.start;
4273 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004274 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004275 setverdict(pass);
4276 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004277 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004279 }
4280 [] RSL_CCHAN.receive {
4281 repeat;
4282 }
4283 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004285 }
4286 }
4287}
4288
4289/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4290testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004291 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004292 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4293 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004294 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004295
4296 f_exp_err_rep(RSL_ERR_PROTO);
4297}
4298
4299/* Provoke a mandatory IE error and match on ERROR REPORT */
4300testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004301 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004302
4303 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4304 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004305 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004306
4307 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4308}
4309
4310/* Provoke an IE content error and match on ERROR REPORT */
4311testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004312 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004313 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4314 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004315 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004316
4317 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4318}
4319
Harald Welteee25aae2019-05-19 14:32:37 +02004320/* attempt to activate channel with wrong RSL Message Discriminator IE */
4321function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4322 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4323 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4324 RSL.send(rsl);
4325 f_rslem_unregister(0, g_chan_nr);
4326}
4327testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4328 var ConnHdlr vc_conn;
4329 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4330
Harald Welte10474062019-05-30 16:48:17 +02004331 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004332
4333 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4334 vc_conn.done;
4335 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4336
4337 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4338}
4339
4340/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004341private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004342 var template (value) RSL_Message rsl_tx;
4343 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4344 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4345 RSL.send(rsl_tx);
4346 f_rslem_unregister(0, g_chan_nr);
4347}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004348private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004349 var template (value) RSL_Message rsl_tx;
4350 /* we first have to activate the dedicated channel */
4351 f_rsl_chan_act(g_pars.chan_mode);
4352 /* ... to then send an invalid RLL message */
4353 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4354 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4355 RSL.send(rsl_tx);
4356 f_rslem_unregister(0, g_chan_nr);
4357}
4358testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4359 var ConnHdlr vc_conn;
4360 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4361 var template (value) RSL_Message rsl_tx;
4362
Harald Welte10474062019-05-30 16:48:17 +02004363 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004364
4365 /* Common Channel with wrong message type */
4366 RSL_CCHAN.clear;
4367 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4368 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004369 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004370 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4371
4372 /* TRX Management */
4373 RSL_CCHAN.clear;
4374 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4375 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004376 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004377 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4378
4379 /* Dedicated Channel */
4380 RSL_CCHAN.clear;
4381 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4382 vc_conn.done;
4383 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4384
4385 /* RLL */
4386 RSL_CCHAN.clear;
4387 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4388 vc_conn.done;
4389 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4390}
4391
4392/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004393private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004394 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4395 f_rslem_unregister(0, g_chan_nr);
4396}
4397testcase TC_err_rep_wrong_sequence() runs on test_CT {
4398 var ConnHdlr vc_conn;
4399 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4400
Harald Welte10474062019-05-30 16:48:17 +02004401 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004402
4403 RSL_CCHAN.clear;
4404 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4405 vc_conn.done;
4406 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4407}
4408
Harald Welte93640c62018-02-25 16:59:33 +01004409/***********************************************************************
4410 * IPA CRCX/MDCX/DLCS media stream handling
4411 ***********************************************************************/
4412
Harald Weltea871a382018-02-25 02:03:14 +01004413/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004414private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004415 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4416 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004417}
4418testcase TC_ipa_dlcx_not_active() runs on test_CT {
4419 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004420 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004421 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4422 vc_conn.done;
4423}
Harald Welte68e495b2018-02-25 00:05:57 +01004424
Harald Weltea3f1df92018-02-25 12:49:55 +01004425/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004426private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004427 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4428 "IPA CRCX ACK");
4429 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4430 "IPA CRCX NACK");
4431}
4432testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4433 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004434 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004435 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4436 vc_conn.done;
4437}
4438
4439/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004440private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004441 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4442 "IPA CRCX ACK");
4443 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4444 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4445 var uint7_t rtp_pt2 := f_rnd_int(127);
4446 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4447 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4448 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4449 "IPA MDCX ACK");
4450 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4451 "IPA DLCX ACK");
4452}
4453testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4454 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004455 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004456 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4457 vc_conn.done;
4458}
4459
Harald Welte3ae11da2018-02-25 13:36:06 +01004460/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004461private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004462 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4463 "IPA CRCX ACK");
4464 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4465 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4466 var uint7_t rtp_pt2 := f_rnd_int(127);
4467 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4468 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4469 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4470 "IPA MDCX ACK");
4471 /* Second MDCX */
4472 remote_ip := f_rnd_int(c_UINT32_MAX);
4473 remote_port := f_rnd_int(c_UINT16_MAX);
4474 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4475 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4476 "IPA MDCX ACK");
4477 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4478 "IPA DLCX ACK");
4479}
4480testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4481 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004482 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004483 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4484 vc_conn.done;
4485}
4486
Harald Welte9912eb52018-02-25 13:30:15 +01004487/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004488private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004489 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4490 "IPA CRCX NACK");
4491}
4492testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4493 var ConnHdlrPars pars;
4494 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004495 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004496
4497 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4498 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4499 vc_conn.done;
4500
4501 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4502 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4503 vc_conn.done;
4504}
4505
Harald Weltea3f1df92018-02-25 12:49:55 +01004506
Harald Welte883340c2018-02-28 18:59:29 +01004507/***********************************************************************
4508 * PCU Socket related tests
4509 ***********************************************************************/
4510
Harald Welte07bd2d22019-05-25 11:03:30 +02004511/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004512friend 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 +01004513runs on test_CT {
4514 timer T := 3.0;
4515
4516 /* we don't expect any RTS.req before PDCH are active */
4517 T.start;
4518 alt {
4519 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004520 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004521 }
4522 [] PCU.receive { repeat; }
4523 [] T.timeout { }
4524 }
4525
4526 /* Send PDCH activate request for known PDCH timeslot */
4527 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4528
4529 /* we now expect RTS.req for this timeslot (only) */
4530 T.start;
4531 alt {
4532 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4533 setverdict(pass);
4534 }
4535 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4536 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004538 }
4539 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004541 }
4542 [] PCU.receive { repeat; }
4543 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004544 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004545 }
4546 [not exp_success] T.timeout {
4547 setverdict(pass);
4548 }
4549 }
4550}
4551
Harald Welte07bd2d22019-05-25 11:03:30 +02004552/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004553friend 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 +01004554runs on test_CT {
4555 timer T := 3.0;
4556
4557 /* Send PDCH activate request for known PDCH timeslot */
4558 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 +02004559 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4560 * when it will actually have been executed in the BTS */
4561 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004562 PCU.clear;
4563 /* we now expect no RTS.req for this timeslot */
4564 T.start;
4565 alt {
4566 [] 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 +02004567 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004568 }
4569 [] PCU.receive { repeat; }
4570 [] T.timeout {
4571 setverdict(pass);
4572 }
4573 }
4574}
4575
Harald Weltead033dc2019-05-25 17:28:16 +02004576friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004577 f_init();
4578 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4579}
4580
Harald Welte883340c2018-02-28 18:59:29 +01004581/* PDCH activation via PCU socket; check for presence of RTS.req */
4582testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004583 f_init_pcu_test();
4584
Harald Welte883340c2018-02-28 18:59:29 +01004585 f_TC_pcu_act_req(0, 0, 7, true);
4586}
4587
4588/* PDCH activation via PCU socket on non-PDCU timeslot */
4589testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004590 f_init_pcu_test();
4591
Harald Welte883340c2018-02-28 18:59:29 +01004592 f_TC_pcu_act_req(0, 0, 1, false);
4593}
4594
4595/* PDCH activation via PCU socket on wrong BTS */
4596testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004597 f_init_pcu_test();
4598
Harald Welte883340c2018-02-28 18:59:29 +01004599 f_TC_pcu_act_req(23, 0, 7, false);
4600}
4601
4602/* PDCH activation via PCU socket on wrong TRX */
4603testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004604 f_init_pcu_test();
4605
Harald Welte883340c2018-02-28 18:59:29 +01004606 f_TC_pcu_act_req(0, 23, 7, false);
4607}
4608
4609/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4610testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004611 f_init_pcu_test();
4612
Harald Welte883340c2018-02-28 18:59:29 +01004613 /* Activate PDCH */
4614 f_TC_pcu_act_req(0, 0, 7, true);
4615 f_sleep(1.0);
4616 /* and De-Activate again */
4617 f_TC_pcu_deact_req(0, 0, 7);
4618}
4619
4620/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4621testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004622 f_init_pcu_test();
4623
Harald Welte883340c2018-02-28 18:59:29 +01004624 f_TC_pcu_deact_req(0, 0, 1);
4625}
4626
4627/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4628testcase TC_pcu_ver_si13() runs on test_CT {
4629 const octetstring si13 := '00010203040506070909'O;
4630 var PCUIF_send_data sd;
4631 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004632 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004633
4634 /* Set SI13 via RSL */
4635 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004636
Harald Welte883340c2018-02-28 18:59:29 +01004637 T.start;
4638 alt {
4639 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4640 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4641 setverdict(pass);
4642 } else {
4643 repeat;
4644 }
4645 }
4646 [] PCU.receive { repeat; }
4647 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004649 }
4650 }
4651}
4652
4653private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4654
4655/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004656friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004657 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4658runs on test_CT
4659{
4660 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4661 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4662}
4663
4664/* 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 +02004665friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4666 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004667runs on test_CT
4668{
4669 var PCUIF_send_data sd;
4670
4671 timer T := 3.0;
4672 T.start;
4673 alt {
4674 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4675 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4676 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4677 sd.data.u.rts_req.fn, sapi, data);
4678 }
4679 [] PCU.receive { repeat; }
4680 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004681 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004682 }
4683 }
4684}
4685
4686/* Send DATA.req on invalid BTS */
4687testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004688 var TfiUsfArr tua := f_TfiUsfArrInit();
4689 var octetstring data := '0000'O & f_rnd_octstring(21);
4690
4691 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004692
Harald Welte883340c2018-02-28 18:59:29 +01004693 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004694 f_TfiUsfArrSet(tua, 7, 0);
4695 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4696 f_sleep(1.0);
4697
4698 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004699}
4700
4701/* Send DATA.req on invalid TRX */
4702testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004703 var TfiUsfArr tua := f_TfiUsfArrInit();
4704 var octetstring data := '0000'O & f_rnd_octstring(21);
4705
4706 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004707
Harald Welte883340c2018-02-28 18:59:29 +01004708 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004709 f_TfiUsfArrSet(tua, 7, 0);
4710 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4711 f_sleep(1.0);
4712
4713 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004714}
4715
4716/* Send DATA.req on invalid timeslot */
4717testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004718 var TfiUsfArr tua := f_TfiUsfArrInit();
4719 var octetstring data := '0000'O & f_rnd_octstring(21);
4720
4721 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004722
Harald Welte883340c2018-02-28 18:59:29 +01004723 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004724 f_TfiUsfArrSet(tua, 7, 0);
4725 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4726 f_sleep(1.0);
4727
4728 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004729}
4730
4731/* Send DATA.req on timeslot that hasn't been activated */
4732testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004733 var TfiUsfArr tua := f_TfiUsfArrInit();
4734 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004735
Harald Welte7162a612019-05-26 12:56:09 +02004736 f_virtphy_common();
4737
4738 f_TfiUsfArrSet(tua, 7, 0);
4739 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4740 f_sleep(1.0);
4741
4742 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004743}
4744
Harald Weltead033dc2019-05-25 17:28:16 +02004745private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004746 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4747 boolean wait_rts := true)
4748runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004749 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004750 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004751
4752 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004753 if (wait_rts) {
4754 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4755 } else {
4756 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4757 }
Harald Weltead033dc2019-05-25 17:28:16 +02004758
4759 T.start;
4760 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004761 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004762 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4763 setverdict(pass);
4764 }
Harald Welte7162a612019-05-26 12:56:09 +02004765 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4766 setverdict(fail, "Received unexpected ", rx_dl);
4767 }
Harald Weltead033dc2019-05-25 17:28:16 +02004768 [] L1CTL.receive {
4769 repeat;
4770 }
Harald Welte7162a612019-05-26 12:56:09 +02004771 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004772 setverdict(fail, "Timeout waiting for ", data);
4773 }
Harald Welte7162a612019-05-26 12:56:09 +02004774 [not expect_data] T.timeout {
4775 setverdict(pass);
4776 }
Harald Weltead033dc2019-05-25 17:28:16 +02004777 }
4778}
4779
4780private function f_disable_dynamic_ts() runs on test_CT
4781{
4782 f_init_vty_bsc();
4783 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4784 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4785 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4786 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004787 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004788}
4789
4790private function f_virtphy_common() runs on test_CT {
4791 f_disable_dynamic_ts();
4792 f_init_l1ctl();
4793 f_l1_tune(L1CTL);
4794}
4795
4796testcase TC_pcu_data_req_pdtch() runs on test_CT {
4797 var TfiUsfArr tua := f_TfiUsfArrInit();
4798 var octetstring data := '0000'O & f_rnd_octstring(21);
4799
4800 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004801
Harald Welte883340c2018-02-28 18:59:29 +01004802 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004803 f_TfiUsfArrSet(tua, 7, 0);
4804 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4805 f_sleep(1.0);
4806
4807 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004808}
4809
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004810/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004811testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004812 var TfiUsfArr tua := f_TfiUsfArrInit();
4813 var octetstring data := '0000'O & f_rnd_octstring(21);
4814
4815 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004816
Harald Welte883340c2018-02-28 18:59:29 +01004817 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004818 f_TfiUsfArrSet(tua, 7, 0);
4819 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4820 f_sleep(1.0);
4821
4822 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004823}
4824
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004825private function f_TC_pcu_ptcch_ul(uint16_t ra)
4826runs on test_CT {
4827 var template PCUIF_Message pcu_rach_ind;
4828 var PCUIF_send_data sd;
4829 var GsmFrameNumber fn;
4830 timer T;
4831
4832 /* Send an Access Burst on PTCCH/U over the Um-interface */
4833 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4834 chan_nr := ts_RslChanNr_PDCH(7),
4835 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4836
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004837 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4838 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004839
4840 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4841 T.start(52.0 * 4.615 / 1000.0);
4842 alt {
4843 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4844 log("Rx an Access Burst on the PCU interface: ", sd.data);
4845 setverdict(pass);
4846 T.stop;
4847 }
4848 [] PCU.receive { repeat; }
4849 [] T.timeout {
4850 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4851 /* Keep going, that's not the end of the world */
4852 }
4853 }
4854}
4855
4856testcase TC_pcu_ptcch() runs on test_CT {
4857 var L1ctlDlMessage dl;
4858 var octetstring data;
4859 timer T;
4860
4861 f_init_pcu_test();
4862 f_init_l1ctl();
4863 f_l1_tune(L1CTL);
4864
4865 /* Activate PDCH channel on TS7 */
4866 f_TC_pcu_act_req(0, 0, 7, true);
4867
4868 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004869 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004870 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004871 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004872 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004873
4874 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4875 for (var integer i := 0; i < 16; i := i + 1) {
4876 log("Sending an Access Burst towards the L1CTL interface");
4877 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4878 }
4879
4880 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4881 data := f_rnd_octstring(23);
4882
4883 /* Verify PTCCH/D: send a random data block, make sure it's received */
4884 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4885 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4886
4887 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4888 * let's give it more time in case if we miss the beginning. */
4889 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4890 alt {
4891 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4892 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4893 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4894 frame := data)) -> value dl {
4895 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4896 setverdict(pass);
4897 T.stop;
4898 }
4899 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4900 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4901 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4902 l2_data := data)) -> value dl {
4903 log("Rx PTCCH/D data block on L1CTL: ", dl);
4904 setverdict(pass);
4905 T.stop;
4906 }
4907 [] L1CTL.receive { repeat; }
4908 [] T.timeout {
4909 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4910 }
4911 }
4912}
4913
Harald Welte883340c2018-02-28 18:59:29 +01004914/* Send AGCH from PCU; check it appears on Um side */
4915testcase TC_pcu_data_req_agch() runs on test_CT {
4916 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004917 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004918 f_init_l1ctl();
4919 f_l1_tune(L1CTL);
4920
4921 f_TC_pcu_act_req(0, 0, 7, true);
4922 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4923
4924 T.start;
4925 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004926 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004927 setverdict(pass);
4928 }
4929 [] L1CTL.receive { repeat; }
4930 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004931 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004932 }
4933 }
4934}
4935
Harald Welte928622b2019-05-26 13:22:59 +02004936/* Send AGCH from PCU; check it appears on Um side */
4937testcase TC_pcu_data_req_pch() runs on test_CT {
4938 timer T := 3.0;
4939 f_init_pcu_test();
4940 f_init_l1ctl();
4941 f_l1_tune(L1CTL);
4942
4943 f_TC_pcu_act_req(0, 0, 7, true);
4944 /* three characters prefix: last 3 digits of IMSI as ASCII */
4945 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4946
4947 T.start;
4948 alt {
4949 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4950 setverdict(pass);
4951 }
4952 [] L1CTL.receive { repeat; }
4953 [] T.timeout {
4954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4955 }
4956 }
4957}
4958
Harald Welte883340c2018-02-28 18:59:29 +01004959/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4960testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4961 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004962 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004963 f_init_l1ctl();
4964 f_l1_tune(L1CTL);
4965
4966 /* append 3 last imsi digits so BTS can compute pagng group */
4967 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4968
4969 timer T := 0.5;
4970 T.start;
4971 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004972 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004973 /* TODO: verify paging group */
4974 setverdict(pass);
4975 }
4976 [] L1CTL.receive { repeat; }
4977 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004979 }
4980 }
4981}
4982
4983/* Send RACH from Um side, expect it to show up on PCU socket */
4984testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004985 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004986 f_init_l1ctl();
4987 f_l1_tune(L1CTL);
4988
4989 var GsmFrameNumber fn_last := 0;
4990 for (var integer i := 0; i < 1000; i := i+1) {
4991 var OCT1 ra := f_rnd_ra_ps();
4992 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4993 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004994 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004995 }
4996 fn_last := fn;
4997
4998 timer T := 2.0;
4999 T.start;
5000 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005001 [] 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 +01005002 T.stop;
5003 }
5004 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005006 }
5007 [] PCU.receive { repeat; }
5008 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005010 }
5011 }
5012 }
5013 setverdict(pass);
5014}
5015
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005016/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5017 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5018testcase TC_pcu_ext_rach_content() runs on test_CT {
5019 var template PCUIF_Message pcu_rach_ind;
5020 var GsmFrameNumber fn_last := 0;
5021 var L1ctlRachSynchSeq synch_seq;
5022 var PCUIF_BurstType pcu_bt;
5023 var GsmFrameNumber fn;
5024 var BIT11 ra11;
5025
5026 f_init_pcu_test();
5027 f_init_l1ctl();
5028 f_l1_tune(L1CTL);
5029
5030 for (var integer i := 0; i < 1000; i := i+1) {
5031 /* We need to test both TS1 & TS2 */
5032 if (i rem 2 == 0) {
5033 synch_seq := RACH_SYNCH_SEQ_TS1;
5034 pcu_bt := BURST_TYPE_1;
5035 } else {
5036 synch_seq := RACH_SYNCH_SEQ_TS2;
5037 pcu_bt := BURST_TYPE_2;
5038 }
5039
5040 ra11 := f_rnd_ra11_ps();
5041 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5042 if (fn == fn_last) {
5043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5044 "Two RACH in same FN?!?");
5045 }
5046 fn_last := fn;
5047
5048 /* Compose the expected message */
5049 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005050 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005051 ra := bit2int(ra11),
5052 is_11bit := 1,
5053 burst_type := pcu_bt,
5054 fn := fn);
5055
5056 timer T := 2.0;
5057 T.start;
5058 alt {
5059 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5060 T.stop;
5061 }
5062 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5063 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5064 }
5065 [] PCU.receive { repeat; }
5066 [] T.timeout {
5067 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5068 }
5069 }
5070 }
5071 setverdict(pass);
5072}
5073
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005074private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5075runs on test_CT {
5076 var template PCUIF_send_data sdt;
5077 var PCUIF_send_data sd;
5078 var int16_t lqual_cb;
5079 timer T := 1.0;
5080
5081 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5082 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5083
5084 /* Send a random PDTCH frame over Um */
5085 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5086 '0000'O & f_rnd_octstring(21)));
5087
5088 T.start;
5089 alt {
5090 /* If expected link quality is above the threshold */
5091 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5092 lqual_cb := sd.data.u.data_ind.lqual_cb;
5093 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5094
5095 /* Make sure the actual link quality matches the expected value */
5096 if (not match(lqual_cb, lqual_cb_exp)) {
5097 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5098 "expected value ", lqual_cb_exp));
5099 } else {
5100 setverdict(pass);
5101 }
5102 }
5103 /* If expected link quality is below the threshold */
5104 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5105 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5106 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5107 }
5108 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5109 [] PCU.receive { repeat; }
5110 [lqual_cb_exp < thresh] T.timeout {
5111 log("Rx nothing, as expected");
5112 setverdict(pass);
5113 }
5114 [lqual_cb_exp >= thresh] T.timeout {
5115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5116 "Timeout waiting for PCUIF_DATA.ind");
5117 }
5118 }
5119}
5120
5121/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5122testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
5123 f_init_pcu_test();
5124 PCU.clear;
5125
5126 f_init_l1ctl();
5127 f_l1_tune(L1CTL);
5128
5129 /* Activate a PDCH channel on TS7 */
5130 f_TC_pcu_act_req(0, 0, 7, true);
5131
5132 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005133 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005134 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005135 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005136 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005137
5138 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5139 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5140 var TrxcMessage ret;
5141
5142 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5143 valueof(ts_TRXC_FAKE_CI(i)));
5144
5145 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5146 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5147 }
5148}
5149
Harald Welte883340c2018-02-28 18:59:29 +01005150/* Send PAGING via RSL, expect it to shw up on PCU socket */
5151testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005152 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01005153
5154 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005155 var MobileIdentityLV mi_lv;
5156 var octetstring mi_lv_enc;
5157 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005158 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005159
Harald Welte883340c2018-02-28 18:59:29 +01005160 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005161 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005162 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005163 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005164 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005165
5166 /* Fancy encoding for PCUIF */
5167 mi_lv := valueof(ts_MI_LV(mi));
5168 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5169 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005170
5171 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005172 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005173 T.start;
5174 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005175 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005176 }
5177 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005178 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005179 }
5180 [] PCU.receive { repeat; }
5181 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005183 }
5184 }
5185 }
5186 setverdict(pass);
5187}
5188
Harald Welted66c9b82019-05-25 09:03:15 +02005189/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5190testcase TC_pcu_time_ind() runs on test_CT {
5191 var PCUIF_send_data pcu_sd;
5192 var integer num_time_ind := 0;
5193 var integer first_fn, last_fn;
5194 var float test_duration := 5.0;
5195 timer T;
5196
5197 f_init_pcu_test();
5198 f_TC_pcu_act_req(0, 0, 7, true);
5199
5200 PCU.clear;
5201 T.start(test_duration);
5202 alt {
5203 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5204 num_time_ind := num_time_ind + 1;
5205 if (not isbound(first_fn)) {
5206 first_fn := pcu_sd.data.u.time_ind.fn;
5207 }
5208 last_fn := pcu_sd.data.u.time_ind.fn;
5209 repeat;
5210 }
5211 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5212 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5213 repeat;
5214 }
5215 [] PCU.receive {
5216 repeat;
5217 }
5218 [] T.timeout {}
5219 }
5220 var integer fn_expired := last_fn - first_fn;
5221 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5222
5223 /* verify the number of frames expired matches our expectation */
5224 const float c_GSM_FN_DURATION_MS := 4.61538;
5225 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005226 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005227 if (not match(fn_expired, t_fn_expected)) {
5228 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5229 }
5230
5231 /* There are three TIME.ind in every fn MOD 13 */
5232 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5233 /* Add some tolerance */
5234 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5235 if (not match(num_time_ind, t_time_ind_exp)) {
5236 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5237 }
5238
5239 setverdict(pass);
5240}
5241
Harald Welte4832c862019-05-25 14:57:18 +02005242/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5243testcase TC_pcu_rts_req() runs on test_CT {
5244 var PCUIF_send_data pcu_sd;
5245 var integer first_fn, last_fn;
5246 var integer num_rts_pdtch := 0;
5247 var integer num_rts_ptcch := 0;
5248 var float test_duration := 5.0;
5249 timer T;
5250
5251 f_init_pcu_test();
5252 f_TC_pcu_act_req(0, 0, 7, true);
5253
5254 PCU.clear;
5255 T.start(test_duration);
5256 alt {
5257 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5258 -> value pcu_sd {
5259 num_rts_pdtch := num_rts_pdtch + 1;
5260 if (not isbound(first_fn)) {
5261 first_fn := pcu_sd.data.u.rts_req.fn;
5262 }
5263 last_fn := pcu_sd.data.u.rts_req.fn;
5264 repeat;
5265 }
5266 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5267 -> value pcu_sd {
5268 num_rts_ptcch := num_rts_ptcch + 1;
5269 if (not isbound(first_fn)) {
5270 first_fn := pcu_sd.data.u.rts_req.fn;
5271 }
5272 last_fn := pcu_sd.data.u.rts_req.fn;
5273 repeat;
5274 }
5275 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5276 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5277 repeat;
5278 }
5279 [] PCU.receive {
5280 repeat;
5281 }
5282 [] T.timeout {}
5283 }
5284 var integer fn_expired := last_fn - first_fn;
5285 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5286 ", num_rts_ptcch=", num_rts_ptcch);
5287
5288 /* verify the number of frames expired matches our expectation */
5289 const float c_GSM_FN_DURATION_MS := 4.61538;
5290 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005291 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005292 if (not match(fn_expired, t_fn_expected)) {
5293 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5294 }
5295
5296 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5297 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5298 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5299 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5300 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5301 t_ptcch_exp);
5302 }
5303
5304 /* We have 12 PDTCH blocks every 52-multiframe */
5305 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5306 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5307 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5308 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5309 t_pdtch_exp);
5310 }
5311
5312 setverdict(pass);
5313}
5314
Harald Welte07bd2d22019-05-25 11:03:30 +02005315/* test for generating Abis side OML ALERT from the PCU */
5316testcase TC_pcu_oml_alert() runs on test_CT {
5317 var PCUIF_send_data pcu_sd;
5318 var integer num_time_ind := 0;
5319 var integer first_fn, last_fn;
5320 var float test_duration := 5.0;
5321 timer T;
5322
5323 f_init_pcu_test();
5324 f_TC_pcu_act_req(0, 0, 7, true);
5325
5326 /* re-connect CTRL port from BTS to BSC */
5327 f_ipa_ctrl_stop();
5328 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5329
5330 /* Send that OML Alert */
5331 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5332
5333 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5334 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5335 setverdict(pass);
5336}
5337
Harald Welteeaa9a862019-05-26 23:01:08 +02005338/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5339private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5340 var PCUIF_Message first_info;
5341 var integer pcu_conn_id := -1;
5342 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5343 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5344 var OCT4 tlli := '01020304'O;
5345 var OCT1 cause := '23'O;
5346 timer T := 5.0;
5347
5348 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5349
5350 f_l1_tune(L1CTL);
5351 RSL.clear;
5352
5353 f_est_dchan();
5354 L1CTL.clear;
5355
5356 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5357
5358 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5359 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5360 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5361
5362 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5363 T.start;
5364 alt {
5365 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5366 setverdict(pass);
5367 }
5368 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5369 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5370 }
5371 [] PCU.receive {
5372 repeat;
5373 }
5374 [] T.timeout {
5375 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5376 }
5377 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005378
5379 /* release the channel */
5380 f_rsl_chan_deact();
5381 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5382 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005383}
5384testcase TC_pcu_rr_suspend() runs on test_CT {
5385 var ConnHdlrPars pars;
5386 var ConnHdlr vc_conn;
5387
5388 f_init();
5389
5390 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5391 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5392 vc_conn.done;
5393}
Harald Welte07bd2d22019-05-25 11:03:30 +02005394
Harald Weltea2e0e942019-05-27 18:12:53 +02005395/* Ensure that PCUIF socket can accept only a single connection */
5396testcase TC_pcu_socket_connect_multi() runs on test_CT {
5397 timer T := 5.0;
5398
5399 /* this (among other things) establishes the first connection to the PCUIF socket */
5400 f_init();
5401
5402 /* try to establish a second connection, expect it to fail */
5403 PCU.send(UD_connect:{mp_pcu_socket, -1});
5404 T.start;
5405 alt {
5406 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5407 setverdict(pass);
5408 }
5409 [] PCU.receive(UD_connect_result:?) {
5410 setverdict(fail, "Unexpected unix domain connect result");
5411 }
5412 [] T.timeout {
5413 setverdict(pass);
5414 }
5415 }
5416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5417}
5418
Harald Weltec8effb72019-05-27 18:23:04 +02005419/* Ensure that PCUIF socket can disconnect + reconnect */
5420testcase TC_pcu_socket_reconnect() runs on test_CT {
5421 /* this (among other things) establishes the first connection to the PCUIF socket */
5422 f_init();
5423
5424 f_sleep(1.0);
5425
5426 f_pcuif_close(PCU, g_pcu_conn_id);
5427 g_pcu_conn_id := -1;
5428
5429 f_sleep(1.0);
5430
5431 /* re-connect */
5432 PCU.clear;
5433 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5434 setverdict(pass);
5435
5436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5437}
5438
Harald Weltebe030482019-05-27 22:29:35 +02005439/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005440private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5441runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005442 var L1ctlDlMessage l1_dl;
5443 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005444 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005445 timer T := 5.0;
5446 T.start;
5447 alt {
5448 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005449 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5450 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005451 repeat;
5452 }
5453 }
5454 [] pt.receive {
5455 repeat;
5456 }
5457 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5459 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005460 }
5461 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005462 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005463}
5464
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005465/* Check if GPRS Indicator is present in RR System Information of a given type */
5466private function f_si_has_gprs_indicator(RrMessageType si_type)
5467runs on test_CT return boolean {
5468 var SystemInformation si := f_get_si(L1CTL, si_type);
5469
5470 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005471 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005472 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005473 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005474 }
5475
5476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5477 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005478}
5479
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005480/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5481private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5482runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005483 /* don't call f_init() as this would connect PCU socket */
5484 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005485
5486 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005487 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005488 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005489
5490 f_init_l1ctl();
5491 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005492 f_sleep(2.0);
5493 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005494
5495 if (f_si_has_gprs_indicator(si_type)) {
5496 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005497 } else {
5498 setverdict(pass);
5499 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005500
Harald Weltebe030482019-05-27 22:29:35 +02005501 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5502}
5503
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005504testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5505 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5506}
Harald Weltebe030482019-05-27 22:29:35 +02005507
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005508testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5509 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5510}
5511
5512/* Ensure that GPRS capability is advertised after PCU socket connect */
5513private function f_TC_pcu_socket_connect(RrMessageType si_type)
5514runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005515 /* this (among other things) establishes the first connection to the PCUIF socket */
5516 f_init();
5517 f_init_l1ctl();
5518 f_l1_tune(L1CTL);
5519
5520 f_sleep(2.0);
5521 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005522
5523 if (not f_si_has_gprs_indicator(si_type)) {
5524 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005525 } else {
5526 setverdict(pass);
5527 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005528
Harald Weltebe030482019-05-27 22:29:35 +02005529 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5530}
5531
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005532testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5533 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5534}
Harald Weltebe030482019-05-27 22:29:35 +02005535
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005536testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5537 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5538}
5539
5540/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5541private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5542runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005543 /* this (among other things) establishes the first connection to the PCUIF socket */
5544 f_init();
5545 f_init_l1ctl();
5546 f_l1_tune(L1CTL);
5547
5548 f_pcuif_close(PCU, g_pcu_conn_id);
5549 g_pcu_conn_id := -1;
5550
5551 f_sleep(1.0);
5552
5553 /* re-connect */
5554 PCU.clear;
5555 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5556
5557 f_sleep(2.0);
5558 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005559
5560 if (f_si_has_gprs_indicator(si_type)) {
5561 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005562 } else {
5563 setverdict(pass);
5564 }
5565
5566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5567}
5568
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005569testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5570 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5571}
5572
5573testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5574 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5575}
5576
Oliver Smithf5239c72019-08-28 10:01:25 +02005577/* 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) */
5578testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5579 var SystemInformation si3 := valueof(ts_SI3_default);
5580
5581 f_init();
5582
Harald Welte76220222020-10-11 20:32:44 +02005583 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5584 * information */
5585 timer T := 2.0;
5586 T.start;
5587 alt {
5588 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5589 [] T.timeout {}
5590 }
5591
Oliver Smithf5239c72019-08-28 10:01:25 +02005592 /* Verify cell_id */
5593 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5594 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5595 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005596 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5597 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5598 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005599 }
5600
5601 /* Verify LAC */
5602 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5603 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5604 if (lac_si3 != lac_pcu) {
5605 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5606 }
5607
5608 setverdict(pass);
5609}
Harald Welted66c9b82019-05-25 09:03:15 +02005610
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005611/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5612testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5613 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005614 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005615
5616 f_init();
5617
5618 info_ind := g_pcu_last_info.u.info_ind;
5619
5620 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5621 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5622 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5623 /* Skip inactive timeslots */
5624 continue;
5625 }
5626
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005627 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005628 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005629 else
5630 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005631
5632 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005633 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005634 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005635 hsn := fhp.maio_hsn.hsn,
5636 maio := fhp.maio_hsn.maio,
5637 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005638 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005639 } else {
5640 tr_ts := tr_PCUIF_InfoTrxTsH0;
5641 }
5642
5643 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5644 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5645 if (not match(ts, tr_ts)) {
5646 setverdict(fail, "Hopping parameters do not match: ",
5647 "received ", ts, " vs expected ", tr_ts);
5648 } else {
5649 setverdict(pass);
5650 }
5651 }
5652 }
5653}
5654
Alexander Couzens5283f552020-07-28 15:39:04 +02005655/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5656testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5657 f_init_vty_bsc();
5658 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5659 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5660
5661 f_init();
5662
5663 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5664 if (not ischosen(remote_addr.v10)) {
5665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5666 log2str("Unexpected remote_addr: ", remote_addr));
5667 }
5668
5669 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5670 setverdict(fail, "Received address family is not IPv4");
5671 }
5672
5673 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5674 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5675 }
5676
5677 setverdict(pass);
5678}
5679
5680/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5681testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5682 f_init_vty_bsc();
5683 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5684
5685 f_init();
5686
5687 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5688 if (not ischosen(remote_addr.v10)) {
5689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5690 log2str("Unexpected remote_addr: ", remote_addr));
5691 }
5692
5693 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5694 setverdict(fail, "Received address family is not IPv6");
5695 }
5696
5697 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5698 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5699 }
5700
5701 setverdict(pass);
5702}
5703
Harald Welte3d04ae62018-04-04 20:29:05 +02005704/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005705 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005706 ***********************************************************************/
5707
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005708private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5709 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005710runs on ConnHdlr {
5711 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005712
5713 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy2a9acce2020-10-31 20:19:06 +07005714 var BIT8 pdch_mask := f_PCUIF_ver_INFO_PDCHMask_get(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005715 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5716 repeat;
5717 }
5718 }
5719}
5720
5721private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5722runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005723 /* Expect BTS to immediately acknowledge activation as PDCH */
5724 PCU.clear;
5725 f_rsl_chan_act(g_pars.chan_mode);
5726 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005727 timer T_wait := 2.0;
5728 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005729 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005730 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005731 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005732 [] T_wait.timeout {
5733 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5734 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5735 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005736 }
5737 /* try to activate this PDCH from the PCU point of view */
5738 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5739 /* FIXME: is there a response? */
5740}
5741
5742private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5743runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005744 /* Send RSL CHAN REL (deactivate) */
5745 PCU.clear;
5746 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5747 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005748 timer T_wait := 2.0;
5749 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005750 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005751 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005752 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005753 [] T_wait.timeout {
5754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5755 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5756 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005757 }
5758 /* Emulate PCU asking BTS to deactivate PDCH */
5759 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5760 alt {
5761 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5762 setverdict(pass);
5763 }
5764 [] RSL.receive { repeat; }
5765 }
5766}
5767
5768/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005769private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005770 var PCUIF_Message first_info;
5771 var integer ts_nr := g_chan_nr.tn;
5772 var integer trx_nr := 0;
5773 var integer bts_nr := 0;
5774 var integer pcu_conn_id := -1;
5775
5776 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5777
5778 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5779 f_sleep(3.0);
5780 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5781 setverdict(pass);
5782}
5783testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5784 var ConnHdlrPars pars;
5785 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005786 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005787
5788 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5789 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5790 vc_conn.done;
5791}
5792
5793/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005794private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005795 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005796 var integer pcu_conn_id := -1;
5797
5798 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5799
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005800 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5801 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5802 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005803 setverdict(pass);
5804}
5805testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5806 var ConnHdlrPars pars;
5807 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005808 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005809
5810 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5811 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5812 vc_conn.done;
5813}
5814
5815/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005816private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005817 var PCUIF_Message first_info;
5818 var integer ts_nr := g_chan_nr.tn;
5819 var integer trx_nr := 0;
5820 var integer bts_nr := 0;
5821 var integer pcu_conn_id := -1;
5822
5823 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5824
5825 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005826 /* Send a second Chan Activ and expect it to be NACKed */
5827 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5828 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005829 setverdict(pass);
5830}
5831testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5832 var ConnHdlrPars pars;
5833 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005834 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005835
5836 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5837 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5838 vc_conn.done;
5839}
5840
5841/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005842private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005843 var PCUIF_Message first_info;
5844 var integer ts_nr := g_chan_nr.tn;
5845 var integer trx_nr := 0;
5846 var integer bts_nr := 0;
5847 var integer pcu_conn_id := -1;
5848 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5849
5850 /* register for the TCH/F channel number */
5851 f_rslem_register(0, chan_nr);
5852
5853 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5854
5855 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5856 "RSL CHAN ACT");
5857 setverdict(pass);
5858}
5859testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5860 var ConnHdlrPars pars;
5861 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005862 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005863
5864 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5865 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5866 vc_conn.done;
5867}
5868
5869/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005870private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005871 var PCUIF_Message first_info;
5872 var integer ts_nr := g_chan_nr.tn;
5873 var integer trx_nr := 0;
5874 var integer bts_nr := 0;
5875 var integer pcu_conn_id := -1;
5876 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5877 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5878
5879 /* register for the TCH/H channel numbers */
5880 f_rslem_register(0, chan_nr[0]);
5881 f_rslem_register(0, chan_nr[1]);
5882
5883 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5884
5885 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5886 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5887 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5888 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5889 setverdict(pass);
5890}
5891testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5892 var ConnHdlrPars pars;
5893 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005894 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005895
5896 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5897 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5898 vc_conn.done;
5899}
5900
Harald Welte9bbbfb52018-04-05 09:33:19 +02005901/***********************************************************************
5902 * IPA Style Dynamic Timeslot Support
5903 ***********************************************************************/
5904
5905private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5906runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005907 /* Expect BTS to immediately acknowledge activation as PDCH */
5908 PCU.clear;
5909 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5910 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005911 timer T_wait := 2.0;
5912 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005913 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005914 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005915 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005916 [] T_wait.timeout {
5917 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5918 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5919 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005920 }
5921 /* try to activate this PDCH from the PCU point of view */
5922 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5923 /* FIXME: is there a response? */
5924
5925 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5926}
5927
5928private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5929runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005930 /* Send RSL CHAN REL (deactivate) */
5931 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5932 PCU.clear;
5933 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005934 timer T_wait := 2.0;
5935 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005936 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005937 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005938 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005939 [] T_wait.timeout {
5940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5941 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5942 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005943 }
5944 /* Emulate PCU asking BTS to deactivate PDCH */
5945 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5946 alt {
5947 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5948 setverdict(pass);
5949 }
5950 [] RSL.receive { repeat; }
5951 }
5952}
5953
5954/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005955private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005956 var PCUIF_Message first_info;
5957 var integer ts_nr := g_chan_nr.tn;
5958 var integer trx_nr := 0;
5959 var integer bts_nr := 0;
5960 var integer pcu_conn_id := -1;
5961
5962 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5963
5964 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5965 f_sleep(3.0);
5966 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5967
5968 setverdict(pass);
5969
5970}
5971testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5972 var ConnHdlrPars pars;
5973 var ConnHdlr vc_conn;
5974 f_init();
5975
5976 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5977 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5978 vc_conn.done;
5979}
5980
5981/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005982private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005983 var PCUIF_Message first_info;
5984 var integer ts_nr := g_chan_nr.tn;
5985 var integer trx_nr := 0;
5986 var integer bts_nr := 0;
5987 var integer pcu_conn_id := -1;
5988
5989 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5990
5991 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5992 "RSL CHAN ACT");
5993 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5994 "RF CHAN REL", true);
5995 setverdict(pass);
5996}
5997testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5998 var ConnHdlrPars pars;
5999 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006000 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006001
6002 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6003 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6004 vc_conn.done;
6005}
6006
6007/* 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 +07006008private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006009 var PCUIF_Message first_info;
6010 var integer ts_nr := g_chan_nr.tn;
6011 var integer trx_nr := 0;
6012 var integer bts_nr := 0;
6013 var integer pcu_conn_id := -1;
6014
6015 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6016
6017 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6018 "RSL CHAN ACT");
6019
6020 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6021 alt {
6022 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6023 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006025 }
6026 [] RSL.receive { repeat; }
6027 }
6028
6029 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6030 "RF CHAN REL", true);
6031 setverdict(pass);
6032}
6033testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6034 var ConnHdlrPars pars;
6035 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006036 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006037
6038 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6039 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6040 vc_conn.done;
6041}
6042
6043/* 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 +07006044private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006045 var PCUIF_Message first_info;
6046 var integer ts_nr := g_chan_nr.tn;
6047 var integer trx_nr := 0;
6048 var integer bts_nr := 0;
6049 var integer pcu_conn_id := -1;
6050
6051 /* register for the TCH/F channel number */
6052 f_rslem_register(0, g_chan_nr);
6053
6054 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6055
6056 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6057
6058 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6059 "RSL CHAN ACT");
6060
6061 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6062
6063 setverdict(pass);
6064}
6065testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6066 var ConnHdlrPars pars;
6067 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006068 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006069
6070 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6071 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6072 vc_conn.done;
6073}
6074
6075
Harald Welte0472ab42018-03-12 15:02:26 +01006076/***********************************************************************
6077 * LAPDm / RLL related
6078 ***********************************************************************/
6079
6080private function f_tx_lapdm(template (value) LapdmFrame l,
6081 template (value) RslLinkId link_id) runs on ConnHdlr {
6082 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006083 var template (value) SacchL1Header l1h;
6084
6085 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006086 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006087 /* Compose dummy L1 header */
6088 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6089 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 +02006090 } else {
6091 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006092 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 +01006093 }
Harald Welte0472ab42018-03-12 15:02:26 +01006094}
6095
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006096private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006097 uint3_t sapi,
6098 RslLinkId link_id,
6099 octetstring l3,
6100 boolean exp
6101}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006102private type record of RllTestCase RllTestCases;
6103private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
6104 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006105 sapi := sapi,
6106 link_id := id,
6107 l3 := l3,
6108 exp := exp
6109}
6110
6111/* execute the same callback function with a set of different parameters (tcs) on a
6112 * variety of logical channels */
6113private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6114 var ConnHdlrPars pars;
6115 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006116 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006117
6118 /* test on each of the channels we have */
6119 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6120 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6121
6122 /* test each of the test cases on the current channel */
6123 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6124 pars.spec.rll := tcs[j];
6125 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6126 vc_conn := f_start_handler(fn, pars);
6127 vc_conn.done;
6128 }
6129 }
6130
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006132}
6133
6134/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6135private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6136 var RllTestCase tc := g_pars.spec.rll;
6137 timer T := 3.0;
6138
6139 f_l1_tune(L1CTL);
6140 RSL.clear;
6141
6142 /* activate the logical channel */
6143 f_est_dchan();
6144 L1CTL.clear;
6145
6146 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6147 T.start;
6148 alt {
6149 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6150 if (tc.exp) {
6151 setverdict(pass);
6152 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006153 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006154 }
6155 }
6156 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6157 if (tc.exp) {
6158 setverdict(pass);
6159 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006160 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006161 }
6162 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006163 /* We also expect to receive the measurements */
6164 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006165 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006167 }
6168 [not tc.exp] T.timeout {
6169 setverdict(pass);
6170 }
6171 }
6172
6173 f_rsl_chan_deact();
6174 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6175 f_rslem_unregister(0, g_chan_nr);
6176}
6177testcase TC_rll_est_ind() runs on test_CT {
6178 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006179 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006180 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006181 /* normal SAPI0 establishment */
6182 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006183 /* SAPI 3 doesn't support contention resolution */
6184 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6185 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6186 /* normal SAPI3 establishment on main DCCH */
6187 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6188 /* normal SAPI3 establishment on SACCH */
6189 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6190 };
6191 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6192}
6193
6194/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6195private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6196 var RllTestCase tc := g_pars.spec.rll;
6197 var L1ctlDlMessage dl;
6198 timer T := 3.0;
6199
6200 f_l1_tune(L1CTL);
6201 RSL.clear;
6202
6203 /* activate the logical channel */
6204 f_est_dchan();
6205 L1CTL.clear;
6206
6207 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6208 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6209 T.start;
6210 alt {
6211 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6212 var LapdmFrame lapdm;
6213 var octetstring l2 := dl.payload.data_ind.payload;
6214 if (dl.dl_info.link_id.c == SACCH) {
6215 /* remove L1 header */
6216 l2 := substr(l2, 2, lengthof(l2)-2);
6217 }
6218 lapdm.ab := dec_LapdmFrameAB(l2);
6219 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6220 setverdict(pass);
6221 } else {
6222 repeat;
6223 }
6224 }
6225 [] L1CTL.receive { repeat; }
6226 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006227 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006228 }
6229 }
6230
6231 f_rsl_chan_deact();
6232 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6233 f_rslem_unregister(0, g_chan_nr);
6234}
6235testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6236 var RllTestCases tcs := {
6237 /* normal SAPI3 establishment on main DCCH */
6238 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6239 };
6240 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6241}
6242testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6243 var RllTestCases tcs := {
6244 /* normal SAPI3 establishment on SACCH */
6245 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6246 }
6247 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6248}
6249
6250/* altstep to receive a LAPDm frame matching the given template */
6251private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6252 var L1ctlDlMessage dl;
6253 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6254 var LapdmFrame lapdm;
6255 var octetstring l2 := dl.payload.data_ind.payload;
6256 if (dl.dl_info.link_id.c == SACCH) {
6257 /* remove L1 header */
6258 l2 := substr(l2, 2, lengthof(l2)-2);
6259 }
6260 if (ischosen(exp.ab)) {
6261 lapdm.ab := dec_LapdmFrameAB(l2);
6262 } else if (ischosen(exp.b4)) {
6263 lapdm.b4 := dec_LapdmFrameB4(l2);
6264 } else if (ischosen(exp.bbis)) {
6265 lapdm.bbis := dec_LapdmFrameBbis(l2);
6266 }
6267 log("Rx LAPDm ", lapdm);
6268 if (match(lapdm, exp)) {
6269 setverdict(pass);
6270 } else {
6271 repeat;
6272 }
6273 }
6274 [] L1CTL.receive { repeat; }
6275}
6276private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6277 timer T := t;
6278 T.start;
6279 alt {
6280 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006282 }
6283 [] as_l1_exp_lapdm(exp);
6284 }
6285}
6286
6287/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6288private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6289 /* send SABM from MS -> BTS */
6290 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6291 /* expect RLL EST IND on Abis */
6292 alt {
6293 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6294 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6295 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006297 }
6298 [] RSL.receive { repeat; }
6299 }
6300 /* expect UA from BTS -> MS */
6301 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6302}
6303
6304/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6305private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6306 var RllTestCase tc := g_pars.spec.rll;
6307
6308 f_l1_tune(L1CTL);
6309 RSL.clear;
6310
6311 /* activate the logical channel */
6312 f_est_dchan();
6313 L1CTL.clear;
6314
6315 /* first establish the link-layer */
6316 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6317
6318 /* then send the DISC */
6319 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6320 /* ... and expect the REL IND on the RSL side */
6321 alt {
6322 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6323 setverdict(pass);
6324 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006325 /* We also expect to receive the measurements */
6326 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006327 }
6328
6329 /* release the channel */
6330 f_rsl_chan_deact();
6331 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6332 f_rslem_unregister(0, g_chan_nr);
6333}
6334testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6335 var RllTestCases tcs := {
6336 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6337 };
6338 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6339}
6340
6341testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6342 var RllTestCases tcs := {
6343 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6344 };
6345 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6346}
6347testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6348 var RllTestCases tcs := {
6349 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6350 };
6351 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6352}
6353testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6354 var RllTestCases tcs := {
6355 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6356 };
6357 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6358}
6359
6360/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6361private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6362 var RllTestCase tc := g_pars.spec.rll;
6363 f_l1_tune(L1CTL);
6364 RSL.clear;
6365
6366 /* activate the logical channel */
6367 f_est_dchan();
6368 L1CTL.clear;
6369
6370 /* first establish the link-layer */
6371 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6372
6373 /* then send the REL REQ via RSL */
6374 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6375 /* ... and expect the DISC on the Um side */
6376 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006377 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006378 /* FIXME: send a UA in resposne to the DISC */
6379 }
6380 }
6381
6382 /* release the channel */
6383 f_rsl_chan_deact();
6384 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6385 f_rslem_unregister(0, g_chan_nr);
6386}
6387testcase TC_rll_rel_req() runs on test_CT {
6388 var RllTestCases tcs := {
6389 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6390 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6391 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6392 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6393 };
6394 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6395}
6396
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006397/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006398testcase TC_rll_data_req() runs on test_CT {
6399}
6400
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006401/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006402testcase TC_rll_data_ind() runs on test_CT {
6403}
6404
6405/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6406private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6407 var RllTestCase tc := g_pars.spec.rll;
6408
6409 f_l1_tune(L1CTL);
6410 RSL.clear;
6411
6412 f_est_dchan();
6413 L1CTL.clear;
6414
6415 /* Send UNITDATA REQ on RSL side */
6416 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6417 /* Expect it to arrive on the other side */
6418 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006419 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006420 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006421 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006422 }
6423
6424 /* release the channel */
6425 f_rsl_chan_deact();
6426 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6427 f_rslem_unregister(0, g_chan_nr);
6428}
6429testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6430 var octetstring l3 := f_rnd_octstring(15);
6431 var RllTestCases tcs := {
6432 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6433 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6434 };
6435 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6436}
6437testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6438 var octetstring l3 := f_rnd_octstring(19);
6439 var RllTestCases tcs := {
6440 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6441 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6442 };
6443 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6444}
6445
6446/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6447private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6448 var RllTestCase tc := g_pars.spec.rll;
6449
6450 f_l1_tune(L1CTL);
6451 RSL.clear;
6452
6453 f_est_dchan();
6454 L1CTL.clear;
6455
6456 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006457 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006458 /* Expdct RLL UNITDATA IND on RSL side */
6459 alt {
6460 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6461 setverdict(pass);
6462 }
6463 [] RSL.receive { repeat; }
6464 }
6465
6466 /* release the channel */
6467 f_rsl_chan_deact();
6468 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6469 f_rslem_unregister(0, g_chan_nr);
6470}
6471testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006472 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006473 var RllTestCases tcs := {
6474 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6475 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6476 };
6477 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6478}
6479testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6480 var octetstring l3 := f_rnd_octstring(18);
6481 var RllTestCases tcs := {
6482 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6483 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6484 };
6485 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6486}
6487
Harald Weltee613f962018-04-18 22:38:16 +02006488/***********************************************************************
6489 * Encryption Related
6490 ***********************************************************************/
6491
6492/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006493private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006494 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6495 if (link_id.c == SACCH) {
6496 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6497 } else {
6498 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6499 }
6500}
6501
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006502/* Expect (or not expect) other kinds of messages */
6503private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6504 [exp_any] RSL.receive { repeat; }
6505 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006506 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006507 }
6508}
6509
Harald Weltee613f962018-04-18 22:38:16 +02006510/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006511private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006512 RslLinkId link_id,
6513 octetstring l3,
6514 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006515 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006516) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006517 timer T := 3.0;
6518 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6519 T.start;
6520 /* Expect RLL UNITDATA IND on RSL side */
6521 alt {
6522 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6523 setverdict(pass);
6524 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006525 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006526 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006527 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006528 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006529 }
Harald Weltee613f962018-04-18 22:38:16 +02006530 }
6531}
6532
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006533/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6534private function f_data_mo(
6535 RslLinkId link_id,
6536 boolean p, uint3_t nr, uint3_t ns,
6537 octetstring l3,
6538 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006539 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006540) runs on ConnHdlr {
6541 timer T := 3.0;
6542 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6543 T.start;
6544 /* Expect RLL DATA IND on RSL side */
6545 alt {
6546 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6547 setverdict(pass);
6548 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006549 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006550 [] as_rsl_any_ind(exp_any);
6551 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006552 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006553 }
6554 }
6555}
6556
Harald Weltee613f962018-04-18 22:38:16 +02006557/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006558private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006559 f_l1_tune(L1CTL);
6560 f_est_dchan(true);
6561
6562 /* now we actually need to transmit some data both ways to check if the encryption works */
6563 var L1ctlDlMessage dl;
6564
Stefan Sperling603d98e2018-07-25 16:47:28 +02006565 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006566 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6567
6568 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6569 f_unitdata_mt(link_id, l3);
6570
6571 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6572 f_unitdata_mo(link_id, l3);
6573
6574 /* release the channel */
6575 f_rsl_chan_deact();
6576 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6577 f_rslem_unregister(0, g_chan_nr);
6578}
6579testcase TC_chan_act_a51() runs on test_CT {
6580 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6581 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6582 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6583}
6584testcase TC_chan_act_a52() runs on test_CT {
6585 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6586 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6587 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6588}
6589testcase TC_chan_act_a53() runs on test_CT {
6590 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6591 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6592 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6593}
6594
Eric Wildf1827a72019-05-28 17:37:35 +02006595/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6596 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 +07006597private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006598 f_l1_tune(L1CTL);
6599 f_est_dchan(true);
6600
6601 /* now we actually need to transmit some data both ways to check if the encryption works */
6602 var L1ctlDlMessage dl;
6603
6604 var octetstring l3 := f_rnd_octstring(20);
6605 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6606
6607 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6608 f_unitdata_mt(link_id, l3);
6609
6610 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6611 f_unitdata_mo(link_id, l3);
6612
6613 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006614 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006615
6616 /* modify key to break proper encryption */
6617 g_pars.encr.key := f_rnd_octstring(8);
6618 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6619 rsl.ies := rsl.ies & { ei };
6620 RSL.send(rsl);
6621
6622 timer T0 := 1.0;
6623 T0.start;
6624 /* Expect RSL MODIFY ACK */
6625 alt {
6626 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6627 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6629 }
6630 [] T0.timeout {
6631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6632 }
6633 }
6634
6635 var octetstring l3msg := f_rnd_octstring(15);
6636 timer T1 := 3.0;
6637 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6638 due to broken encryption */
6639 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6640 T1.start;
6641 alt {
6642 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6643 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6644 }
6645 [] T1.timeout {
6646 setverdict(pass);
6647 }
6648 }
6649
6650 /* release the channel */
6651 f_rsl_chan_deact();
6652 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6653 f_rslem_unregister(0, g_chan_nr);
6654}
6655testcase TC_rsl_modify_encr() runs on test_CT {
6656 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6657 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6658 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6659}
Harald Weltee613f962018-04-18 22:38:16 +02006660
6661/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006662private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006663 /* L3 payload doesn't matter, as it is passed transparently */
6664 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6665 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6666 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6667
6668 f_l1_tune(L1CTL);
6669
6670 /* first establish a dedicated channel in the clear */
6671 f_est_dchan(false);
6672
6673 /* Establish ABM */
6674 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6675
6676 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6677 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6678 /* expect the L3 to arrive still unencrypted on the MS side */
6679 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6680
6681 /* configure L1 to apply ciphering */
6682 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6683 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6684
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006685 /* send first ciphered I-frame in response and expect it on RSL */
6686 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006687
6688 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6689 * and hence enable encryption also on the downlink */
6690
6691 /* expect bi-directional communication work in encrypted mode */
6692 f_unitdata_mo(link_id, f_rnd_octstring(15));
6693 f_unitdata_mt(link_id, f_rnd_octstring(15));
6694
6695 /* release the channel */
6696 f_rsl_chan_deact();
6697 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6698 f_rslem_unregister(0, g_chan_nr);
6699}
6700testcase TC_encr_cmd_a51() runs on test_CT {
6701 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6702 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6703 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6704}
6705testcase TC_encr_cmd_a52() runs on test_CT {
6706 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6707 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6708 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6709}
6710testcase TC_encr_cmd_a53() runs on test_CT {
6711 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6712 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6713 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6714}
6715
6716private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6717 var LapdmFrame lf;
6718 var octetstring reenc;
6719
6720 /* decode the LAPDm frame */
6721 if (ischosen(exp_match.ab)) {
6722 lf.ab := dec_LapdmFrameAB(enc);
6723 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006724 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006725 }
6726
6727 /* check if decoder result matches expectation */
6728 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006730 } else {
6731 log(name, ": matched");
6732 setverdict(pass);
6733 }
6734
6735 /* test if re-encoded frame equals original input */
6736 reenc := enc_LapdmFrame(lf);
6737 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006739 } else {
6740 setverdict(pass);
6741 }
6742}
6743
6744testcase TC_lapdm_selftest() runs on test_CT {
6745 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6746 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6747 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6748 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6749 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6750 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6751 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6752}
6753
Stefan Sperling4880be42018-08-07 18:12:59 +02006754/***********************************************************************
6755 * DTX Related (see GSM 05.08, section 8.3)
6756 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006757private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006758 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02006759 var GsmFrameNumber first_fn;
6760 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006761 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006762 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006763 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6764 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006765 const integer frame_dtx_tchf_mod := 104;
6766 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6767 * which operates in terms of blocks rather than frames. */
6768 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6769 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006770 timer T := 5.0;
6771
6772 f_l1_tune(L1CTL);
6773 RSL.clear;
6774 L1CTL.clear;
6775
6776 /* activate TCHF signalling channel */
6777 f_est_dchan(false);
6778
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006779 /* A template for matching dummy LAPDm func=UA frames */
6780 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
6781 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
6782 l2_data := f_pad_oct('030301'O, 23, '2B'O));
6783
Stefan Sperling4880be42018-08-07 18:12:59 +02006784 T.start;
6785 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006786 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02006787 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02006788
6789 if (is_first_frame) {
6790 is_first_frame := false;
6791 first_fn := dl.dl_info.frame_nr;
6792 }
6793
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006794 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006795 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006796 T.stop;
6797 f_rsl_chan_deact();
6798 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006799
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006800 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
6801 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006802
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006803 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006804 setverdict(fail, "Not enough fill frames received: ",
6805 nfill_frames, " out of ", expected_fill_frames);
6806 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006807 } else {
6808 setverdict(pass);
6809 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006810 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006811 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6812 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6813 * we should only see the subset of frames numbers which correspond to a block boundary.
6814 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6815 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6816 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006817 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006818 repeat;
6819 }
6820 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006821 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
6822 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6823 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006824 f_rsl_chan_deact();
6825 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02006826 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006827 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006828 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006829 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006830 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006831
6832 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006833 /* TCH/F: we expect 24 fill frames for every 104 frames. */
6834 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006835 /* TCH/H: we expect 2 fill frames for every 104 frames. */
6836 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
6837 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006838 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
6839 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006840 case else {
6841 /* This shall not happen, just to be sure */
6842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6843 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006844 }
6845
6846 f_rsl_chan_deact();
6847 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006848
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006849 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006850 setverdict(pass);
6851 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006852 setverdict(fail, "Not enough fill frames received: ",
6853 nfill_frames, " out of ", expected_fill_frames);
6854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006855 }
6856 } else {
6857 repeat;
6858 }
6859 }
6860 }
6861 [] L1CTL.receive { repeat; }
6862 [] T.timeout {
6863 f_rsl_chan_deact();
6864 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006866 }
6867 }
6868}
6869
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006870private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006871 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02006872 var ConnHdlr vc_conn;
6873 var ConnHdlrPars pars;
6874 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006875 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006876 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02006877 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006878 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02006879 if (dtxd) {
6880 if (i >= 4) { /* DTX is only allowed on TCH/F */
6881 break;
6882 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006883 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006884 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02006885 vc_conn.done;
6886 }
6887}
6888
6889/* Verify that L2 fill frames are sent on TCH in signaling mode if
6890 * there is nothing to transmit while DTX is disabled on downlink. */
6891testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6892 f_tch_sign_l2_fill_frame(false);
6893}
6894
6895/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6896 * there is nothing to transmit while DTX is enabled on downlink. */
6897testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6898 f_tch_sign_l2_fill_frame(true);
6899}
Harald Welte0472ab42018-03-12 15:02:26 +01006900
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006901testcase TC_chopped_ipa_ping() runs on test_CT {
6902 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6903}
6904
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006905testcase TC_chopped_ipa_payload() runs on test_CT {
6906 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6907}
6908
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006909
6910/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6911 * Return value: Measurement Report to be sent (encoded octetstring). */
6912type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6913 runs on ConnHdlr return octetstring;
6914
6915private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6916runs on ConnHdlr {
6917 var L1ctlDlMessage l1_dl;
6918 var SacchL1Header l1h;
6919 var octetstring l2;
6920
6921 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6922 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6923 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6924 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6925
6926 /* Pass it to the user specified call-back function */
6927 l2 := cb.apply(l1h, num_blocks);
6928 /* Send a Measurement Report generated by the call-back */
6929 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6930 l1_dl.dl_info.link_id,
6931 l1h, l2));
6932
6933 /* Shall we keep going? */
6934 num_blocks := num_blocks - 1;
6935 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6936 if (num_blocks > 0) { repeat; }
6937 }
6938 [] L1CTL.receive { repeat; }
6939}
6940
6941private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6942runs on ConnHdlr return octetstring {
6943 /* Command the L1 to apply received parameters */
6944 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6945
6946 /* Dummy measurement report (the results are invalid) */
6947 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6948}
6949
6950private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6951runs on ConnHdlr return octetstring {
6952 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6953 setverdict(fail, "Unexpected MS Power level change: ",
6954 g_pars.l1_pars.ms_power_level, " -> ",
6955 l1h.ms_power_lvl);
6956 }
6957
6958 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6959}
6960
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07006961private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
6962runs on ConnHdlr return octetstring {
6963 /* UL RSSI oscillation driven by SACCH block number */
6964 if (num_blocks rem 2 == 0) {
6965 f_trxc_fake_rssi(-100);
6966 } else {
6967 f_trxc_fake_rssi(-50);
6968 }
6969
6970 /* Make sure that MS power level remains constant */
6971 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
6972}
6973
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006974/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6975private function f_TC_ms_pwr_ctrl_constant(charstring id)
6976runs on ConnHdlr {
6977 var integer num_blocks := 8;
6978 timer T := int2float(num_blocks);
6979
6980 f_l1_tune(L1CTL);
6981 RSL.clear;
6982
6983 /* These IEs are needed for autonomous MS power control */
6984 var template (value) RSL_IE_List ies := {
6985 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6986 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6987 }),
6988 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6989 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6990 })
6991 };
6992
6993 /* Ensure that 'rx-current' equals 'rx-target' */
6994 f_trxc_fake_rssi(mp_uplink_power_target);
6995
6996 /* Establish a dedicated channel */
6997 f_est_dchan(more_ies := valueof(ies));
6998
6999 L1CTL.clear;
7000 T.start;
7001 alt {
7002 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7003 [] T.timeout {
7004 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7005 num_blocks, " were not handled");
7006 }
7007 }
7008}
7009testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7010 var ConnHdlr vc_conn;
7011 var ConnHdlrPars pars;
7012
7013 f_init();
7014
7015 /* Explicitly configure the Uplink power target (in dBm) */
7016 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7017
7018 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7019 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7020 log(testcasename(), ": starting on ", pars.chan_nr);
7021
7022 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7023 pars, trxc_comp := true);
7024 vc_conn.done;
7025 }
7026
7027 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7029}
7030
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007031/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7032private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7033runs on ConnHdlr {
7034 var integer num_blocks := 16;
7035 timer T := int2float(num_blocks);
7036
7037 f_l1_tune(L1CTL);
7038 RSL.clear;
7039
7040 /* These IEs are needed for autonomous MS power control */
7041 var template (value) RSL_IE_List ies := {
7042 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7043 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7044 }),
7045 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7046 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7047 })
7048 };
7049
7050 /* Ensure that 'rx-current' equals 'rx-target' */
7051 f_trxc_fake_rssi(mp_uplink_power_target);
7052
7053 /* Establish a dedicated channel */
7054 f_est_dchan(more_ies := valueof(ies));
7055
7056 L1CTL.clear;
7057 T.start;
7058 alt {
7059 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7060 [] T.timeout {
7061 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7062 num_blocks, " were not handled");
7063 }
7064 }
7065}
7066testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7067 var ConnHdlr vc_conn;
7068 var ConnHdlrPars pars;
7069
7070 f_init();
7071
7072 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7073 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7074 /* Explicitly configure the Uplink power range (target and delte) */
7075 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7076 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7077
7078 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7079 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7080 log(testcasename(), ": starting on ", pars.chan_nr);
7081
7082 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7083 pars, trxc_comp := true);
7084 vc_conn.done;
7085 }
7086
7087 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7088 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7089}
7090
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007091private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7092 var template L1ctlDlMessage tr_bad_frame;
7093 var L1ctlDlMessage l1_dl;
7094 timer T := 8.0;
7095
7096 f_l1_tune(L1CTL);
7097 RSL.clear;
7098
7099 f_est_dchan();
7100
7101 /* There may be a few errors right after the channel activation */
7102 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7103 L1CTL.clear;
7104
7105 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7106 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7107 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7108 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7109 tr_bad_frame.payload := ?;
7110
7111 T.start;
7112 alt {
7113 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7114 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7115 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7116 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7117 }
7118 [] as_l1_sacch();
7119 [] L1CTL.receive { repeat; }
7120 [] T.timeout {
7121 /* We're done, break the loop */
7122 setverdict(pass);
7123 }
7124 }
7125
7126 f_rsl_chan_deact();
7127 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7128}
7129testcase TC_speech_no_rtp_tchf() runs on test_CT {
7130 var ConnHdlr vc_conn;
7131 var ConnHdlrPars pars;
7132
7133 f_init();
7134
7135 /* TS1, TCH/F, V1 (FR codec) */
7136 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7137 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7138 vc_conn.done;
7139}
7140testcase TC_speech_no_rtp_tchh() runs on test_CT {
7141 var ConnHdlr vc_conn;
7142 var ConnHdlrPars pars;
7143
7144 f_init();
7145
7146 /* TS5, TCH/H, V1 (HR codec) */
7147 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7148 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7149 vc_conn.done;
7150}
7151
Harald Welte0472ab42018-03-12 15:02:26 +01007152/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7153/* protocol error as per 44.006 */
7154/* link layer failure (repetition of I-frame N200 times without ACK */
7155/* repetition of SABM or DISC N200 times without ACK */
7156/* receptiom of SABM in multi-frame established state */
7157
7158
Harald Welte68e495b2018-02-25 00:05:57 +01007159/* TODO Areas:
7160
7161* channel activation
7162** with BS_Power / MS_Power, bypassing power control loop
7163** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007164** with timing advance from initial activation on
7165* mode modify
7166** encryption
7167** multirate
7168* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007169** unsupported algorithm
7170* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007171* BS Power Control
7172* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007173* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007174* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007175** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007176* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007177** DATA_IND from BTS->PCU
7178** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007179
7180*/
Harald Welte70767382018-02-21 12:16:40 +01007181
7182control {
7183 execute( TC_chan_act_stress() );
7184 execute( TC_chan_act_react() );
7185 execute( TC_chan_deact_not_active() );
7186 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007187 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007188 execute( TC_sacch_filling() );
7189 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007190 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007191 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007192 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007193 execute( TC_sacch_chan_act_ho_async() );
7194 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007195 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007196 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007197 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007198 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007199 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007200 execute( TC_rach_load_idle_thresh0() );
7201 execute( TC_rach_load_idle_below_thresh() );
7202 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007203 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02007204 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007205 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02007206 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07007207 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01007208 execute( TC_meas_res_sign_tchf() );
7209 execute( TC_meas_res_sign_tchh() );
7210 execute( TC_meas_res_sign_sdcch4() );
7211 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007212 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007213 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007214 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007215 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007216 execute( TC_rsl_bs_pwr_static_ass() );
7217 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007218 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007219 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007220 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007221 execute( TC_rsl_ms_pwr_dyn_up() );
7222 execute( TC_rsl_ms_pwr_dyn_down() );
7223 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7224 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007225 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007226 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007227 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007228 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007229 execute( TC_paging_imsi_80percent() );
7230 execute( TC_paging_tmsi_80percent() );
7231 execute( TC_paging_imsi_200percent() );
7232 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007233 execute( TC_rsl_protocol_error() );
7234 execute( TC_rsl_mand_ie_error() );
7235 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007236 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007237 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007238 execute( TC_si_sched_2bis() );
7239 execute( TC_si_sched_2ter() );
7240 execute( TC_si_sched_2ter_2bis() );
7241 execute( TC_si_sched_2quater() );
7242 execute( TC_si_sched_13() );
7243 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007244 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007245 execute( TC_ipa_crcx_twice_not_active() );
7246 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007247 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007248 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007249
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007250 if (mp_pcu_socket != "") {
7251 execute( TC_pcu_act_req() );
7252 execute( TC_pcu_act_req_wrong_ts() );
7253 execute( TC_pcu_act_req_wrong_bts() );
7254 execute( TC_pcu_act_req_wrong_trx() );
7255 execute( TC_pcu_deact_req() );
7256 execute( TC_pcu_deact_req_wrong_ts() );
7257 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007258 if (mp_l1_supports_gprs) {
7259 execute( TC_pcu_data_req_pdtch() );
7260 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007261 execute( TC_pcu_data_req_wrong_bts() );
7262 execute( TC_pcu_data_req_wrong_trx() );
7263 execute( TC_pcu_data_req_wrong_ts() );
7264 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007265 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007266 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007267 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007268 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007269 execute( TC_pcu_data_req_imm_ass_pch() );
7270 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007271 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007272 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007273 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007274 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007275 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007276 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007277 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007278 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007279 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007280 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007281 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007282 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007283 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007284 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007285 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007286 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007287 execute( TC_dyn_osmo_pdch_act_deact() );
7288 execute( TC_dyn_osmo_pdch_double_act() );
7289 execute( TC_dyn_ipa_pdch_act_deact() );
7290 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7291
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007292 if (PCUIF_Types.mp_pcuif_version >= 10) {
7293 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007294 execute( TC_pcu_socket_nsvc_ipv4() );
7295 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007296 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007297 } else {
7298 log("PCU socket path not available, skipping PCU tests");
7299 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007300
Harald Welte3d04ae62018-04-04 20:29:05 +02007301 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007302 execute( TC_dyn_osmo_pdch_tchf_act() );
7303 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007304 execute( TC_dyn_ipa_pdch_tchf_act() );
7305 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007306
7307 execute( TC_rll_est_ind() );
7308 execute( TC_rll_est_req_DCCH_3() );
7309 execute( TC_rll_est_req_ACCH_3() );
7310 execute( TC_rll_rel_ind_DCCH_0() );
7311 execute( TC_rll_rel_ind_DCCH_3() );
7312 execute( TC_rll_rel_ind_ACCH_0() );
7313 execute( TC_rll_rel_ind_ACCH_3() );
7314 execute( TC_rll_rel_req() );
7315 execute( TC_rll_unit_data_req_DCCH() );
7316 execute( TC_rll_unit_data_req_ACCH() );
7317 execute( TC_rll_unit_data_ind_DCCH() );
7318 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007319
7320 execute( TC_chan_act_a51() );
7321 execute( TC_chan_act_a52() );
7322 execute( TC_chan_act_a53() );
7323 execute( TC_encr_cmd_a51() );
7324 execute( TC_encr_cmd_a52() );
7325 execute( TC_encr_cmd_a53() );
7326
Harald Welteee25aae2019-05-19 14:32:37 +02007327 execute( TC_err_rep_wrong_mdisc() );
7328 execute( TC_err_rep_wrong_msg_type() );
7329 execute( TC_err_rep_wrong_sequence() );
7330
Harald Weltee613f962018-04-18 22:38:16 +02007331 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007332
7333 execute( TC_tch_sign_l2_fill_frame() );
7334 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007335
7336 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007337 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007338
7339 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007340 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007341
7342 execute( TC_speech_no_rtp_tchf() );
7343 execute( TC_speech_no_rtp_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007344}
7345
7346
7347}