blob: 4128406f635621b6fc549f1ff5b297e6a6986bca [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,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200754 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100755 },
Harald Weltee613f962018-04-18 22:38:16 +0200756 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200757 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700758 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700759 fhp := {
760 enabled := false,
761 maio_hsn := ts_HsnMaio(0, 0),
762 ma_map := c_MA_null,
763 ma := l1ctl_ma_def
764 }
Harald Welte70767382018-02-21 12:16:40 +0100765}
766
Harald Welte93640c62018-02-25 16:59:33 +0100767/***********************************************************************
768 * Channel Activation / Deactivation
769 ***********************************************************************/
770
Harald Welte70767382018-02-21 12:16:40 +0100771/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700772private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100773 for (var integer i := 0; i < 500; i := i+1) {
774 f_rsl_chan_act(g_pars.chan_mode);
775 f_rsl_chan_deact();
776 }
777 setverdict(pass);
778}
779testcase TC_chan_act_stress() runs on test_CT {
780 var ConnHdlr vc_conn;
781 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200782 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100783 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
784 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200785 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100786}
787
788/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700789private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100790 f_rsl_chan_act(g_pars.chan_mode);
791 /* attempt to activate the same lchan again -> expect reject */
792 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
793 alt {
794 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200795 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100796 }
797 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
798 setverdict(pass);
799 }
800 }
801 f_rsl_chan_deact();
802}
803testcase TC_chan_act_react() runs on test_CT {
804 var ConnHdlr vc_conn;
805 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100806 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100807 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
808 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100810}
811
812/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700813private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100814 timer T := 3.0;
815 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
816 T.start;
817 alt {
818 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
819 setverdict(pass);
820 }
821 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100823 }
824 }
825}
826testcase TC_chan_deact_not_active() runs on test_CT {
827 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100828 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100829 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
830 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200831 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100832}
833
834/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700835private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100836 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
837 alt {
838 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200839 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100840 }
841 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
842 setverdict(pass);
843 }
844 }
845}
846private type record WrongChanNrCase {
847 RslChannelNr chan_nr,
848 charstring description
849}
850private type record of WrongChanNrCase WrongChanNrCases;
851private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
852 chan_nr := chan_nr,
853 description := desc
854}
855
856testcase TC_chan_act_wrong_nr() runs on test_CT {
857 var ConnHdlr vc_conn;
858 var ConnHdlrPars pars;
859
Harald Welte294b0a22018-03-10 23:26:48 +0100860 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100861
862 var WrongChanNrCases wrong := {
863 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
864 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
865 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
866 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
867 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
868 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
869 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
870 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
871 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
872 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
873 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
874 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
875 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
876 };
877
878 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
879 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
880 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
881 vc_conn.done;
882 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200883 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100884}
885
Harald Weltee613f962018-04-18 22:38:16 +0200886/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200887friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200888 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200889 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200890
891 /* test on each of the channels we have */
892 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
893 pars.chan_nr := valueof(g_AllChanTypes[i]);
894
895 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
896 vc_conn := f_start_handler(fn, pars);
897 vc_conn.done;
898 }
899
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200901}
902
Harald Welte93640c62018-02-25 16:59:33 +0100903/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100904 * SACCH handling
905 ***********************************************************************/
906
907private function f_exp_sacch(boolean exp) runs on ConnHdlr {
908 timer T_sacch := 3.0;
909 T_sacch.start;
910 alt {
911 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200912 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100913 }
914 [not exp] T_sacch.timeout {
915 setverdict(pass);
916 }
917 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
918 setverdict(pass);
919 }
920 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200921 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100922 }
923 [] L1CTL.receive { repeat; }
924 [] RSL.receive { repeat; }
925 }
926}
927
928/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
929private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
930 f_l1_tune(L1CTL);
931 RSL.clear;
932
933 /* activate the logical channel */
934 f_est_dchan();
935 L1CTL.clear;
936
937 /* check that SACCH actually are received as expected */
938 f_exp_sacch(true);
939
940 /* deactivate SACCH on the logical channel */
941 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
942 f_sleep(1.0);
943 L1CTL.clear;
944
945 /* check that no SACCH are received anymore */
946 f_exp_sacch(false);
947
948 /* release the channel */
949 f_rsl_chan_deact();
950 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
951}
952testcase TC_deact_sacch() runs on test_CT {
953 var ConnHdlr vc_conn;
954 var ConnHdlrPars pars;
955 f_init();
956 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
957 //for (var integer i := 0; i < 1; i := i+1) {
958 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
959 log(testcasename(), ": Starting for ", g_AllChannels[i]);
960 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
961 vc_conn.done;
962 }
963 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100965}
966
Harald Welte55700662018-03-12 13:15:43 +0100967/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100968private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
969 var L1ctlDlMessage dl;
970 /* check that the specified SI5 value is actually sent */
971 timer T_sacch := 3.0;
972 L1CTL.clear;
973 T_sacch.start;
974 alt {
975 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
976 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
977 if (match(l3, l3_exp)) {
978 setverdict(pass);
979 } else {
980 repeat;
981 }
982 }
983 [] L1CTL.receive { repeat; }
984 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100986 }
987 }
988}
989
Harald Welte55700662018-03-12 13:15:43 +0100990/* verify that given SACCH payload is not present */
991private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
992 var L1ctlDlMessage dl;
993 /* check that the specified SI5 value is actually sent */
994 timer T_sacch := 3.0;
995 L1CTL.clear;
996 T_sacch.start;
997 alt {
998 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
999 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1000 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001001 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001002 } else {
1003 repeat;
1004 }
1005 }
1006 [] L1CTL.receive { repeat; }
1007 [] T_sacch.timeout {
1008 setverdict(pass);
1009 }
1010 }
1011}
1012
Harald Welte629cc6b2018-03-11 17:19:05 +01001013/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001014private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1015 /* Set a known default SACCH filling for SI5 */
1016 var octetstring si5 := f_rnd_octstring(19);
1017 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1018
1019 f_l1_tune(L1CTL);
1020 RSL.clear;
1021
1022 /* activate the logical channel */
1023 f_est_dchan();
1024
1025 /* check that the specified SI5 value is actually sent */
1026 f_sacch_present(si5);
1027
1028 /* release the channel */
1029 RSL.clear;
1030 f_rsl_chan_deact();
1031 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1032}
1033testcase TC_sacch_filling() runs on test_CT {
1034 var ConnHdlr vc_conn;
1035 var ConnHdlrPars pars;
1036 f_init();
1037 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1038 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1039 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1040 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1041 vc_conn.done;
1042 }
1043 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001045}
1046
Harald Welte629cc6b2018-03-11 17:19:05 +01001047/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001048private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1049 /* Set a known default SACCH filling for SI5 */
1050 var octetstring si5 := f_rnd_octstring(19);
1051 var octetstring si5_diff := f_rnd_octstring(19);
1052 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1053
1054 f_l1_tune(L1CTL);
1055 RSL.clear;
1056
1057 log("Activating channel, expecting standard SI5");
1058 /* activate the logical channel */
1059 f_est_dchan();
1060 /* check that the specified SI5 value is actually sent */
1061 f_sacch_present(si5);
1062
1063 /* set channel-specific different SI5 */
1064 log("Setting channel specific SACCH INFO, expecting it");
1065 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1066 /* check that the specified lchan-specific value is now used */
1067 f_sacch_present(si5_diff);
1068
1069 /* deactivate the channel and re-activate it, this should result in default SI5 */
1070 log("De-activating and re-activating channel, expecting standard SI5");
1071 f_rsl_chan_deact();
1072 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1073 /* Verify that the TRX-wide default SACCH filling is present again */
1074 f_sacch_present(si5);
1075
1076 /* release the channel */
1077 RSL.clear;
1078 f_rsl_chan_deact();
1079 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1080}
1081testcase TC_sacch_info_mod() runs on test_CT {
1082 var ConnHdlr vc_conn;
1083 var ConnHdlrPars pars;
1084 f_init();
1085 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1086 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1087 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1088 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1089 vc_conn.done;
1090 }
1091 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001093}
1094
Harald Welte075d84c2018-03-12 13:07:24 +01001095/* Test SACCH scheduling of multiple different SI message types */
1096private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1097 var octetstring si5 := f_rnd_octstring(19);
1098 var octetstring si5bis := f_rnd_octstring(19);
1099 var octetstring si5ter := f_rnd_octstring(19);
1100 var octetstring si6 := f_rnd_octstring(19);
1101
1102 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1103 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1104 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1105 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1106
1107 f_l1_tune(L1CTL);
1108 RSL.clear;
1109
1110 /* activate the logical channel */
1111 f_est_dchan();
1112 L1CTL.clear;
1113
1114 /* check that SACCH actually are received as expected */
1115 f_sacch_present(si5);
1116 f_sacch_present(si5bis);
1117 f_sacch_present(si5ter);
1118 f_sacch_present(si6);
1119
1120 /* release the channel */
1121 f_rsl_chan_deact();
1122 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1123}
1124testcase TC_sacch_multi() runs on test_CT {
1125 var ConnHdlr vc_conn;
1126 var ConnHdlrPars pars;
1127 f_init();
1128 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1129 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1130 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1131 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1132 vc_conn.done;
1133 }
1134 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001136}
1137
Harald Welte55700662018-03-12 13:15:43 +01001138/* Test if SACH information is modified as expected */
1139private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1140 var octetstring si5 := f_rnd_octstring(19);
1141 var octetstring si6 := f_rnd_octstring(19);
1142
1143 /* First, configure both SI5 and SI6 to be transmitted */
1144 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1145 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1146
1147 f_l1_tune(L1CTL);
1148 RSL.clear;
1149
1150 /* activate the logical channel */
1151 f_est_dchan();
1152 L1CTL.clear;
1153
1154 /* check that SACCH actually are received as expected */
1155 f_sacch_present(si5);
1156 f_sacch_present(si6);
1157
1158 /* disable SI6 */
1159 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1160
1161 /* check that SI5 is still transmitted */
1162 f_sacch_present(si5);
1163 /* check if SI6 is now gone */
1164 f_sacch_missing(si6);
1165
1166 /* release the channel */
1167 f_rsl_chan_deact();
1168 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1169}
1170testcase TC_sacch_multi_chg() runs on test_CT {
1171 var ConnHdlr vc_conn;
1172 var ConnHdlrPars pars;
1173 f_init();
1174 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1175 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1176 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1177 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1178 vc_conn.done;
1179 }
1180 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001182}
1183
Harald Weltec8d363c2019-05-19 20:36:48 +02001184/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1185private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1186 var octetstring si5 := f_rnd_octstring(19);
1187 var octetstring si6 := f_rnd_octstring(19);
1188 var octetstring si5_specific := f_rnd_octstring(19);
1189 var octetstring si6_specific := f_rnd_octstring(19);
1190
1191 /* First, configure both SI5 and SI6 to be transmitted */
1192 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1193 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1194
1195 f_l1_tune(L1CTL);
1196 RSL.clear;
1197
1198 /* activate channel with different SACCH filling */
1199 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1200 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1201 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1202 }));
1203 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1204 RSL_IE_Body:{sacch_info := sacch_info})) };
1205 f_est_dchan(more_ies := addl_ies);
1206
1207 /* check that SACCH actually are received as expected */
1208 f_sacch_present(si5_specific);
1209 f_sacch_present(si6_specific);
1210
1211 /* release the channel */
1212 f_rsl_chan_deact();
1213 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1214}
1215testcase TC_sacch_chan_act() runs on test_CT {
1216 var ConnHdlr vc_conn;
1217 var ConnHdlrPars pars;
1218 f_init();
1219
1220 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1221 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1222 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1223 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1224 vc_conn.done;
1225 }
1226 /* TODO: do the above in parallel, rather than sequentially? */
1227 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1228}
1229
Harald Welte8b01c792019-05-19 22:51:25 +02001230/* verify that SACCH DL transmission is started only if MS power IE present
1231 * see section 4.1.3 of 3GPP TS 48.058 */
1232private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1233 var octetstring si5 := f_rnd_octstring(19);
1234
1235 f_l1_tune(L1CTL);
1236 RSL.clear;
1237
1238 /* Step 1: Activate ASYNC HO channel without MS power IE */
1239
1240 /* Activate channel on BTS side */
1241 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1242 /* don't perform immediate assignment here, as we're testing non-IA case */
1243 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001244 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001245
1246 /* Verify that no DL SACCH is being received */
1247 f_sacch_missing(?);
1248
1249 f_rsl_chan_deact();
1250 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1251
1252
1253 /* Step 2: Activate ASYNC HO channel with MS power IE */
1254
1255 /* Activate channel on BTS side */
1256 var RSL_IE_List addl_ies := {
1257 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1258 };
1259 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1260 /* don't perform immediate assignment here, as we're testing non-IA case */
1261 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001262 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001263
1264 /* Verify that DL SACCH is being received */
1265 f_sacch_present(si5);
1266
1267 f_rsl_chan_deact();
1268 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1269}
1270testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1271 var ConnHdlr vc_conn;
1272 var ConnHdlrPars pars;
1273 f_init();
1274
1275 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1276 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1277 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1278 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1279 vc_conn.done;
1280 }
1281 /* TODO: do the above in parallel, rather than sequentially? */
1282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1283}
1284
1285/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1286 * see section 4.1.4 of 3GPP TS 48.058 */
1287private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1288 var octetstring si5 := f_rnd_octstring(19);
1289 var RSL_IE_List addl_ies;
1290
1291 f_l1_tune(L1CTL);
1292 RSL.clear;
1293
1294 /* Step 1: Activate SYNC HO channel without MS power IE */
1295
1296 /* Activate channel on BTS side */
1297 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1298 /* don't perform immediate assignment here, as we're testing non-IA case */
1299 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001300 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001301
1302 /* Verify that no DL SACCH is being received */
1303 f_sacch_missing(?);
1304
1305 f_rsl_chan_deact();
1306 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1307
1308
1309 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1310
1311 /* Activate channel on BTS side */
1312 addl_ies := {
1313 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1314 };
1315 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1316 /* don't perform immediate assignment here, as we're testing non-IA case */
1317 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001318 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001319
1320 /* Verify that no DL SACCH is being received */
1321 f_sacch_missing(?);
1322
1323 f_rsl_chan_deact();
1324 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1325
1326
1327 /* Step 2b: Activate SYNC HO channel with TA IE */
1328
1329 /* Activate channel on BTS side */
1330 addl_ies := {
1331 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1332 };
1333 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1334 /* don't perform immediate assignment here, as we're testing non-IA case */
1335 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001336 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001337
1338 /* Verify that no DL SACCH is being received */
1339 f_sacch_missing(?);
1340
1341 f_rsl_chan_deact();
1342 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1343
1344
1345 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1346
1347 /* Activate channel on BTS side */
1348 addl_ies := {
1349 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1350 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1351 };
1352 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1353 /* don't perform immediate assignment here, as we're testing non-IA case */
1354 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001355 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001356
1357 /* Verify that DL SACCH is being received */
1358 f_sacch_present(si5);
1359
1360 f_rsl_chan_deact();
1361 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1362}
1363testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1364 var ConnHdlr vc_conn;
1365 var ConnHdlrPars pars;
1366 f_init();
1367
1368 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1369 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1370 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1371 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1372 vc_conn.done;
1373 }
1374 /* TODO: do the above in parallel, rather than sequentially? */
1375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1376}
Harald Welte629cc6b2018-03-11 17:19:05 +01001377
1378
1379/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001380 * RACH Handling
1381 ***********************************************************************/
1382
Harald Welte8c24c2b2018-02-26 08:31:31 +01001383/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001384private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001385 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001386 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001387 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001388
Harald Welte8c24c2b2018-02-26 08:31:31 +01001389 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001390 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001391 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001392 var OCT1 ra := f_rnd_ra_emerg();
1393 if (emerg == true) {
1394 ra := f_rnd_ra_emerg();
1395 } else {
1396 ra := f_rnd_ra_cs();
1397 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001398 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1399 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001400 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001401 }
1402 fn_last := fn;
1403
1404 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001405 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001406 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001407 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001408 T.stop;
1409 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001410 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001411 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001412 }
1413 [] RSL_CCHAN.receive { repeat; }
1414 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001415 test_failed := true;
1416 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001417 }
1418 }
1419 }
Maxba06feb2019-03-05 10:52:46 +01001420 if (test_failed) {
1421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001422 }
Maxba06feb2019-03-05 10:52:46 +01001423 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001425}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001426
Philipp Maier16ade782020-07-08 21:36:00 +02001427/* Normal variant */
1428testcase TC_rach_content() runs on test_CT {
1429 f_TC_rach_content(emerg := false);
1430}
1431
1432/* Emergency call variant */
1433testcase TC_rach_content_emerg() runs on test_CT {
1434 f_TC_rach_content(emerg := true);
1435}
1436
Harald Welte8c24c2b2018-02-26 08:31:31 +01001437/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1438testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001439 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001440 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001441 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001442 f_l1_tune(L1CTL);
1443
1444 var GsmFrameNumber fn_last := 0;
1445 for (var integer i := 0; i < 1000; i := i+1) {
1446 var OCT1 ra := f_rnd_ra_cs();
1447 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1448 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001450 }
1451 fn_last := fn;
1452 }
1453 var integer rsl_chrqd := 0;
1454 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001455 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001456 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001457 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001458 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001459 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001460 repeat;
1461 }
1462 [] RSL_CCHAN.receive { repeat; }
1463 [] T.timeout { }
1464 }
1465 if (rsl_chrqd == 1000) {
1466 setverdict(pass);
1467 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001469 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001470 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001471}
1472
Harald Welte3453ab42019-05-24 21:19:58 +02001473private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1474 var charstring bts_str := "bts " & int2str(bts_nr);
1475 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1476}
1477
1478/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1479private template integer tr_rach_slots_per_interval := (90 .. 130);
1480
1481/* Expect 0 RACH load on an idle BTS that has just started up */
1482testcase TC_rach_load_idle_thresh0() runs on test_CT {
1483 var ASP_RSL_Unitdata rx_ud;
1484
1485 f_init_vty_bsc();
1486 /* send load indications even at 0% load */
1487 f_vty_load_ind_thresh(0);
1488 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1489 f_sleep(2.0);
1490
1491 f_init();
1492
Harald Weltee37f9a52020-10-11 20:45:23 +02001493 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1494 alt {
1495 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1496 [] RSL_CCHAN.receive { repeat }
1497 }
1498
Harald Welte3453ab42019-05-24 21:19:58 +02001499 timer T := 5.0;
1500 T.start;
1501 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001502 [] 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 +02001503 setverdict(pass);
1504 repeat;
1505 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001506 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001507 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1508 repeat;
1509 }
1510 [] RSL_CCHAN.receive {
1511 repeat;
1512 }
1513 [] T.timeout { }
1514 }
1515
1516 f_vty_load_ind_thresh(10);
1517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1518}
1519
1520/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1521testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1522 var ASP_RSL_Unitdata rx_ud;
1523
1524 f_init_vty_bsc();
1525 f_init();
1526
1527 timer T := 5.0;
1528 T.start;
1529 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001530 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001531 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1532 repeat;
1533 }
1534 [] RSL_CCHAN.receive {
1535 repeat;
1536 }
1537 [] T.timeout {
1538 setverdict(pass);
1539 }
1540 }
1541
1542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1543}
1544
1545/* Expect 0 RACH load on an idle BTS that has just started up */
1546testcase TC_rach_load_count() runs on test_CT {
1547 var ASP_RSL_Unitdata rx_ud;
1548 var integer load_access_count := 0;
1549
1550 f_init_vty_bsc();
1551 /* send load indications even at 0% load */
1552 f_vty_load_ind_thresh(0);
1553 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1554 f_sleep(2.0);
1555 f_init();
1556
1557 f_init_l1ctl();
1558 f_sleep(1.0);
1559 f_l1_tune(L1CTL);
1560
Harald Welte52ae1682020-10-11 20:45:55 +02001561 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1562 alt {
1563 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1564 [] RSL_CCHAN.receive { repeat }
1565 }
1566
Harald Welte3453ab42019-05-24 21:19:58 +02001567 var GsmFrameNumber fn_last := 0;
1568 for (var integer i := 0; i < 1000; i := i+1) {
1569 var OCT1 ra := f_rnd_ra_cs();
1570 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1571 if (fn == fn_last) {
1572 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1573 }
1574 fn_last := fn;
1575 }
1576
1577 timer T := 5.0;
1578 T.start;
1579 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001580 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001581 -> value rx_ud {
1582 var RSL_IE_Body ie;
1583 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1584 load_access_count := load_access_count + ie.rach_load.access_count;
1585 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1586 setverdict(fail, "Access count cannot be < Busy count");
1587 }
1588 repeat;
1589 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001590 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001591 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1592 repeat;
1593 }
1594 [] RSL_CCHAN.receive {
1595 repeat;
1596 }
1597 [] T.timeout { }
1598 }
1599 if (load_access_count == 1000) {
1600 setverdict(pass);
1601 } else {
1602 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1603 }
1604
1605 f_vty_load_ind_thresh(10);
1606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1607}
1608
Harald Welte54a2a2d2018-02-26 09:14:05 +01001609private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001610 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001611 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001612 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001613 f_sleep(0.5);
1614
1615 /* Transmit RACH request + wait for confirmation */
1616 var OCT1 ra := f_rnd_ra_cs();
1617 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1618
1619 /* Check for expected result */
1620 timer T := 1.5;
1621 T.start;
1622 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001623 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001624 setverdict(pass);
1625 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001626 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001628 }
1629 [] RSL_CCHAN.receive { repeat; }
1630 [not expect_pass] T.timeout {
1631 setverdict(pass);
1632 }
1633 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001635 }
1636 }
1637}
1638
1639/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1640testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001641 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001642 f_init_l1ctl();
1643 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001644 f_sleep(1.0);
1645
1646 /* default max-ta is 63 (full range of GSM timing advance */
1647
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001648 /* We allow early arrival up to 2 symbols */
1649 f_rach_toffs(-1*256, true);
1650 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001651 f_rach_toffs(-10*256, false);
1652
1653 /* 0 / 32 / 63 bits is legal / permitted */
1654 f_rach_toffs(0, true);
1655 f_rach_toffs(32*256, true);
1656 f_rach_toffs(63*256, true);
1657
1658 /* more than 63 bits is not legal / permitted */
1659 f_rach_toffs(64*256, false);
1660 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001662}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001663
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001664private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001665 var GsmFrameNumber fn;
1666 var RSL_Message rm;
1667
1668 f_l1_tune(L1CTL);
1669 RSL.clear;
1670
1671 /* Generate a random Handover Reference */
1672 var integer ho_ref := oct2int(f_rnd_octstring(1));
1673
1674 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1675 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1676 RSL_IE_Body:{ handover_ref := ho_ref }));
1677
1678 /* Activate a channel on the BTS side (no encryption) */
1679 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1680 act_type := t_RSL_IE_ActType_HO_SYNC);
1681
1682 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1683 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001684 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001685
1686 /* Send handover Access Burst */
1687 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1688
1689 /* TODO: test mismatching Handover Reference, and missing IE */
1690
1691 /* Wait for handover detection */
1692 timer T := 3.0;
1693 T.start;
1694 alt {
1695 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1696 log("Handover RACH has been detected: ", rm);
1697 setverdict(pass);
1698 }
1699 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1701 log2str("RSL_CHAN_RQD was not expected: ", rm));
1702 }
1703 [] RSL.receive { repeat; }
1704 [] T.timeout {
1705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1706 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1707 }
1708 }
1709
1710 /* Release the channel */
1711 f_rsl_chan_deact();
1712 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1713}
1714
1715/* Test handover RACH detection */
1716testcase TC_ho_rach() runs on test_CT {
1717 var ConnHdlrPars pars;
1718 var ConnHdlr vc_conn;
1719
1720 f_init();
1721
1722 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1723 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1724 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1725 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1726 vc_conn.done;
1727 }
1728
1729 /* TODO: do the above in parallel, rather than sequentially? */
1730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1731}
1732
Harald Welte93640c62018-02-25 16:59:33 +01001733/***********************************************************************
1734 * Measurement Processing / Reporting
1735 ***********************************************************************/
1736
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001737private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001738 spare := '0'B,
1739 lpd := 0,
1740 sapi := sapi,
1741 c_r := c_r,
1742 ea := true
1743}
1744
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001745private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001746 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001747 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001748 len := 0, /* overwritten */
1749 m := false,
1750 el := 1,
1751 payload := pl
1752}
1753
1754/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001755private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001756 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001757 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001758 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001759 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 +01001760 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001761 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001762
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001763 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1764 g_pars.l1_pars.ms_power_level, false,
1765 g_pars.l1_pars.ms_actual_ta);
1766
1767 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1768 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1769
1770 log("Sending Measurement Report: ", l1h, l2);
1771 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001772 repeat;
1773 }
1774}
1775
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001776private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001777 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001778 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001779 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1780 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001781 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1782 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001783 repeat;
1784 }
1785}
1786
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001787private altstep as_l1_tch_loop() runs on ConnHdlr {
1788 var L1ctlDlMessage l1_dl;
1789 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1790 log("TCH received: ", l1_dl.payload.traffic_ind.data);
1791 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1792 l1_dl.payload.traffic_ind.data));
1793 repeat;
1794 }
1795}
1796
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001797private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001798 uint6_t rxlev,
1799 uint3_t rxqual
1800}
1801
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001802private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001803 MeasElem full,
1804 MeasElem sub
1805}
1806
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001807private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001808 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001809 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001810 MeasElemFS meas_ul,
1811 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001812 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001813 uint5_t ms_power_level,
1814 uint8_t ms_actual_ta
1815}
1816
1817/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1818private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1819 return 63 + (toffs256s/256);
1820}
1821
Harald Welted5684392018-03-10 18:22:04 +01001822private function f_max(integer a, integer b) return integer {
1823 if (a > b) {
1824 return a;
1825 } else {
1826 return b;
1827 }
1828}
1829
1830private function f_min(integer a, integer b) return integer {
1831 if (a < b) {
1832 return a;
1833 } else {
1834 return b;
1835 }
1836}
1837
1838/* compute negative tolerance val-tolerance, ensure >= min */
1839private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1840 val := val - tolerance;
1841 return f_max(val, min);
1842}
1843
1844/* compute positive tolerance val+tolerance, ensure <= max */
1845private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1846 val := val + tolerance;
1847 return f_min(val, max);
1848}
1849
1850/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1851private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1852return template integer {
1853 var template integer ret;
1854 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1855 return ret;
1856}
1857
1858
Harald Welte70767382018-02-21 12:16:40 +01001859/* build a template for matching measurement results against */
1860private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1861 var ConnL1Pars l1p := g_pars.l1_pars;
1862 var template RSL_IE_UplinkMeas ul_meas := {
1863 len := 3,
1864 rfu := '0'B,
1865 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001866 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001867 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001868 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001869 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001870 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1871 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001872 supp_meas_info := omit
1873 };
Harald Welte685d5982018-02-27 20:42:05 +01001874 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001875 ul_meas.len := (3+8);
1876 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001877 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001878 toa256_min := ?,
1879 toa256_max := ?,
1880 toa256_std_dev := ?
1881 }
Harald Welte685d5982018-02-27 20:42:05 +01001882 }
Harald Welte70767382018-02-21 12:16:40 +01001883 var template RSL_IE_BS_Power bs_power := {
1884 reserved := 0,
1885 epc := false,
1886 fpc := false,
1887 power_level := l1p.bs_power_level
1888 };
1889 var template RSL_IE_L1Info l1_info := {
1890 ms_power_lvl := l1p.ms_power_level,
1891 fpc := false,
1892 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001893 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001894 };
1895 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001896 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001897 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1898 ?, t_toffs);
1899}
1900
Philipp Maierdd841d32019-12-17 14:44:54 +01001901/* build a template for matching measurement results that do not contain any
1902 * MS related measurement (l1_info, l3_info and ms timing offset). */
1903private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1904 var ConnL1Pars l1p := g_pars.l1_pars;
1905 var template RSL_IE_UplinkMeas ul_meas := {
1906 len := 3,
1907 rfu := '0'B,
1908 dtx_d := l1p.dtx_enabled,
1909 rxlev_f_u := ?,
1910 reserved1 := '00'B,
1911 rxlev_s_u := ?,
1912 reserved2 := '00'B,
1913 rxq_f_u := ?,
1914 rxq_s_u := ?,
1915 supp_meas_info := omit
1916 };
1917 if (l1p.toa256_enabled) {
1918 ul_meas.len := (3+8);
1919 ul_meas.supp_meas_info := {
1920 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1921 toa256_min := ?,
1922 toa256_max := ?,
1923 toa256_std_dev := ?
1924 }
1925 }
1926 var template RSL_IE_BS_Power bs_power := {
1927 reserved := 0,
1928 epc := false,
1929 fpc := false,
1930 power_level := l1p.bs_power_level
1931 };
1932
1933 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1934}
1935
Harald Welte70767382018-02-21 12:16:40 +01001936/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001937private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001938 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001939 var boolean chan_est := false;
1940
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001941 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001942
1943 /* Receive osmocom specific measurement reports. This is the normal
1944 * case. Here we verify that the measurement reports we sent are
1945 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001946 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1947 /* increment counter of next to-be-expected meas rep */
1948 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1949 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001950 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001951
1952 /* The following two cases may only happen in the beginning
1953 * of the channel establishment phase. Once we have received
1954 * the "our" measurement report the first time, the channel
1955 * is established and empty or hardcoded TRXCON reports must
1956 * not occur anymore. */
1957 chan_est := true;
1958
1959 repeat;
1960 }
1961
1962 /* When the BTS has established the channel, the MS might need slightly
1963 * more time to establish the channel and actually start sending. The
1964 * result is then a measurement report that just lacks the measurement
1965 * information of the MS. This is normal and we tolerate this behavior. */
1966 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1967 /* increment counter of next to-be-expected meas rep */
1968 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1969 /* Re-start the timer expecting the next MEAS RES */
1970 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001971 repeat;
1972 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001973
1974 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1975 * measurements if the TTCN3 side does not supply measurement input in
1976 * time. In those cases TRXCON will either use a cached measurement
1977 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1978 * report the templates above will not match. We tolerate this
1979 * behavior, but only once. */
1980 [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 +01001981 /* increment counter of next to-be-expected meas rep */
1982 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1983 if (g_first_meas_res) {
1984 g_first_meas_res := false;
1985 repeat;
1986 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001988 }
Harald Welte70767382018-02-21 12:16:40 +01001989 }
1990 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001992 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001993 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001994 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001995 }
1996}
1997
Harald Weltee613f962018-04-18 22:38:16 +02001998private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1999 select (rsl_alg_id) {
2000 case (RSL_ALG_ID_A5_0) { return 0; }
2001 case (RSL_ALG_ID_A5_1) { return 1; }
2002 case (RSL_ALG_ID_A5_2) { return 2; }
2003 case (RSL_ALG_ID_A5_3) { return 3; }
2004 case (RSL_ALG_ID_A5_4) { return 4; }
2005 case (RSL_ALG_ID_A5_5) { return 5; }
2006 case (RSL_ALG_ID_A5_6) { return 6; }
2007 case (RSL_ALG_ID_A5_7) { return 7; }
2008 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2010 /* Make compiler happy by calling mtc.stop here. It is already
2011 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002012 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002013 }
2014 }
2015}
2016
2017private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2018 select (rsl_alg_id) {
2019 case (RSL_ALG_ID_A5_1) { return '000'B; }
2020 case (RSL_ALG_ID_A5_2) { return '001'B; }
2021 case (RSL_ALG_ID_A5_3) { return '010'B; }
2022 case (RSL_ALG_ID_A5_4) { return '011'B; }
2023 case (RSL_ALG_ID_A5_5) { return '100'B; }
2024 case (RSL_ALG_ID_A5_6) { return '101'B; }
2025 case (RSL_ALG_ID_A5_7) { return '110'B; }
2026 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2028 /* Make compiler happy by calling mtc.stop here. It is already
2029 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002030 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002031 }
2032 }
2033}
2034
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002035/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2036private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2037 var GsmFrameNumber fn;
2038 timer T := 8.0;
2039
2040 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2041 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2042
2043 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2044 /* Send the actual RACH */
2045 fn := f_L1CTL_RACH(L1CTL, ra);
2046
2047 T.start;
2048 alt {
2049 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2050 [] T.timeout {
2051 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2052 }
2053 }
2054 T.stop
2055 return fn;
2056}
Harald Weltee613f962018-04-18 22:38:16 +02002057
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002058/* Tune to a dedicated channel: L1CTL only */
2059private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002060 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002061 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2062 7 /* TODO: mp_tsc */,
2063 mp_trx0_arfcn));
2064 } else {
2065 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2066 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002067 pars.fhp.maio_hsn.hsn,
2068 pars.fhp.maio_hsn.maio,
2069 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002070 }
2071}
2072
Harald Welte70767382018-02-21 12:16:40 +01002073/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002074private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002075 var GsmFrameNumber fn;
2076 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002077 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002078 var integer ra := 23;
2079
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002080 /* Send RACH request and wait for ChanReq */
2081 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002082
2083 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002084 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002085
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002086 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002087 if (g_pars.fhp.enabled) {
2088 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002089 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002090 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002091 }
2092
Harald Welte70767382018-02-21 12:16:40 +01002093 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002094 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 +01002095 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2096
2097 /* receive IMM.ASS on MS side */
2098 var ImmediateAssignment ia_um;
2099 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002100
2101 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2102 if (ch_desc.h != ia_um.chan_desc.h) {
2103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2104 }
2105
Harald Welte70767382018-02-21 12:16:40 +01002106 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002107 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002108 /* enable encryption, if requested */
2109 if (encr_enable) {
2110 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2111 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2112 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002113
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002114 /* Send TCH Mode Request to the L1 if needed */
2115 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2116 var L1ctlTchMode tch_mode;
2117
2118 select (g_pars.chan_mode.coding_alg_rate) {
2119 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2120 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2121 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2122 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2123 case else {
2124 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2125 " is not supported by the L1, falling back to signalling");
2126 tch_mode := L1CTL_CHAN_MODE_SIGN;
2127 }
2128 }
2129
2130 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2131 }
2132
Harald Weltefa45e9e2018-03-10 18:59:03 +01002133 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002134}
2135
2136/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002137private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002138 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002139 RSL.clear;
2140
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002141 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002142 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002143 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002144 }
Harald Welte70767382018-02-21 12:16:40 +01002145
2146 f_est_dchan();
2147
2148 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2149 * RSL measurement reports on Abis side */
2150 timer T := 8.0;
2151 T.start;
2152 alt {
2153 [] as_l1_sacch();
2154 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002155 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002156 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002157 [] L1CTL.receive { repeat; }
2158 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002159 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002160 * of any earlier errors, so if we reach this timeout, we're good */
2161 setverdict(pass);
2162 }
2163 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002165 }
2166 }
2167 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002168 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002169}
Harald Welte0472ab42018-03-12 15:02:26 +01002170
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002171/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2172private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002173 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002174 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2175 timer Tup := 10.0;
2176 Tup.start;
2177 alt {
2178 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2179 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2180 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002181
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002182 if (rx_lvl != max_rx_lvl) {
2183 repeat;
2184 }
2185 Tup.stop;
2186 }
2187 [] L1CTL.receive { repeat; }
2188 [] Tup.timeout {
2189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2190 log2str("Didn't reach full power ", max_rx_lvl));
2191 }
2192 }
2193 return max_rx_lvl;
2194}
2195
2196/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2197private function f_verify_ramp_up() runs on ConnHdlr {
2198 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002199 var integer initial_rx_lvl := -1;
2200 var integer last_rx_lvl := -1;
2201 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2202
2203 timer T := 2.0;
2204 alt {
2205 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2206 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2207 log("Received rx_level=", rx_lvl);
2208 if (initial_rx_lvl == -1) {
2209 initial_rx_lvl := rx_lvl;
2210 last_rx_lvl := rx_lvl;
2211
2212 /* Expect a somehow low value during first received messages */
2213 if (initial_rx_lvl >= max_rx_lvl / 2) {
2214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2215 log2str("Detected high initial tx power during ramp up: ",
2216 initial_rx_lvl , ", full power is", max_rx_lvl));
2217 }
2218 }
2219
2220 /* received Rx level bigger than maximum allowed power by CN */
2221 if (rx_lvl > max_rx_lvl) {
2222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2223 log2str("Detected Tx power higher than full power: ",
2224 rx_lvl , " > ", max_rx_lvl));
2225 }
2226
2227 /* Make sure it never decreases, since we are rumping up */
2228 if (last_rx_lvl > rx_lvl) {
2229 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2230 log2str("Detected Tx power decrease during ramp up: ",
2231 last_rx_lvl , " -> ", rx_lvl));
2232 }
2233
2234 if (rx_lvl == max_rx_lvl and not T.running) {
2235 /* We reached the maximum power, start timer and receive
2236 /* a few more to make sure we don't surpass it */
2237 log("Reached full power, wating a bit more until success");
2238 T.start;
2239 }
2240
2241 last_rx_lvl := rx_lvl;
2242 repeat;
2243 }
2244 [] L1CTL.receive { repeat; }
2245 [] T.timeout { }
2246 }
2247
2248 /* We didn't increase tx power during ramp up */
2249 if (initial_rx_lvl < last_rx_lvl) {
2250 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2251 } else {
2252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2253 log2str("No Tx power increase during whole ramp up: ",
2254 initial_rx_lvl , " -> ", last_rx_lvl));
2255 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002256}
2257
2258/* verify BTS ramps power down to rx_level 0 */
2259private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2260 var L1ctlDlMessage l1_dl;
2261 var integer last_rx_lvl := max_rx_lvl;
2262
2263 timer Tdown := 5.0;
2264 Tdown.start;
2265 alt {
2266 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2267 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2268 log("Received rx_level=", rx_lvl);
2269
2270 /* received Rx level bigger than maximum allowed power by CN */
2271 if (rx_lvl > max_rx_lvl) {
2272 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2273 log2str("Detected Tx power higher than full power: ",
2274 rx_lvl , " > ", max_rx_lvl));
2275 }
2276
2277 /* Make sure it never increases, since we are rumping down */
2278 if (last_rx_lvl < rx_lvl) {
2279 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2280 log2str("Detected Tx power increase during ramp up: ",
2281 last_rx_lvl , " -> ", rx_lvl));
2282 }
2283
2284 last_rx_lvl := rx_lvl;
2285 if (last_rx_lvl != 0) {
2286 repeat;
2287 }
2288 /* we reached power level 0, we are done */
2289 Tdown.stop;
2290 }
2291 [] L1CTL.receive { repeat; }
2292 [] Tdown.timeout { }
2293 }
2294
2295 /* We didn't increase tx power during ramp down */
2296 if (max_rx_lvl > last_rx_lvl) {
2297 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2298 } else {
2299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2300 log2str("No Tx power decrease during whole ramp down: ",
2301 max_rx_lvl , " -> ", last_rx_lvl));
2302 }
2303}
2304
2305/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002306private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002307 f_l1_tune(L1CTL);
2308 RSL.clear;
2309
2310 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002311
2312 setverdict(pass);
2313}
2314testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2315 var ConnHdlr vc_conn;
2316 var ConnHdlrPars pars;
2317 f_init();
2318 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2319 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2320 pcu_comp := false, trxc_comp := true);
2321 vc_conn.done;
2322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2323}
2324
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002325/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002326private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002327 f_connhdlr_init_vty_bsc();
2328
2329 f_l1_tune(L1CTL);
2330 RSL.clear;
2331
2332 /* Wait until BTS is started and at full power */
2333 var integer max_rx_lvl := f_wait_ramp_up();
2334 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2335
2336 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2337 f_verify_ramp_down(max_rx_lvl);
2338
2339 setverdict(pass);
2340}
2341testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2342 var ConnHdlr vc_conn;
2343 var ConnHdlrPars pars;
2344 f_init();
2345 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2346 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2347 pcu_comp := false, trxc_comp := true);
2348 vc_conn.done;
2349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2350}
2351
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002352/* Verify Tx power:
2353 * + ramping down during ADM state UNLOCKED->LOCKED
2354 * + ramping up during ADM state LOCKED->UNLOCKED
2355 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002356private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002357 var L1ctlDlMessage l1_dl;
2358 var integer last_rx_lvl;
2359
2360 f_connhdlr_init_vty_bsc();
2361
2362 f_l1_tune(L1CTL);
2363 RSL.clear;
2364
2365 /* Wait until BTS is started and at full power */
2366 var integer max_rx_lvl := f_wait_ramp_up();
2367 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2368
2369 log("ADM STATE UNLOCKED->LOCKED");
2370 f_vty_enter_cfg_trx(BSCVTY);
2371 f_vty_transceive(BSCVTY, "rf_locked 1");
2372 last_rx_lvl := max_rx_lvl;
2373 f_verify_ramp_down(max_rx_lvl);
2374
2375 /* Let some time after we received 0dBm, then check we don't receive BCCH
2376 * anymore because scheduler has stopped after ramping down */
2377 f_sleep(2.0);
2378 L1CTL.clear;
2379 timer Tlocked := 2.0;
2380 Tlocked.start;
2381 alt {
2382 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2383 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2384 log2str("Received data_ind during rf_locked: ", l1_dl));
2385 }
2386 [] L1CTL.receive { repeat; }
2387 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2388 }
2389
2390 log("ADM STATE LOCKED->UNLOCKED");
2391 f_vty_transceive(BSCVTY, "rf_locked 0");
2392 f_verify_ramp_up();
2393 setverdict(pass);
2394}
2395testcase TC_tx_power_ramp_adm_state_change() 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_ramp_adm_state_change), pars,
2401 pcu_comp := false, trxc_comp := true);
2402 vc_conn.done;
2403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2404}
2405
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002406private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002407 timer T := 8.0;
2408 T.start;
2409 var RSL_Message rsl;
2410 alt {
2411 [] as_l1_sacch();
2412 [] L1CTL.receive { repeat; }
2413 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2414 if (rsl.ies[3].body.bs_power.power_level == level) {
2415 setverdict(pass)
2416 } else {
2417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2418 }
2419 }
2420 [] T.timeout {
2421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2422 }
2423 }
2424}
2425
2426/* see if the rsl meas res contains our expeced bs power level
2427bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002428private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002429 f_l1_tune(L1CTL);
2430 RSL.clear;
2431
2432 if (mp_bts_trxc_port != -1) {
2433 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2434 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2435 }
2436
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002437 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002438 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2439 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2440
2441 f_est_dchan(more_ies :={valueof(pwr)});
2442
2443 f_check_meas_bs_power_level(pwr_var);
2444
2445 f_rsl_chan_deact();
2446 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2447}
2448
2449/* see if the rsl meas res contains our expeced bs power level
2450bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002451private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002452 f_l1_tune(L1CTL);
2453 RSL.clear;
2454
2455 if (mp_bts_trxc_port != -1) {
2456 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2457 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2458 }
2459
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002460 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002461 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2462
2463 f_est_dchan();
2464
2465 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2466
2467 f_check_meas_bs_power_level(pwr_var);
2468
2469 f_rsl_chan_deact();
2470 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2471}
2472
2473testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2474 var ConnHdlr vc_conn;
2475 var ConnHdlrPars pars;
2476 f_init();
2477 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2478 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2479 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2480 pcu_comp := false, trxc_comp := true);
2481 vc_conn.done;
2482 }
2483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2484}
2485
2486testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2487 var ConnHdlr vc_conn;
2488 var ConnHdlrPars pars;
2489 f_init();
2490 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2491 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2492 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2493 pcu_comp := false, trxc_comp := true);
2494 vc_conn.done;
2495 }
2496 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2497}
2498
Eric Wild61edb7e2019-06-03 12:38:31 +02002499/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2500second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2501These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002502private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002503 var uint5_t pwr_var := 7;
2504 var L1ctlDlMessage l1_dl;
2505
2506 f_trxc_fake_rssi(rxlev2dbm(10));
2507 f_l1_tune(L1CTL);
2508 RSL.clear;
2509
2510 var RSL_IE_List addl_ies;
2511 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2512
2513 addl_ies := {
2514 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2515 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2516 };
2517
2518 /* establish with power parameters */
2519 f_est_dchan(more_ies := addl_ies);
2520
2521 /* set a high value to ensure L1 power control level increases */
2522 f_trxc_fake_rssi(rxlev2dbm(20));
2523
2524 timer T2 := 6.0;
2525 T2.start;
2526 alt {
2527 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002528 /* Update sent MS power to follow what BTS requests */
2529 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2530 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002531 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002532 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002533 T2.stop;
2534 }
2535 [] L1CTL.receive { repeat; }
2536 [] T2.timeout {
2537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2538 "Power Level in L1 header has not increased sufficiently");
2539 }
2540 }
2541
2542 /* set a low value to ensure L1 power control level decreases */
2543 f_trxc_fake_rssi(rxlev2dbm(0));
2544
2545 timer T4 := 6.0;
2546 T4.start;
2547 alt {
2548 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002549 /* Update sent MS power to follow what BTS requests */
2550 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2551 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002552 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002553 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002554 T4.stop;
2555 setverdict(pass, "Power level in L1 decreased/increased as expected");
2556 }
2557 [] L1CTL.receive { repeat; }
2558 [] T4.timeout {
2559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2560 "Power Level in L1 header has not decreased sufficiently");
2561 }
2562 }
2563
2564 f_rsl_chan_deact();
2565 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2566
2567}
2568
2569/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002570private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002571 var uint5_t pwr_var := 7;
2572 var L1ctlDlMessage l1_dl;
2573
2574 /* set a low value to ensure power increases */
2575 f_trxc_fake_rssi(rxlev2dbm(10));
2576 f_l1_tune(L1CTL);
2577 RSL.clear;
2578
2579 var RSL_IE_List addl_ies;
2580 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2581
2582 addl_ies := {
2583 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2584 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2585 };
2586
2587 /* establish with power parameters */
2588 f_est_dchan(more_ies := addl_ies);
2589
2590 timer T1 := 10.0;
2591 T1.start;
2592 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002593 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2594 /* Update sent MS power to follow what BTS requests */
2595 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2596 repeat;
2597 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002598 [] L1CTL.receive { repeat; }
2599 [] T1.timeout {
2600 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2601 setverdict(fail, "Power level in L1 header should not have changed");
2602 }
2603 }
2604 }
2605
2606 f_rsl_chan_deact();
2607 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2608
2609}
2610
2611/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002612private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002613 var L1ctlDlMessage l1_dl;
2614 var uint5_t pwr_var := 15;
2615 var uint5_t pwr_max_var := f_get_max_power_from_band();
2616
2617 /* set a low value to ensure power increases */
2618 f_trxc_fake_rssi(rxlev2dbm(10));
2619 f_l1_tune(L1CTL);
2620 RSL.clear;
2621
2622 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2623 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2624
2625 /* establish with fixed power level */
2626 f_est_dchan(more_ies :={valueof(pwr)});
2627
2628 /* check our initial power level */
2629 f_wait_for_l1_power_level(pwr_var);
2630
2631 /* update power param to enable power loop
2632 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2633 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2634
2635 /* wait, then check that our power level was reduced */
2636 timer T1 := 10.0;
2637 T1.start;
2638 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002639 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2640 /* Update sent MS power to follow what BTS requests */
2641 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2642 repeat;
2643 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002644 [] L1CTL.receive { repeat; }
2645 [] T1.timeout {
2646 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2647 if( f_power_level_is_highest_dbm(rcv) ){
2648 setverdict(pass, "Power level in L1 header reduced as expected");
2649 } else {
2650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2651 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2652 }
2653 }
2654 }
2655
2656 f_rsl_chan_deact();
2657 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2658
2659}
2660
2661/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002662private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002663 var L1ctlDlMessage l1_dl;
2664
2665 /* set a high value to ensure power decreases */
2666 f_trxc_fake_rssi(rxlev2dbm(50));
2667 f_l1_tune(L1CTL);
2668 RSL.clear;
2669
2670 var uint5_t pwr_var := 5;
2671 var uint5_t pwr_target_val := 15;
2672
2673 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2674 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2675
2676 /* establish with fixed power level */
2677 f_est_dchan(more_ies :={valueof(pwr)});
2678
2679 /* check our initial power level */
2680 f_wait_for_l1_power_level(pwr_var);
2681
2682 /* update power param to enable power loop
2683 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002684 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002685
2686 /* wait, then check that our power level was increased */
2687 timer T1 := 10.0;
2688 T1.start;
2689 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002690 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2691 /* Update sent MS power to follow what BTS requests */
2692 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2693 repeat;
2694 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002695 [] L1CTL.receive { repeat; }
2696 [] T1.timeout {
2697 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2698 setverdict(pass, "Power level in L1 header increased to lowest power value");
2699 } else {
2700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2701 "Power level in L1 header NOT increased to lowest power value");
2702 }
2703 }
2704 }
2705
2706 f_rsl_chan_deact();
2707 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2708
2709}
2710
Eric Wild095024b2019-06-17 15:08:57 +02002711/* see if we change the power level without receiving power parameters, which should not happen
2712rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002713private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002714 var L1ctlDlMessage l1_dl;
2715
2716 /* set a high value to ensure power decreases */
2717 f_trxc_fake_rssi(rxlev2dbm(50));
2718 f_l1_tune(L1CTL);
2719 RSL.clear;
2720
2721 var uint5_t pwr_var := 5;
2722
2723 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2724 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2725
2726 /* establish with fixed power level */
2727 f_est_dchan(more_ies :={valueof(pwr)});
2728
2729 /* check our initial power level */
2730 f_wait_for_l1_power_level(pwr_var);
2731
2732 /* wait, then check that our power level did not change */
2733 timer T1 := 10.0;
2734 T1.start;
2735 alt {
2736 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2737 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2739 "BS power control should not be active unless we receive a power parameters IE!");
2740 }
2741 repeat;
2742 }
2743 [] L1CTL.receive { repeat; }
2744 [] T1.timeout { setverdict(pass); }
2745 }
2746
2747 f_rsl_chan_deact();
2748 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2749
2750}
2751
Eric Wild095024b2019-06-17 15:08:57 +02002752/* see if we change the power level without receiving power parameters, which should not happen
2753ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002754private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002755 var L1ctlDlMessage l1_dl;
2756
2757 /* set a high value to ensure power decreases */
2758 f_trxc_fake_rssi(rxlev2dbm(50));
2759 f_l1_tune(L1CTL);
2760 RSL.clear;
2761
2762 var uint5_t pwr_var := 5;
2763
2764 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2765 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2766
2767 /* establish with fixed power level */
2768 f_est_dchan(more_ies :={valueof(pwr)});
2769
2770 /* check our initial power level */
2771 f_wait_for_l1_power_level(pwr_var);
2772
2773 /* pwr control without power params IE, should NOT activate MS power control*/
2774 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2775
2776 /* wait, then check that our power level did not change */
2777 timer T1 := 10.0;
2778 T1.start;
2779 alt {
2780 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2781 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2783 "BS power control should not be active unless we receive a power parameters IE!");
2784 }
2785 repeat;
2786 }
2787 [] L1CTL.receive { repeat; }
2788 [] T1.timeout { setverdict(pass); }
2789 }
2790
2791 f_rsl_chan_deact();
2792 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2793
2794}
2795
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002796private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002797 var L1ctlDlMessage l1_dl;
2798 timer T0 := 10.0;
2799 T0.start;
2800 alt {
2801 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2802 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2803 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2804 "Power level in L1 header != signaled (RSL) power level.");
2805 }
2806 }
2807 [] L1CTL.receive { repeat; }
2808 [] T0.timeout {
2809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2810 "Timeout waiting for initial power level");
2811 }
2812 }
2813 T0.stop;
2814}
2815
2816private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2817 var IntegerRecord min_dbm_level;
2818 var IntegerRecord max_dbm_level;
2819 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2820
2821 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2822 if (min_dbm_level[i] == level) {
2823 return true;
2824 }
2825 }
2826 return false;
2827}
2828
2829private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2830 var IntegerRecord min_dbm_level;
2831 var IntegerRecord max_dbm_level;
2832 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2833
2834 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2835 if (max_dbm_level[i] == level) {
2836 return true;
2837 }
2838 }
2839 return false;
2840}
2841
2842private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2843 var IntegerRecord min_dbm_level;
2844 var IntegerRecord max_dbm_level;
2845 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2846 return max_dbm_level[0];
2847}
2848
2849type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002850private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002851private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2852 // 45.005 4.1.1
2853 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2854 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2855 2, 1, 0};
2856 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2857 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2858 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2859 var IntegerRecord rv;
2860
2861 select(band){
2862 case (BtsBand_allGSM){
2863 rv := gsm_power;
2864 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2865 max_dbm_level := {2, 1, 0};
2866 }
2867 case("DCS1800"){
2868 rv := dcs_power;
2869 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2870 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2871 }
2872 case("PCS1900"){
2873 rv := pcs_power;
2874 min_dbm_level := {15};
2875 max_dbm_level := {30};
2876 }
Harald Welte194b6912020-10-11 21:01:55 +02002877 case else {
2878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2879 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002880 }
2881
2882 return rv;
2883}
2884
2885private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002886 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 +02002887}
2888
2889testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2890 var ConnHdlr vc_conn;
2891 var ConnHdlrPars pars;
2892 f_init();
2893 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2894 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2895 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2896 pars.bts0_band := f_vty_get_bts0_band();
2897 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2898 vc_conn.done;
2899 }
2900 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2902}
2903
2904testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2905 var ConnHdlr vc_conn;
2906 var ConnHdlrPars pars;
2907 f_init();
2908 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2909 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2910 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2911 pars.bts0_band := f_vty_get_bts0_band();
2912 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2913 vc_conn.done;
2914 }
2915 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2916 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2917}
2918
2919testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2920 var ConnHdlr vc_conn;
2921 var ConnHdlrPars pars;
2922 f_init();
2923 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2924 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2925 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2926 pars.bts0_band := f_vty_get_bts0_band();
2927 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2928 vc_conn.done;
2929 }
2930 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2931 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2932}
2933
2934testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2935 var ConnHdlr vc_conn;
2936 var ConnHdlrPars pars;
2937 f_init();
2938 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2939 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2940 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2941 pars.bts0_band := f_vty_get_bts0_band();
2942 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2943 vc_conn.done;
2944 }
2945 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2946 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2947}
2948
Eric Wild280ccb82019-06-17 11:11:52 +02002949testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2950 var ConnHdlr vc_conn;
2951 var ConnHdlrPars pars;
2952 f_init();
2953 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2954 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2955 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2956 pars.bts0_band := f_vty_get_bts0_band();
2957 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2958 vc_conn.done;
2959 }
2960 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2962}
2963
Eric Wild095024b2019-06-17 15:08:57 +02002964testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2965 var ConnHdlr vc_conn;
2966 var ConnHdlrPars pars;
2967 f_init();
2968 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2969 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2970 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2971 pars.bts0_band := f_vty_get_bts0_band();
2972 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2973 vc_conn.done;
2974 }
2975 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2977}
2978
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07002979testcase TC_meas_res_speech_tchf() runs on test_CT {
2980 var template RSL_IE_ChannelMode ch_mode;
2981 var ConnHdlr vc_conn;
2982 var ConnHdlrPars pars;
2983 f_init();
2984 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
2985 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
2986 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
2987 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2988 pcu_comp := false, trxc_comp := true);
2989 vc_conn.done;
2990 }
2991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2992}
2993testcase TC_meas_res_speech_tchh() runs on test_CT {
2994 var template RSL_IE_ChannelMode ch_mode;
2995 var ConnHdlr vc_conn;
2996 var ConnHdlrPars pars;
2997 f_init();
2998 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
2999 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3000 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3001 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3002 pcu_comp := false, trxc_comp := true);
3003 vc_conn.done;
3004 }
3005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3006}
3007
Harald Welte70767382018-02-21 12:16:40 +01003008testcase TC_meas_res_sign_tchf() runs on test_CT {
3009 var ConnHdlr vc_conn;
3010 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003011 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003012 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3013 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003014 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3015 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003016 vc_conn.done;
3017 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003018 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003019}
3020testcase TC_meas_res_sign_tchh() runs on test_CT {
3021 var ConnHdlr vc_conn;
3022 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003023 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003024 for (var integer ss := 0; ss <= 1; ss := ss+1) {
3025 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003026 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3027 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003028 vc_conn.done;
3029 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003031}
3032testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3033 var ConnHdlr vc_conn;
3034 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003035 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003036 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3037 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003038 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3039 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003040 vc_conn.done;
3041 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003043}
3044testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3045 var ConnHdlr vc_conn;
3046 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003047 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003048 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3049 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003050 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3051 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003052 vc_conn.done;
3053 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003055}
Harald Welte685d5982018-02-27 20:42:05 +01003056testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3057 var ConnHdlr vc_conn;
3058 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003059 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003060 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3061 for (var integer ss := 0; ss <= 1; ss := ss+1) {
3062 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
3063 pars.l1_pars.toa256_enabled := true;
3064 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
3065 vc_conn.done;
3066 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003067 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003068}
3069
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003070/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3071 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003072private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003073 var L1ctlDlMessage l1_dl;
3074 var RSL_IE_MS_Power ms_power;
3075 var RSL_Message rsl;
3076 var uint5_t power_level := 0;
3077
3078 f_l1_tune(L1CTL);
3079 RSL.clear;
3080
3081 f_est_dchan();
3082
3083 ms_power.reserved := 0;
3084 ms_power.fpc_epc := false;
3085
3086 /* Send the first power control command. This will disable any BTS/TRX
3087 * internal power control and switch the MS (which is not in scope of
3088 * this test) to a constant power level. We start with a power level
3089 * of 0 */
3090 ms_power.power_level := power_level;
3091 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3092 RSL.send(rsl);
3093
3094 alt {
3095
3096 /* Pick all SACCH blocks for checking */
3097 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3098
3099 /* The first byte of the L1 header contains the power level.
3100 * The reserved bits and the fpc bit is set to 0, so we may
3101 * compare directly. */
3102 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3103 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3104 }
3105
3106 /* Signal a new power level via RSL for the next turn. */
3107 if (power_level < 31) {
3108 power_level := power_level + 1;
3109 ms_power.power_level := power_level;
3110 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3111 RSL.send(rsl);
3112 repeat;
3113 }
3114
3115 }
3116
3117 /* Ignore all other blocks */
3118 [] L1CTL.receive { repeat; }
3119
3120 }
3121
3122 f_rsl_chan_deact();
3123 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3124
3125 setverdict(pass);
3126}
3127
3128testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3129 var ConnHdlr vc_conn;
3130 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003131 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003132
3133 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3134 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3135 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3136 vc_conn.done;
3137 }
3138 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3139}
Harald Welte70767382018-02-21 12:16:40 +01003140
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003141/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003142TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003143private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003144 var L1ctlDlMessage l1_dl;
3145 var uint5_t ta_to_test := 16;
3146
3147
3148 f_l1_tune(L1CTL);
3149 RSL.clear;
3150
3151 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003152 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003153
3154 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3155
3156
3157 alt {
3158
3159 /* Pick all SACCH blocks for checking */
3160 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3161
3162 /* The second byte of the L1 header contains the TA. */
3163 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3164 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3165 }
3166
3167 }
3168
3169 /* Ignore all other blocks */
3170 [] L1CTL.receive { repeat; }
3171
3172 }
3173
3174 f_rsl_chan_deact();
3175 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3176
3177 setverdict(pass);
3178}
3179
3180testcase TC_rsl_chan_initial_ta() runs on test_CT {
3181 var ConnHdlr vc_conn;
3182 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003183 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003184 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003185 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3186 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003187 vc_conn.done;
3188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3189}
3190
Eric Wilde57e1a62019-05-28 13:30:55 +02003191/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003192private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003193 var L1ctlDlMessage l1_dl;
3194 var uint5_t ms_power_level := 7;
3195
3196 var RSL_IE_MS_Power ms_power;
3197 ms_power.reserved := 0;
3198 ms_power.fpc_epc := false;
3199 ms_power.power_level := ms_power_level;
3200
3201 f_l1_tune(L1CTL);
3202 RSL.clear;
3203
3204 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3205
3206 timer T := 1.0;
3207 T.start;
3208 alt {
3209 /* Pick all SACCH blocks for checking */
3210 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3211 /* The first byte of the L1 header contains the power level.. */
3212 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3213 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3214 }
3215 }
3216 /* Ignore all other blocks */
3217 [] L1CTL.receive { repeat; }
3218 [] T.timeout {
3219 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3220 }
3221 }
3222
3223 f_rsl_chan_deact();
3224 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3225 setverdict(pass);
3226}
3227
3228testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3229 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3230 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3231}
3232
Harald Welte0472ab42018-03-12 15:02:26 +01003233/* 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 +01003234private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003235 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003236 RSL.clear;
3237
3238 f_est_dchan();
3239 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003240 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003241
3242 timer T := 40.0;
3243 T.start;
3244 alt {
3245 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3246 setverdict(pass)
3247 }
3248 [] RSL.receive { repeat };
3249 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003250 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003251 }
3252 }
3253 f_rsl_chan_deact();
3254}
3255testcase TC_conn_fail_crit() runs on test_CT {
3256 var ConnHdlr vc_conn;
3257 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003258 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003259 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3260 pars.t_guard := 60.0;
3261 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3262 vc_conn.done;
3263}
3264
Harald Welte93640c62018-02-25 16:59:33 +01003265/***********************************************************************
3266 * Paging
3267 ***********************************************************************/
3268
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003269private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003270 if (tmsi == 'FFFFFFFF'O) {
3271 return true;
3272 } else {
3273 return false;
3274 }
3275}
Harald Welte70767382018-02-21 12:16:40 +01003276
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003277private type record allowedFn { integer frame_nr }
3278private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3279private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3280private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3281private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3282private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3283private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3284private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3285private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3286private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003287{
3288 var integer frame_nr_51;
3289 frame_nr_51 := frame_nr mod 51
3290
3291 var allowedFn fn_check;
3292 fn_check.frame_nr := frame_nr_51;
3293
3294 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003295 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003296 return;
3297 }
3298
3299 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3300 return;
3301 }
3302 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3303 return;
3304 }
3305 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3306 return;
3307 }
3308 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3309 return;
3310 }
3311 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3312 return;
3313 }
3314 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3315 return;
3316 }
3317 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3318 return;
3319 }
3320 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3321 return;
3322 }
3323
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003325 return;
3326}
3327
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003328private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3329 inout integer num_paging_rcv_ids,
3330 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003331runs on test_CT {
3332 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003333 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003334 repeat;
3335 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003336 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003337 var octetstring without_plen :=
3338 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3339 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003340
3341 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3342
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003343 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3344 /* Ignore empty RR Paging Request (PCH filling) messages.
3345 * TODO: does it make sense to count them? */
3346 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003347 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3348 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003349 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003350 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3351 }
3352 } else if (match(rr, tr_PAGING_REQ2)) {
3353 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3354 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3355 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3356 }
3357 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3358 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3359 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003360 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003361 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3362 }
3363 } else if (match(rr, tr_PAGING_REQ3)) {
3364 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3365 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3366 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3367 }
3368 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3369 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3370 }
3371 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3372 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3373 }
3374 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3375 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3376 }
3377 }
3378 repeat;
3379 }
3380}
3381
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003382private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003383 boolean combined_ccch,
3384 integer bs_ag_blks_res,
3385 float load_factor,
3386 boolean exp_load_ind,
3387 boolean exp_overload,
3388 boolean use_tmsi
3389}
3390
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003391private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003392 integer num_paging_sent,
3393 integer num_paging_rcv_msgs,
3394 integer num_paging_rcv_ids,
3395 integer num_overload
3396}
3397
Harald Welte68e495b2018-02-25 00:05:57 +01003398/* Helper function for paging related testing */
3399private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003400 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003401 f_init_l1ctl();
3402 f_l1_tune(L1CTL);
3403
3404 var PagingTestState st := {
3405 num_paging_sent := 0,
3406 num_paging_rcv_msgs := 0,
3407 num_paging_rcv_ids := 0,
3408 num_overload := 0
3409 };
3410
3411 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3412 var float max_pch_imsi_per_sec;
3413 if (cfg.use_tmsi) {
3414 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3415 } else {
3416 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3417 }
3418 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3419 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003420 var float time_total := 20.0;
3421 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3422 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003423
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003424 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3425 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003426
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003427 timer T_itv := 0.0;
3428 T_itv.start;
3429 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003430 alt {
3431 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003432 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003433 st.num_overload := st.num_overload + 1;
3434 repeat;
3435 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003436 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003437 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003438 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003439 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003440 log("Rx LOAD_IND");
3441 /* FIXME: analyze/verify interval + contents */
3442 repeat;
3443 }
3444 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003445 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003446 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003447 [] T_itv.timeout {
3448 /* Send paging cmds based on elapsed time */
3449 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3450 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003451 var MobileIdentityV mi;
3452
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003453 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003454 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003455 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003456 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003457 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003458 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003459
3460 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003461 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 +02003462
3463 st.num_paging_sent := st.num_paging_sent + 1;
3464 }
3465 if (st.num_paging_sent < pkt_total) {
3466 /* Wait for interval to next PAGING COMMAND */
3467 var float time_now := T_total.read;
3468 var float next_sched := int2float(st.num_paging_sent)*interval;
3469 if (next_sched > time_now) {
3470 T_itv.start(next_sched - time_now);
3471 } else {
3472 T_itv.start(0.0);
3473 }
3474 } else {
3475 /* We are done, no need to keep counting */
3476 T_total.stop;
3477 }
3478 }
3479 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003480 }
3481 }
3482
3483 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3484 timer T_wait := 18.0;
3485 T_wait.start;
3486 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003487 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003488 [] L1CTL.receive { repeat; }
3489 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003490 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3491 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003492 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003494 }
Harald Welte68e495b2018-02-25 00:05:57 +01003495 }
3496
3497 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3498 " rcvd_ids=", st.num_paging_rcv_ids);
3499 return st;
3500}
3501
3502/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3503 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3504 * - that CCCH LOAD IND (PCH) are being generated
3505 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3506testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003507 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003508 var PagingTestCfg cfg := {
3509 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003510 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003511 load_factor := 0.8,
3512 exp_load_ind := true,
3513 exp_overload := false,
3514 use_tmsi := false
3515 };
3516 var PagingTestState st := f_TC_paging(cfg);
3517 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3519 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003520 } else {
3521 setverdict(pass);
3522 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003523 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003524}
3525
3526/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3527 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3528 * - that CCCH LOAD IND (PCH) are being generated
3529 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3530testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003531 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003532 var PagingTestCfg cfg := {
3533 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003534 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003535 load_factor := 0.8,
3536 exp_load_ind := true,
3537 exp_overload := false,
3538 use_tmsi := true
3539 };
3540 var PagingTestState st := f_TC_paging(cfg);
3541 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3543 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003544 } else {
3545 setverdict(pass);
3546 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003547 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003548}
3549
3550/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3551 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3552 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3553 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3554testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003555 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003556 var PagingTestCfg cfg := {
3557 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003558 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003559 load_factor := 2.0,
3560 exp_load_ind := true,
3561 exp_overload := true,
3562 use_tmsi := false
3563 };
3564 var PagingTestState st := f_TC_paging(cfg);
3565 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3566 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003567 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003568 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003569 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 +01003570 } else {
3571 setverdict(pass);
3572 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003573 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003574}
3575
3576/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3577 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3578 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3579 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3580testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003581 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003582 var PagingTestCfg cfg := {
3583 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003584 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003585 load_factor := 2.0,
3586 exp_load_ind := true,
3587 exp_overload := true,
3588 use_tmsi := true
3589 };
3590 var PagingTestState st := f_TC_paging(cfg);
3591 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3592 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003593 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003594 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003595 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 +01003596 } else {
3597 setverdict(pass);
3598 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003599 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003600}
3601
3602
Harald Welte93640c62018-02-25 16:59:33 +01003603/***********************************************************************
3604 * Immediate Assignment / AGCH
3605 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003606private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003607 len := 0,
3608 ma := ''B
3609}
Harald Welte93640c62018-02-25 16:59:33 +01003610
Harald Weltee8d750e2018-06-10 21:41:35 +02003611private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3612 return int2str(num_tx) & " sent, "
3613 & int2str(num_rx) & " received, "
3614 & int2str(num_del) & " deleted";
3615}
3616
3617private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3618 var L1ctlDlMessage l1_dl;
3619 timer T := 10.0;
3620 var integer num_tx := 0;
3621 var integer num_rx := 0;
3622 var integer num_del := 0;
3623 var charstring res_str;
3624 var float rx_ratio;
3625
Harald Welte10474062019-05-30 16:48:17 +02003626 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003627 f_init_l1ctl();
3628 f_l1_tune(L1CTL);
3629
3630 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003631 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003632 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3633 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003634 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003635 num_tx := num_tx+1;
3636 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003637 }
3638 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003639 T.start;
3640 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003641 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003642 num_del := num_del+1;
3643 repeat;
3644 }
3645 [] RSL_CCHAN.receive {
3646 repeat;
3647 }
3648 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003649 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3650 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3651 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003652 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003653 } else {
3654 num_rx := num_rx+1;
3655 }
3656 repeat;
3657 }
3658 [] L1CTL.receive { repeat; }
3659 [] T.timeout { }
3660 }
3661 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3662 log("AGCH test: " & res_str);
3663 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003664 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003665 }
3666 rx_ratio := int2float(num_rx) / int2float(num_tx);
3667 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003668 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 +02003669 } else {
3670 setverdict(pass);
3671 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003673}
3674
Harald Weltee8d750e2018-06-10 21:41:35 +02003675/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3676testcase TC_imm_ass_1000_20ms() runs on test_CT {
3677 f_TC_imm_ass(1000, 0.02, 0.25);
3678}
3679
3680/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3681testcase TC_imm_ass_200_0ms() runs on test_CT {
3682 f_TC_imm_ass(200, 0.0, 0.05);
3683}
3684
3685/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3686testcase TC_imm_ass_200_76ms() runs on test_CT {
3687 f_TC_imm_ass(150, 0.076, 1.00);
3688}
3689
3690
3691
Harald Welte48494ca2018-02-25 16:59:50 +01003692/***********************************************************************
3693 * BCCH
3694 ***********************************************************************/
3695
3696/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003697private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003698 GsmFrameNumber frame_number,
3699 SystemInformation si
3700}
3701
3702/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003703private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003704
3705/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003706private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003707
3708/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003709private function f_si_vecslot_contains(SystemInformationVector arr,
3710 RrMessageType key,
3711 boolean bcch_ext := false)
3712return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003713 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3714 var integer fn_mod51 := arr[i].frame_number mod 51;
3715 if (not bcch_ext and fn_mod51 == 2 or
3716 bcch_ext and fn_mod51 == 6) {
3717 if (arr[i].si.header.message_type == key) {
3718 return true;
3719 }
3720 }
3721 }
3722 return false;
3723}
3724
3725/* 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 +07003726private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3727 integer tc, RrMessageType key,
3728 boolean ext_bcch := false)
3729{
Harald Welte48494ca2018-02-25 16:59:50 +01003730 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003731 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003732 }
3733}
3734
3735/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003736private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3737 RrMessageType key)
3738return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003739 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3740 if (f_si_vecslot_contains(arr[tc], key) or
3741 f_si_vecslot_contains(arr[tc], key, true)) {
3742 return true;
3743 }
3744 }
3745 return false;
3746}
3747
3748/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003749private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3750 RrMessageType key,
3751 boolean bcch_ext := false,
3752 integer n := 1, integer m := 4)
3753return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003754 var integer count := 0;
3755 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003756 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3757 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003758 }
3759 for (var integer i:= 0; i < m; i := i + 1) {
3760 var integer fn_mod51 := arr[i].frame_number mod 51;
3761 if (not bcch_ext and fn_mod51 == 2 or
3762 bcch_ext and fn_mod51 == 6) {
3763 if (arr[i].si.header.message_type == key) {
3764 count := count + 1;
3765 }
3766 }
3767 }
3768 if (count >= n) {
3769 return true;
3770 } else {
3771 return false;
3772 }
3773}
3774
3775/* 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 +07003776private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3777 integer tc, RrMessageType key,
3778 boolean ext_bcch := false,
3779 integer n, integer m)
3780{
Harald Welte48494ca2018-02-25 16:59:50 +01003781 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003783 }
3784}
3785
3786/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003787private function f_si_vecslot_contains_only(SystemInformationVector arr,
3788 RrMessageType key,
3789 boolean bcch_ext := false)
3790return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003791 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3792 var integer fn_mod51 := arr[i].frame_number mod 51;
3793 if (not bcch_ext and fn_mod51 == 2 or
3794 bcch_ext and fn_mod51 == 6) {
3795 if (arr[i].si.header.message_type != key) {
3796 return false;
3797 }
3798 }
3799 }
3800 return true;
3801}
3802
3803/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003804private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3805 integer tc, RrMessageType key,
3806 boolean ext_bcch := false)
3807{
Harald Welte48494ca2018-02-25 16:59:50 +01003808 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003810 }
3811}
3812
3813/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003814private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003815 boolean bcch_extended,
3816 boolean si1_present,
3817 boolean si2bis_present,
3818 boolean si2ter_present,
3819 boolean si2quater_present,
3820 boolean si7_present,
3821 boolean si8_present,
3822 boolean si9_present,
3823 boolean si13_present,
3824 boolean si13alt_present,
3825 boolean si15_present,
3826 boolean si16_present,
3827 boolean si17_present,
3828 boolean si2n_present,
3829 boolean si21_present,
3830 boolean si22_present
3831}
3832
3833/* 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 +07003834private function f_validate_si_scheduling(SystemInformationConfig cfg,
3835 SystemInformationVectorPerTc si_per_tc)
3836{
Harald Welte48494ca2018-02-25 16:59:50 +01003837 var integer i;
3838 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3839 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003840 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003841 }
3842 }
3843 if (cfg.si1_present) {
3844 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3845 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3846 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3847 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3848 /* make sure *ALL* contain SI1 */
3849 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3850 }
3851 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3852 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3853 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3854 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3855 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3856 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3857
3858 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3859 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3860 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3861 * consecutive occurrences of TC = 4. */
3862 if (cfg.si2bis_present and not cfg.si2ter_present) {
3863 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3864 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3865 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3866 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3867 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3868 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3869 }
3870
3871 if (cfg.si7_present or cfg.si8_present) {
3872 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3873 * if System Information type 4 does not contain all information needed for cell
3874 * selection and reselection. */
3875 if (not cfg.bcch_extended) {
3876 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3877 }
3878 if (cfg.si7_present) {
3879 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3880 }
3881 if (cfg.si8_present) {
3882 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3883 }
3884 }
3885
3886 if (cfg.si2quater_present) {
3887 /* iii) System information type 2 quater is sent if needed, as determined by the system
3888 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3889 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3890 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3891 * within any of 4 consecutive occurrences of TC = 5. */
3892 if (not (cfg.bcch_extended)) {
3893 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3894 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3895 } else {
3896 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3897 }
3898 } else {
3899 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3900 }
3901 }
3902 if (cfg.si9_present) {
3903 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3904 * in system information type 3 as defined in 3GPP TS 44.018. */
3905 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3906 }
3907 if (cfg.si13_present) {
3908 /* vii) System Information type 13 is only related to the GPRS service. System Information
3909 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3910 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3911 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3912 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3913 * within any of 4 consecutive occurrences of TC=4. */
3914 if (not cfg.bcch_extended) {
3915 log("not-bccch-extended");
3916 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3917 } else {
3918 log("bccch-extended");
3919 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3920 }
3921 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003922 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003923 }
3924 }
3925 if (cfg.si16_present or cfg.si17_present) {
3926 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3927 * should not be sent in a cell where network sharing is used (see rule xv). */
3928 if (cfg.si22_present) {
3929 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3930 }
3931 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003932 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003933 }
3934 if (not cfg.bcch_extended) {
3935 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3936 }
3937 if (cfg.si16_present) {
3938 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3939 }
3940 if (cfg.si17_present) {
3941 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3942 }
3943 }
3944
3945 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3946 * broadcast information. The frequency with which they are sent is determined by the
3947 * system operator. System Information type 9 identifies the scheduling of System
3948 * Information type 18 and 20 messages. */
3949
3950 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3951 * Information Type 19 is present, then its scheduling shall be indicated in System
3952 * Information Type 9. */
3953
3954 if (cfg.si15_present) {
3955 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3956 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3957 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3958 * 4 consecutive occurrences of TC = 1. */
3959 if (not cfg.bcch_extended) {
3960 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3961 } else {
3962 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3963 }
3964 }
3965 if (cfg.si13alt_present) {
3966 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3967 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3968 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3969 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3970 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3971 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3972 * of TC = 4. */
3973 if (cfg.si13_present) {
3974 testcase.stop("Error: Cannot have SI13alt and SI13");
3975 }
3976 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003978 }
3979 if (not cfg.bcch_extended) {
3980 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3981 } else {
3982 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3983 }
3984 }
3985 if (cfg.si2n_present) {
3986 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3987 * as determined by the system operator. In the case that the message is sent on the
3988 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3989 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3990 * consecutive occurrences of TC = 4. */
3991 if (not cfg.bcch_extended) {
3992 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3993 } else {
3994 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3995 }
3996 }
3997 if (cfg.si21_present) {
3998 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3999 * determined by the system operator. If Extended Access Barring is in use in the cell
4000 * then this message is sent at least once within any of 4 consecutive occurrences of
4001 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4002 * cell then this message shall only be sent on BCCH Ext. */
4003 if (not cfg.bcch_extended) {
4004 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4005 } else {
4006 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4007 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004009 }
4010 }
4011 }
4012 if (cfg.si22_present) {
4013 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4014 * should not be sent in a cell where SoLSA is used (see rule viii). System
4015 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4016 * =2 and TC=6. */
4017 if (cfg.si16_present or cfg.si17_present) {
4018 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4019 }
4020 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4021 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004022 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004023 }
4024 if (not cfg.bcch_extended) {
4025 testcase.stop("Error: SI22 requires BCCH Extd!");
4026 } else {
4027 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4028 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4029 }
4030 }
4031}
4032
4033/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004034private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4035return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004036 timer T := duration;
4037 var SystemInformationVectorPerTc si_per_tc;
4038 var L1ctlDlMessage l1_dl;
4039
4040 /* initialize all per-TC vectors empty */
4041 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4042 si_per_tc[i] := {};
4043 }
4044
4045 /* flush all previous L1 queued msgs */
4046 pt.clear;
4047
4048 T.start;
4049 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004050 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004051 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4052 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4053 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004054 repeat;
4055 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004056
Harald Welte48494ca2018-02-25 16:59:50 +01004057 var integer tc := f_gsm_compute_tc(sig.frame_number);
4058 log("SI received at TC=", tc, ": ", sig.si);
4059 /* append to the per-TC bucket */
4060 si_per_tc[tc] := si_per_tc[tc] & { sig };
4061 repeat;
4062 }
4063 [] pt.receive { repeat; }
4064 [] T.timeout { }
4065 }
4066
4067 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4068 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4069 }
4070 log("si_per_tc=", si_per_tc);
4071 return si_per_tc;
4072}
4073
4074/* helper function: Set given SI via RSL + validate scheduling.
4075 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004076private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004077 var SystemInformationVectorPerTc si_per_tc;
4078 f_init_l1ctl();
4079 f_l1_tune(L1CTL);
4080
4081 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004082 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004083 f_validate_si_scheduling(si_cfg, si_per_tc);
4084
4085 setverdict(pass);
4086}
4087
4088testcase TC_si_sched_default() runs on test_CT {
4089 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004090 /* 2+3+4 are mandatory and set in f_init() */
4091 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004093}
4094
4095testcase TC_si_sched_1() runs on test_CT {
4096 f_init();
4097 si_cfg.si1_present := true;
4098 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004099 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004101}
4102
4103testcase TC_si_sched_2bis() runs on test_CT {
4104 f_init();
4105 si_cfg.si2bis_present := true;
4106 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4107 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004108 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004109}
4110
4111testcase TC_si_sched_2ter() runs on test_CT {
4112 f_init();
4113 si_cfg.si2ter_present := true;
4114 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4115 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004116 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004117}
4118
4119testcase TC_si_sched_2ter_2bis() runs on test_CT {
4120 f_init();
4121 si_cfg.si2bis_present := true;
4122 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4123 si_cfg.si2ter_present := true;
4124 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4125 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004127}
4128
4129testcase TC_si_sched_2quater() runs on test_CT {
4130 f_init();
4131 si_cfg.si2quater_present := true;
4132 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004133 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004134 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004135}
4136
4137testcase TC_si_sched_13() runs on test_CT {
4138 f_init();
4139 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004140 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004141 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004142 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004143}
4144
4145testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4146 f_init();
4147 si_cfg.si2bis_present := true;
4148 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4149 si_cfg.si2ter_present := true;
4150 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4151 si_cfg.si2quater_present := true;
4152 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4153 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004154 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004155 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004157}
4158
4159
Harald Welte68e495b2018-02-25 00:05:57 +01004160testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004161 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004162 /* FIXME: enable / disable individual BCCH info */
4163 //ts_RSL_BCCH_INFO(si_type, info);
4164 /* expect no ERROR REPORT after either of them *
4165 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004167}
4168
Harald Welte93640c62018-02-25 16:59:33 +01004169/***********************************************************************
4170 * Low-Level Protocol Errors / ERROR REPORT
4171 ***********************************************************************/
4172
Harald Welte01d982c2018-02-25 01:31:40 +01004173private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4174 timer T := 5.0;
4175 T.start;
4176 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004177 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004178 setverdict(pass);
4179 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004180 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004182 }
4183 [] RSL_CCHAN.receive {
4184 repeat;
4185 }
4186 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004188 }
4189 }
4190}
4191
4192/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4193testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004194 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004195 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4196 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004197 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004198
4199 f_exp_err_rep(RSL_ERR_PROTO);
4200}
4201
4202/* Provoke a mandatory IE error and match on ERROR REPORT */
4203testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004204 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004205
4206 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4207 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004208 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004209
4210 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4211}
4212
4213/* Provoke an IE content error and match on ERROR REPORT */
4214testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004215 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004216 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4217 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004218 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004219
4220 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4221}
4222
Harald Welteee25aae2019-05-19 14:32:37 +02004223/* attempt to activate channel with wrong RSL Message Discriminator IE */
4224function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4225 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4226 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4227 RSL.send(rsl);
4228 f_rslem_unregister(0, g_chan_nr);
4229}
4230testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4231 var ConnHdlr vc_conn;
4232 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4233
Harald Welte10474062019-05-30 16:48:17 +02004234 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004235
4236 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4237 vc_conn.done;
4238 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4239
4240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4241}
4242
4243/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004244private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004245 var template (value) RSL_Message rsl_tx;
4246 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4247 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4248 RSL.send(rsl_tx);
4249 f_rslem_unregister(0, g_chan_nr);
4250}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004251private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004252 var template (value) RSL_Message rsl_tx;
4253 /* we first have to activate the dedicated channel */
4254 f_rsl_chan_act(g_pars.chan_mode);
4255 /* ... to then send an invalid RLL message */
4256 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4257 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4258 RSL.send(rsl_tx);
4259 f_rslem_unregister(0, g_chan_nr);
4260}
4261testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4262 var ConnHdlr vc_conn;
4263 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4264 var template (value) RSL_Message rsl_tx;
4265
Harald Welte10474062019-05-30 16:48:17 +02004266 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004267
4268 /* Common Channel with wrong message type */
4269 RSL_CCHAN.clear;
4270 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4271 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004272 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004273 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4274
4275 /* TRX Management */
4276 RSL_CCHAN.clear;
4277 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4278 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004279 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004280 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4281
4282 /* Dedicated Channel */
4283 RSL_CCHAN.clear;
4284 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4285 vc_conn.done;
4286 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4287
4288 /* RLL */
4289 RSL_CCHAN.clear;
4290 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4291 vc_conn.done;
4292 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4293}
4294
4295/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004296private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004297 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4298 f_rslem_unregister(0, g_chan_nr);
4299}
4300testcase TC_err_rep_wrong_sequence() runs on test_CT {
4301 var ConnHdlr vc_conn;
4302 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4303
Harald Welte10474062019-05-30 16:48:17 +02004304 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004305
4306 RSL_CCHAN.clear;
4307 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4308 vc_conn.done;
4309 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4310}
4311
Harald Welte93640c62018-02-25 16:59:33 +01004312/***********************************************************************
4313 * IPA CRCX/MDCX/DLCS media stream handling
4314 ***********************************************************************/
4315
Harald Weltea871a382018-02-25 02:03:14 +01004316/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004317private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004318 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4319 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004320}
4321testcase TC_ipa_dlcx_not_active() runs on test_CT {
4322 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004323 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004324 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4325 vc_conn.done;
4326}
Harald Welte68e495b2018-02-25 00:05:57 +01004327
Harald Weltea3f1df92018-02-25 12:49:55 +01004328/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004329private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004330 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4331 "IPA CRCX ACK");
4332 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4333 "IPA CRCX NACK");
4334}
4335testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4336 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004337 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004338 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4339 vc_conn.done;
4340}
4341
4342/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004343private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004344 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4345 "IPA CRCX ACK");
4346 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4347 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4348 var uint7_t rtp_pt2 := f_rnd_int(127);
4349 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4350 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4351 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4352 "IPA MDCX ACK");
4353 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4354 "IPA DLCX ACK");
4355}
4356testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4357 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004358 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004359 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4360 vc_conn.done;
4361}
4362
Harald Welte3ae11da2018-02-25 13:36:06 +01004363/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004364private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004365 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4366 "IPA CRCX ACK");
4367 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4368 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4369 var uint7_t rtp_pt2 := f_rnd_int(127);
4370 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4371 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4372 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4373 "IPA MDCX ACK");
4374 /* Second MDCX */
4375 remote_ip := f_rnd_int(c_UINT32_MAX);
4376 remote_port := f_rnd_int(c_UINT16_MAX);
4377 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4378 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4379 "IPA MDCX ACK");
4380 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4381 "IPA DLCX ACK");
4382}
4383testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4384 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004385 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004386 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4387 vc_conn.done;
4388}
4389
Harald Welte9912eb52018-02-25 13:30:15 +01004390/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004391private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004392 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4393 "IPA CRCX NACK");
4394}
4395testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4396 var ConnHdlrPars pars;
4397 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004398 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004399
4400 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4401 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4402 vc_conn.done;
4403
4404 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4405 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4406 vc_conn.done;
4407}
4408
Harald Weltea3f1df92018-02-25 12:49:55 +01004409
Harald Welte883340c2018-02-28 18:59:29 +01004410/***********************************************************************
4411 * PCU Socket related tests
4412 ***********************************************************************/
4413
Harald Welte07bd2d22019-05-25 11:03:30 +02004414/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004415friend 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 +01004416runs on test_CT {
4417 timer T := 3.0;
4418
4419 /* we don't expect any RTS.req before PDCH are active */
4420 T.start;
4421 alt {
4422 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004424 }
4425 [] PCU.receive { repeat; }
4426 [] T.timeout { }
4427 }
4428
4429 /* Send PDCH activate request for known PDCH timeslot */
4430 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4431
4432 /* we now expect RTS.req for this timeslot (only) */
4433 T.start;
4434 alt {
4435 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4436 setverdict(pass);
4437 }
4438 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4439 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004440 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004441 }
4442 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004444 }
4445 [] PCU.receive { repeat; }
4446 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004447 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004448 }
4449 [not exp_success] T.timeout {
4450 setverdict(pass);
4451 }
4452 }
4453}
4454
Harald Welte07bd2d22019-05-25 11:03:30 +02004455/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004456friend 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 +01004457runs on test_CT {
4458 timer T := 3.0;
4459
4460 /* Send PDCH activate request for known PDCH timeslot */
4461 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 +02004462 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4463 * when it will actually have been executed in the BTS */
4464 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004465 PCU.clear;
4466 /* we now expect no RTS.req for this timeslot */
4467 T.start;
4468 alt {
4469 [] 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 +02004470 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004471 }
4472 [] PCU.receive { repeat; }
4473 [] T.timeout {
4474 setverdict(pass);
4475 }
4476 }
4477}
4478
Harald Weltead033dc2019-05-25 17:28:16 +02004479friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004480 f_init();
4481 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4482}
4483
Harald Welte883340c2018-02-28 18:59:29 +01004484/* PDCH activation via PCU socket; check for presence of RTS.req */
4485testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004486 f_init_pcu_test();
4487
Harald Welte883340c2018-02-28 18:59:29 +01004488 f_TC_pcu_act_req(0, 0, 7, true);
4489}
4490
4491/* PDCH activation via PCU socket on non-PDCU timeslot */
4492testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004493 f_init_pcu_test();
4494
Harald Welte883340c2018-02-28 18:59:29 +01004495 f_TC_pcu_act_req(0, 0, 1, false);
4496}
4497
4498/* PDCH activation via PCU socket on wrong BTS */
4499testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004500 f_init_pcu_test();
4501
Harald Welte883340c2018-02-28 18:59:29 +01004502 f_TC_pcu_act_req(23, 0, 7, false);
4503}
4504
4505/* PDCH activation via PCU socket on wrong TRX */
4506testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004507 f_init_pcu_test();
4508
Harald Welte883340c2018-02-28 18:59:29 +01004509 f_TC_pcu_act_req(0, 23, 7, false);
4510}
4511
4512/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4513testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004514 f_init_pcu_test();
4515
Harald Welte883340c2018-02-28 18:59:29 +01004516 /* Activate PDCH */
4517 f_TC_pcu_act_req(0, 0, 7, true);
4518 f_sleep(1.0);
4519 /* and De-Activate again */
4520 f_TC_pcu_deact_req(0, 0, 7);
4521}
4522
4523/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4524testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004525 f_init_pcu_test();
4526
Harald Welte883340c2018-02-28 18:59:29 +01004527 f_TC_pcu_deact_req(0, 0, 1);
4528}
4529
4530/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4531testcase TC_pcu_ver_si13() runs on test_CT {
4532 const octetstring si13 := '00010203040506070909'O;
4533 var PCUIF_send_data sd;
4534 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004535 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004536
4537 /* Set SI13 via RSL */
4538 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004539
Harald Welte883340c2018-02-28 18:59:29 +01004540 T.start;
4541 alt {
4542 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4543 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4544 setverdict(pass);
4545 } else {
4546 repeat;
4547 }
4548 }
4549 [] PCU.receive { repeat; }
4550 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004551 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004552 }
4553 }
4554}
4555
4556private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4557
4558/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004559friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004560 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4561runs on test_CT
4562{
4563 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4564 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4565}
4566
4567/* 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 +02004568friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4569 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004570runs on test_CT
4571{
4572 var PCUIF_send_data sd;
4573
4574 timer T := 3.0;
4575 T.start;
4576 alt {
4577 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4578 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4579 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4580 sd.data.u.rts_req.fn, sapi, data);
4581 }
4582 [] PCU.receive { repeat; }
4583 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004584 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004585 }
4586 }
4587}
4588
4589/* Send DATA.req on invalid BTS */
4590testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004591 var TfiUsfArr tua := f_TfiUsfArrInit();
4592 var octetstring data := '0000'O & f_rnd_octstring(21);
4593
4594 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004595
Harald Welte883340c2018-02-28 18:59:29 +01004596 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004597 f_TfiUsfArrSet(tua, 7, 0);
4598 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4599 f_sleep(1.0);
4600
4601 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004602}
4603
4604/* Send DATA.req on invalid TRX */
4605testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004606 var TfiUsfArr tua := f_TfiUsfArrInit();
4607 var octetstring data := '0000'O & f_rnd_octstring(21);
4608
4609 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004610
Harald Welte883340c2018-02-28 18:59:29 +01004611 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004612 f_TfiUsfArrSet(tua, 7, 0);
4613 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4614 f_sleep(1.0);
4615
4616 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004617}
4618
4619/* Send DATA.req on invalid timeslot */
4620testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004621 var TfiUsfArr tua := f_TfiUsfArrInit();
4622 var octetstring data := '0000'O & f_rnd_octstring(21);
4623
4624 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004625
Harald Welte883340c2018-02-28 18:59:29 +01004626 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004627 f_TfiUsfArrSet(tua, 7, 0);
4628 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4629 f_sleep(1.0);
4630
4631 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004632}
4633
4634/* Send DATA.req on timeslot that hasn't been activated */
4635testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004636 var TfiUsfArr tua := f_TfiUsfArrInit();
4637 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004638
Harald Welte7162a612019-05-26 12:56:09 +02004639 f_virtphy_common();
4640
4641 f_TfiUsfArrSet(tua, 7, 0);
4642 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4643 f_sleep(1.0);
4644
4645 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004646}
4647
Harald Weltead033dc2019-05-25 17:28:16 +02004648private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004649 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4650 boolean wait_rts := true)
4651runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004652 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004653 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004654
4655 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004656 if (wait_rts) {
4657 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4658 } else {
4659 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4660 }
Harald Weltead033dc2019-05-25 17:28:16 +02004661
4662 T.start;
4663 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004664 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004665 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4666 setverdict(pass);
4667 }
Harald Welte7162a612019-05-26 12:56:09 +02004668 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4669 setverdict(fail, "Received unexpected ", rx_dl);
4670 }
Harald Weltead033dc2019-05-25 17:28:16 +02004671 [] L1CTL.receive {
4672 repeat;
4673 }
Harald Welte7162a612019-05-26 12:56:09 +02004674 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004675 setverdict(fail, "Timeout waiting for ", data);
4676 }
Harald Welte7162a612019-05-26 12:56:09 +02004677 [not expect_data] T.timeout {
4678 setverdict(pass);
4679 }
Harald Weltead033dc2019-05-25 17:28:16 +02004680 }
4681}
4682
4683private function f_disable_dynamic_ts() runs on test_CT
4684{
4685 f_init_vty_bsc();
4686 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4687 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4688 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4689 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004690 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004691}
4692
4693private function f_virtphy_common() runs on test_CT {
4694 f_disable_dynamic_ts();
4695 f_init_l1ctl();
4696 f_l1_tune(L1CTL);
4697}
4698
4699testcase TC_pcu_data_req_pdtch() runs on test_CT {
4700 var TfiUsfArr tua := f_TfiUsfArrInit();
4701 var octetstring data := '0000'O & f_rnd_octstring(21);
4702
4703 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004704
Harald Welte883340c2018-02-28 18:59:29 +01004705 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004706 f_TfiUsfArrSet(tua, 7, 0);
4707 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4708 f_sleep(1.0);
4709
4710 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004711}
4712
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004713/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004714testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004715 var TfiUsfArr tua := f_TfiUsfArrInit();
4716 var octetstring data := '0000'O & f_rnd_octstring(21);
4717
4718 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004719
Harald Welte883340c2018-02-28 18:59:29 +01004720 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004721 f_TfiUsfArrSet(tua, 7, 0);
4722 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4723 f_sleep(1.0);
4724
4725 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004726}
4727
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004728private function f_TC_pcu_ptcch_ul(uint16_t ra)
4729runs on test_CT {
4730 var template PCUIF_Message pcu_rach_ind;
4731 var PCUIF_send_data sd;
4732 var GsmFrameNumber fn;
4733 timer T;
4734
4735 /* Send an Access Burst on PTCCH/U over the Um-interface */
4736 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4737 chan_nr := ts_RslChanNr_PDCH(7),
4738 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4739
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004740 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4741 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004742
4743 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4744 T.start(52.0 * 4.615 / 1000.0);
4745 alt {
4746 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4747 log("Rx an Access Burst on the PCU interface: ", sd.data);
4748 setverdict(pass);
4749 T.stop;
4750 }
4751 [] PCU.receive { repeat; }
4752 [] T.timeout {
4753 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4754 /* Keep going, that's not the end of the world */
4755 }
4756 }
4757}
4758
4759testcase TC_pcu_ptcch() runs on test_CT {
4760 var L1ctlDlMessage dl;
4761 var octetstring data;
4762 timer T;
4763
4764 f_init_pcu_test();
4765 f_init_l1ctl();
4766 f_l1_tune(L1CTL);
4767
4768 /* Activate PDCH channel on TS7 */
4769 f_TC_pcu_act_req(0, 0, 7, true);
4770
4771 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004772 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004773 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004774 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004775 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004776
4777 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4778 for (var integer i := 0; i < 16; i := i + 1) {
4779 log("Sending an Access Burst towards the L1CTL interface");
4780 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4781 }
4782
4783 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4784 data := f_rnd_octstring(23);
4785
4786 /* Verify PTCCH/D: send a random data block, make sure it's received */
4787 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4788 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4789
4790 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4791 * let's give it more time in case if we miss the beginning. */
4792 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4793 alt {
4794 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4795 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4796 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4797 frame := data)) -> value dl {
4798 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4799 setverdict(pass);
4800 T.stop;
4801 }
4802 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4803 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4804 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4805 l2_data := data)) -> value dl {
4806 log("Rx PTCCH/D data block on L1CTL: ", dl);
4807 setverdict(pass);
4808 T.stop;
4809 }
4810 [] L1CTL.receive { repeat; }
4811 [] T.timeout {
4812 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4813 }
4814 }
4815}
4816
Harald Welte883340c2018-02-28 18:59:29 +01004817/* Send AGCH from PCU; check it appears on Um side */
4818testcase TC_pcu_data_req_agch() runs on test_CT {
4819 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004820 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004821 f_init_l1ctl();
4822 f_l1_tune(L1CTL);
4823
4824 f_TC_pcu_act_req(0, 0, 7, true);
4825 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4826
4827 T.start;
4828 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004829 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004830 setverdict(pass);
4831 }
4832 [] L1CTL.receive { repeat; }
4833 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004834 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004835 }
4836 }
4837}
4838
Harald Welte928622b2019-05-26 13:22:59 +02004839/* Send AGCH from PCU; check it appears on Um side */
4840testcase TC_pcu_data_req_pch() runs on test_CT {
4841 timer T := 3.0;
4842 f_init_pcu_test();
4843 f_init_l1ctl();
4844 f_l1_tune(L1CTL);
4845
4846 f_TC_pcu_act_req(0, 0, 7, true);
4847 /* three characters prefix: last 3 digits of IMSI as ASCII */
4848 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4849
4850 T.start;
4851 alt {
4852 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4853 setverdict(pass);
4854 }
4855 [] L1CTL.receive { repeat; }
4856 [] T.timeout {
4857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4858 }
4859 }
4860}
4861
Harald Welte883340c2018-02-28 18:59:29 +01004862/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4863testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4864 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004865 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004866 f_init_l1ctl();
4867 f_l1_tune(L1CTL);
4868
4869 /* append 3 last imsi digits so BTS can compute pagng group */
4870 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4871
4872 timer T := 0.5;
4873 T.start;
4874 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004875 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004876 /* TODO: verify paging group */
4877 setverdict(pass);
4878 }
4879 [] L1CTL.receive { repeat; }
4880 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004882 }
4883 }
4884}
4885
4886/* Send RACH from Um side, expect it to show up on PCU socket */
4887testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004888 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004889 f_init_l1ctl();
4890 f_l1_tune(L1CTL);
4891
4892 var GsmFrameNumber fn_last := 0;
4893 for (var integer i := 0; i < 1000; i := i+1) {
4894 var OCT1 ra := f_rnd_ra_ps();
4895 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4896 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004898 }
4899 fn_last := fn;
4900
4901 timer T := 2.0;
4902 T.start;
4903 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004904 [] 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 +01004905 T.stop;
4906 }
4907 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004908 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004909 }
4910 [] PCU.receive { repeat; }
4911 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004912 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004913 }
4914 }
4915 }
4916 setverdict(pass);
4917}
4918
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004919/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4920 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4921testcase TC_pcu_ext_rach_content() runs on test_CT {
4922 var template PCUIF_Message pcu_rach_ind;
4923 var GsmFrameNumber fn_last := 0;
4924 var L1ctlRachSynchSeq synch_seq;
4925 var PCUIF_BurstType pcu_bt;
4926 var GsmFrameNumber fn;
4927 var BIT11 ra11;
4928
4929 f_init_pcu_test();
4930 f_init_l1ctl();
4931 f_l1_tune(L1CTL);
4932
4933 for (var integer i := 0; i < 1000; i := i+1) {
4934 /* We need to test both TS1 & TS2 */
4935 if (i rem 2 == 0) {
4936 synch_seq := RACH_SYNCH_SEQ_TS1;
4937 pcu_bt := BURST_TYPE_1;
4938 } else {
4939 synch_seq := RACH_SYNCH_SEQ_TS2;
4940 pcu_bt := BURST_TYPE_2;
4941 }
4942
4943 ra11 := f_rnd_ra11_ps();
4944 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4945 if (fn == fn_last) {
4946 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4947 "Two RACH in same FN?!?");
4948 }
4949 fn_last := fn;
4950
4951 /* Compose the expected message */
4952 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004953 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004954 ra := bit2int(ra11),
4955 is_11bit := 1,
4956 burst_type := pcu_bt,
4957 fn := fn);
4958
4959 timer T := 2.0;
4960 T.start;
4961 alt {
4962 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4963 T.stop;
4964 }
4965 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4967 }
4968 [] PCU.receive { repeat; }
4969 [] T.timeout {
4970 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4971 }
4972 }
4973 }
4974 setverdict(pass);
4975}
4976
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004977private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4978runs on test_CT {
4979 var template PCUIF_send_data sdt;
4980 var PCUIF_send_data sd;
4981 var int16_t lqual_cb;
4982 timer T := 1.0;
4983
4984 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4985 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4986
4987 /* Send a random PDTCH frame over Um */
4988 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4989 '0000'O & f_rnd_octstring(21)));
4990
4991 T.start;
4992 alt {
4993 /* If expected link quality is above the threshold */
4994 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4995 lqual_cb := sd.data.u.data_ind.lqual_cb;
4996 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4997
4998 /* Make sure the actual link quality matches the expected value */
4999 if (not match(lqual_cb, lqual_cb_exp)) {
5000 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5001 "expected value ", lqual_cb_exp));
5002 } else {
5003 setverdict(pass);
5004 }
5005 }
5006 /* If expected link quality is below the threshold */
5007 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5009 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5010 }
5011 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5012 [] PCU.receive { repeat; }
5013 [lqual_cb_exp < thresh] T.timeout {
5014 log("Rx nothing, as expected");
5015 setverdict(pass);
5016 }
5017 [lqual_cb_exp >= thresh] T.timeout {
5018 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5019 "Timeout waiting for PCUIF_DATA.ind");
5020 }
5021 }
5022}
5023
5024/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5025testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
5026 f_init_pcu_test();
5027 PCU.clear;
5028
5029 f_init_l1ctl();
5030 f_l1_tune(L1CTL);
5031
5032 /* Activate a PDCH channel on TS7 */
5033 f_TC_pcu_act_req(0, 0, 7, true);
5034
5035 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005036 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005037 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005038 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005039 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005040
5041 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5042 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5043 var TrxcMessage ret;
5044
5045 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5046 valueof(ts_TRXC_FAKE_CI(i)));
5047
5048 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5049 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5050 }
5051}
5052
Harald Welte883340c2018-02-28 18:59:29 +01005053/* Send PAGING via RSL, expect it to shw up on PCU socket */
5054testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005055 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01005056
5057 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005058 var MobileIdentityLV mi_lv;
5059 var octetstring mi_lv_enc;
5060 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005061 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005062
Harald Welte883340c2018-02-28 18:59:29 +01005063 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005064 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005065 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005066 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005067 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005068
5069 /* Fancy encoding for PCUIF */
5070 mi_lv := valueof(ts_MI_LV(mi));
5071 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5072 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005073
5074 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005075 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005076 T.start;
5077 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005078 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005079 }
5080 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005081 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005082 }
5083 [] PCU.receive { repeat; }
5084 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005085 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005086 }
5087 }
5088 }
5089 setverdict(pass);
5090}
5091
Harald Welted66c9b82019-05-25 09:03:15 +02005092/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5093testcase TC_pcu_time_ind() runs on test_CT {
5094 var PCUIF_send_data pcu_sd;
5095 var integer num_time_ind := 0;
5096 var integer first_fn, last_fn;
5097 var float test_duration := 5.0;
5098 timer T;
5099
5100 f_init_pcu_test();
5101 f_TC_pcu_act_req(0, 0, 7, true);
5102
5103 PCU.clear;
5104 T.start(test_duration);
5105 alt {
5106 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5107 num_time_ind := num_time_ind + 1;
5108 if (not isbound(first_fn)) {
5109 first_fn := pcu_sd.data.u.time_ind.fn;
5110 }
5111 last_fn := pcu_sd.data.u.time_ind.fn;
5112 repeat;
5113 }
5114 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5115 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5116 repeat;
5117 }
5118 [] PCU.receive {
5119 repeat;
5120 }
5121 [] T.timeout {}
5122 }
5123 var integer fn_expired := last_fn - first_fn;
5124 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5125
5126 /* verify the number of frames expired matches our expectation */
5127 const float c_GSM_FN_DURATION_MS := 4.61538;
5128 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005129 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005130 if (not match(fn_expired, t_fn_expected)) {
5131 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5132 }
5133
5134 /* There are three TIME.ind in every fn MOD 13 */
5135 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5136 /* Add some tolerance */
5137 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5138 if (not match(num_time_ind, t_time_ind_exp)) {
5139 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5140 }
5141
5142 setverdict(pass);
5143}
5144
Harald Welte4832c862019-05-25 14:57:18 +02005145/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5146testcase TC_pcu_rts_req() runs on test_CT {
5147 var PCUIF_send_data pcu_sd;
5148 var integer first_fn, last_fn;
5149 var integer num_rts_pdtch := 0;
5150 var integer num_rts_ptcch := 0;
5151 var float test_duration := 5.0;
5152 timer T;
5153
5154 f_init_pcu_test();
5155 f_TC_pcu_act_req(0, 0, 7, true);
5156
5157 PCU.clear;
5158 T.start(test_duration);
5159 alt {
5160 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5161 -> value pcu_sd {
5162 num_rts_pdtch := num_rts_pdtch + 1;
5163 if (not isbound(first_fn)) {
5164 first_fn := pcu_sd.data.u.rts_req.fn;
5165 }
5166 last_fn := pcu_sd.data.u.rts_req.fn;
5167 repeat;
5168 }
5169 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5170 -> value pcu_sd {
5171 num_rts_ptcch := num_rts_ptcch + 1;
5172 if (not isbound(first_fn)) {
5173 first_fn := pcu_sd.data.u.rts_req.fn;
5174 }
5175 last_fn := pcu_sd.data.u.rts_req.fn;
5176 repeat;
5177 }
5178 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5179 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5180 repeat;
5181 }
5182 [] PCU.receive {
5183 repeat;
5184 }
5185 [] T.timeout {}
5186 }
5187 var integer fn_expired := last_fn - first_fn;
5188 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5189 ", num_rts_ptcch=", num_rts_ptcch);
5190
5191 /* verify the number of frames expired matches our expectation */
5192 const float c_GSM_FN_DURATION_MS := 4.61538;
5193 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005194 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005195 if (not match(fn_expired, t_fn_expected)) {
5196 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5197 }
5198
5199 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5200 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5201 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5202 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5203 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5204 t_ptcch_exp);
5205 }
5206
5207 /* We have 12 PDTCH blocks every 52-multiframe */
5208 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5209 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5210 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5211 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5212 t_pdtch_exp);
5213 }
5214
5215 setverdict(pass);
5216}
5217
Harald Welte07bd2d22019-05-25 11:03:30 +02005218/* test for generating Abis side OML ALERT from the PCU */
5219testcase TC_pcu_oml_alert() runs on test_CT {
5220 var PCUIF_send_data pcu_sd;
5221 var integer num_time_ind := 0;
5222 var integer first_fn, last_fn;
5223 var float test_duration := 5.0;
5224 timer T;
5225
5226 f_init_pcu_test();
5227 f_TC_pcu_act_req(0, 0, 7, true);
5228
5229 /* re-connect CTRL port from BTS to BSC */
5230 f_ipa_ctrl_stop();
5231 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5232
5233 /* Send that OML Alert */
5234 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5235
5236 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5237 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5238 setverdict(pass);
5239}
5240
Harald Welteeaa9a862019-05-26 23:01:08 +02005241/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5242private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5243 var PCUIF_Message first_info;
5244 var integer pcu_conn_id := -1;
5245 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5246 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5247 var OCT4 tlli := '01020304'O;
5248 var OCT1 cause := '23'O;
5249 timer T := 5.0;
5250
5251 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5252
5253 f_l1_tune(L1CTL);
5254 RSL.clear;
5255
5256 f_est_dchan();
5257 L1CTL.clear;
5258
5259 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5260
5261 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5262 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5263 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5264
5265 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5266 T.start;
5267 alt {
5268 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5269 setverdict(pass);
5270 }
5271 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5272 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5273 }
5274 [] PCU.receive {
5275 repeat;
5276 }
5277 [] T.timeout {
5278 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5279 }
5280 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005281
5282 /* release the channel */
5283 f_rsl_chan_deact();
5284 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5285 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005286}
5287testcase TC_pcu_rr_suspend() runs on test_CT {
5288 var ConnHdlrPars pars;
5289 var ConnHdlr vc_conn;
5290
5291 f_init();
5292
5293 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5294 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5295 vc_conn.done;
5296}
Harald Welte07bd2d22019-05-25 11:03:30 +02005297
Harald Weltea2e0e942019-05-27 18:12:53 +02005298/* Ensure that PCUIF socket can accept only a single connection */
5299testcase TC_pcu_socket_connect_multi() runs on test_CT {
5300 timer T := 5.0;
5301
5302 /* this (among other things) establishes the first connection to the PCUIF socket */
5303 f_init();
5304
5305 /* try to establish a second connection, expect it to fail */
5306 PCU.send(UD_connect:{mp_pcu_socket, -1});
5307 T.start;
5308 alt {
5309 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5310 setverdict(pass);
5311 }
5312 [] PCU.receive(UD_connect_result:?) {
5313 setverdict(fail, "Unexpected unix domain connect result");
5314 }
5315 [] T.timeout {
5316 setverdict(pass);
5317 }
5318 }
5319 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5320}
5321
Harald Weltec8effb72019-05-27 18:23:04 +02005322/* Ensure that PCUIF socket can disconnect + reconnect */
5323testcase TC_pcu_socket_reconnect() runs on test_CT {
5324 /* this (among other things) establishes the first connection to the PCUIF socket */
5325 f_init();
5326
5327 f_sleep(1.0);
5328
5329 f_pcuif_close(PCU, g_pcu_conn_id);
5330 g_pcu_conn_id := -1;
5331
5332 f_sleep(1.0);
5333
5334 /* re-connect */
5335 PCU.clear;
5336 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5337 setverdict(pass);
5338
5339 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5340}
5341
Harald Weltebe030482019-05-27 22:29:35 +02005342/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005343private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5344runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005345 var L1ctlDlMessage l1_dl;
5346 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005347 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005348 timer T := 5.0;
5349 T.start;
5350 alt {
5351 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005352 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5353 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005354 repeat;
5355 }
5356 }
5357 [] pt.receive {
5358 repeat;
5359 }
5360 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5362 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005363 }
5364 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005365 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005366}
5367
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005368/* Check if GPRS Indicator is present in RR System Information of a given type */
5369private function f_si_has_gprs_indicator(RrMessageType si_type)
5370runs on test_CT return boolean {
5371 var SystemInformation si := f_get_si(L1CTL, si_type);
5372
5373 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005374 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005375 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005376 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005377 }
5378
5379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5380 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005381}
5382
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005383/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5384private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5385runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005386 /* don't call f_init() as this would connect PCU socket */
5387 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005388
5389 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005390 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005391 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005392
5393 f_init_l1ctl();
5394 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005395 f_sleep(2.0);
5396 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005397
5398 if (f_si_has_gprs_indicator(si_type)) {
5399 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005400 } else {
5401 setverdict(pass);
5402 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005403
Harald Weltebe030482019-05-27 22:29:35 +02005404 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5405}
5406
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005407testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5408 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5409}
Harald Weltebe030482019-05-27 22:29:35 +02005410
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005411testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5412 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5413}
5414
5415/* Ensure that GPRS capability is advertised after PCU socket connect */
5416private function f_TC_pcu_socket_connect(RrMessageType si_type)
5417runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005418 /* this (among other things) establishes the first connection to the PCUIF socket */
5419 f_init();
5420 f_init_l1ctl();
5421 f_l1_tune(L1CTL);
5422
5423 f_sleep(2.0);
5424 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005425
5426 if (not f_si_has_gprs_indicator(si_type)) {
5427 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005428 } else {
5429 setverdict(pass);
5430 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005431
Harald Weltebe030482019-05-27 22:29:35 +02005432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5433}
5434
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005435testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5436 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5437}
Harald Weltebe030482019-05-27 22:29:35 +02005438
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005439testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5440 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5441}
5442
5443/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5444private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5445runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005446 /* this (among other things) establishes the first connection to the PCUIF socket */
5447 f_init();
5448 f_init_l1ctl();
5449 f_l1_tune(L1CTL);
5450
5451 f_pcuif_close(PCU, g_pcu_conn_id);
5452 g_pcu_conn_id := -1;
5453
5454 f_sleep(1.0);
5455
5456 /* re-connect */
5457 PCU.clear;
5458 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5459
5460 f_sleep(2.0);
5461 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005462
5463 if (f_si_has_gprs_indicator(si_type)) {
5464 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005465 } else {
5466 setverdict(pass);
5467 }
5468
5469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5470}
5471
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005472testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5473 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5474}
5475
5476testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5477 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5478}
5479
Oliver Smithf5239c72019-08-28 10:01:25 +02005480/* 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) */
5481testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5482 var SystemInformation si3 := valueof(ts_SI3_default);
5483
5484 f_init();
5485
Harald Welte76220222020-10-11 20:32:44 +02005486 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5487 * information */
5488 timer T := 2.0;
5489 T.start;
5490 alt {
5491 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5492 [] T.timeout {}
5493 }
5494
Oliver Smithf5239c72019-08-28 10:01:25 +02005495 /* Verify cell_id */
5496 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5497 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5498 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005499 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5500 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5501 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005502 }
5503
5504 /* Verify LAC */
5505 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5506 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5507 if (lac_si3 != lac_pcu) {
5508 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5509 }
5510
5511 setverdict(pass);
5512}
Harald Welted66c9b82019-05-25 09:03:15 +02005513
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005514/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5515testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5516 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005517 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005518
5519 f_init();
5520
5521 info_ind := g_pcu_last_info.u.info_ind;
5522
5523 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5524 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5525 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5526 /* Skip inactive timeslots */
5527 continue;
5528 }
5529
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005530 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005531 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005532 else
5533 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005534
5535 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005536 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005537 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005538 hsn := fhp.maio_hsn.hsn,
5539 maio := fhp.maio_hsn.maio,
5540 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005541 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005542 } else {
5543 tr_ts := tr_PCUIF_InfoTrxTsH0;
5544 }
5545
5546 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5547 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5548 if (not match(ts, tr_ts)) {
5549 setverdict(fail, "Hopping parameters do not match: ",
5550 "received ", ts, " vs expected ", tr_ts);
5551 } else {
5552 setverdict(pass);
5553 }
5554 }
5555 }
5556}
5557
Alexander Couzens5283f552020-07-28 15:39:04 +02005558/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5559testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5560 f_init_vty_bsc();
5561 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5562 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5563
5564 f_init();
5565
5566 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5567 if (not ischosen(remote_addr.v10)) {
5568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5569 log2str("Unexpected remote_addr: ", remote_addr));
5570 }
5571
5572 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5573 setverdict(fail, "Received address family is not IPv4");
5574 }
5575
5576 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5577 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5578 }
5579
5580 setverdict(pass);
5581}
5582
5583/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5584testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5585 f_init_vty_bsc();
5586 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5587
5588 f_init();
5589
5590 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5591 if (not ischosen(remote_addr.v10)) {
5592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5593 log2str("Unexpected remote_addr: ", remote_addr));
5594 }
5595
5596 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5597 setverdict(fail, "Received address family is not IPv6");
5598 }
5599
5600 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5601 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5602 }
5603
5604 setverdict(pass);
5605}
5606
Harald Welte3d04ae62018-04-04 20:29:05 +02005607/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005608 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005609 ***********************************************************************/
5610
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005611private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5612 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005613runs on ConnHdlr {
5614 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005615
5616 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005617 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005618 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5619 repeat;
5620 }
5621 }
5622}
5623
5624private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5625runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005626 /* Expect BTS to immediately acknowledge activation as PDCH */
5627 PCU.clear;
5628 f_rsl_chan_act(g_pars.chan_mode);
5629 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005630 timer T_wait := 2.0;
5631 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005632 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005633 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005634 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005635 [] T_wait.timeout {
5636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5637 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5638 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005639 }
5640 /* try to activate this PDCH from the PCU point of view */
5641 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5642 /* FIXME: is there a response? */
5643}
5644
5645private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5646runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005647 /* Send RSL CHAN REL (deactivate) */
5648 PCU.clear;
5649 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5650 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005651 timer T_wait := 2.0;
5652 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005653 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005654 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005655 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005656 [] T_wait.timeout {
5657 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5658 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5659 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005660 }
5661 /* Emulate PCU asking BTS to deactivate PDCH */
5662 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5663 alt {
5664 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5665 setverdict(pass);
5666 }
5667 [] RSL.receive { repeat; }
5668 }
5669}
5670
5671/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005672private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005673 var PCUIF_Message first_info;
5674 var integer ts_nr := g_chan_nr.tn;
5675 var integer trx_nr := 0;
5676 var integer bts_nr := 0;
5677 var integer pcu_conn_id := -1;
5678
5679 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5680
5681 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5682 f_sleep(3.0);
5683 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5684 setverdict(pass);
5685}
5686testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5687 var ConnHdlrPars pars;
5688 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005689 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005690
5691 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5692 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5693 vc_conn.done;
5694}
5695
5696/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005697private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005698 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005699 var integer pcu_conn_id := -1;
5700
5701 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5702
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005703 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5704 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5705 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005706 setverdict(pass);
5707}
5708testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5709 var ConnHdlrPars pars;
5710 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005711 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005712
5713 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5714 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5715 vc_conn.done;
5716}
5717
5718/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005719private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005720 var PCUIF_Message first_info;
5721 var integer ts_nr := g_chan_nr.tn;
5722 var integer trx_nr := 0;
5723 var integer bts_nr := 0;
5724 var integer pcu_conn_id := -1;
5725
5726 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5727
5728 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005729 /* Send a second Chan Activ and expect it to be NACKed */
5730 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5731 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005732 setverdict(pass);
5733}
5734testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5735 var ConnHdlrPars pars;
5736 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005737 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005738
5739 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5740 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5741 vc_conn.done;
5742}
5743
5744/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005745private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005746 var PCUIF_Message first_info;
5747 var integer ts_nr := g_chan_nr.tn;
5748 var integer trx_nr := 0;
5749 var integer bts_nr := 0;
5750 var integer pcu_conn_id := -1;
5751 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5752
5753 /* register for the TCH/F channel number */
5754 f_rslem_register(0, chan_nr);
5755
5756 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5757
5758 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5759 "RSL CHAN ACT");
5760 setverdict(pass);
5761}
5762testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5763 var ConnHdlrPars pars;
5764 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005765 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005766
5767 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5768 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5769 vc_conn.done;
5770}
5771
5772/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005773private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005774 var PCUIF_Message first_info;
5775 var integer ts_nr := g_chan_nr.tn;
5776 var integer trx_nr := 0;
5777 var integer bts_nr := 0;
5778 var integer pcu_conn_id := -1;
5779 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5780 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5781
5782 /* register for the TCH/H channel numbers */
5783 f_rslem_register(0, chan_nr[0]);
5784 f_rslem_register(0, chan_nr[1]);
5785
5786 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5787
5788 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5789 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5790 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5791 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5792 setverdict(pass);
5793}
5794testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5795 var ConnHdlrPars pars;
5796 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005797 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005798
5799 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5800 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5801 vc_conn.done;
5802}
5803
Harald Welte9bbbfb52018-04-05 09:33:19 +02005804/***********************************************************************
5805 * IPA Style Dynamic Timeslot Support
5806 ***********************************************************************/
5807
5808private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5809runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005810 /* Expect BTS to immediately acknowledge activation as PDCH */
5811 PCU.clear;
5812 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5813 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005814 timer T_wait := 2.0;
5815 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005816 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005817 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005818 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005819 [] T_wait.timeout {
5820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5821 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5822 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005823 }
5824 /* try to activate this PDCH from the PCU point of view */
5825 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5826 /* FIXME: is there a response? */
5827
5828 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5829}
5830
5831private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5832runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005833 /* Send RSL CHAN REL (deactivate) */
5834 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5835 PCU.clear;
5836 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005837 timer T_wait := 2.0;
5838 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005839 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005840 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005841 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005842 [] T_wait.timeout {
5843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5844 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5845 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005846 }
5847 /* Emulate PCU asking BTS to deactivate PDCH */
5848 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5849 alt {
5850 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5851 setverdict(pass);
5852 }
5853 [] RSL.receive { repeat; }
5854 }
5855}
5856
5857/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005858private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005859 var PCUIF_Message first_info;
5860 var integer ts_nr := g_chan_nr.tn;
5861 var integer trx_nr := 0;
5862 var integer bts_nr := 0;
5863 var integer pcu_conn_id := -1;
5864
5865 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5866
5867 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5868 f_sleep(3.0);
5869 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5870
5871 setverdict(pass);
5872
5873}
5874testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5875 var ConnHdlrPars pars;
5876 var ConnHdlr vc_conn;
5877 f_init();
5878
5879 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5880 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5881 vc_conn.done;
5882}
5883
5884/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005885private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005886 var PCUIF_Message first_info;
5887 var integer ts_nr := g_chan_nr.tn;
5888 var integer trx_nr := 0;
5889 var integer bts_nr := 0;
5890 var integer pcu_conn_id := -1;
5891
5892 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5893
5894 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5895 "RSL CHAN ACT");
5896 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5897 "RF CHAN REL", true);
5898 setverdict(pass);
5899}
5900testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5901 var ConnHdlrPars pars;
5902 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005903 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005904
5905 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5906 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5907 vc_conn.done;
5908}
5909
5910/* 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 +07005911private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005912 var PCUIF_Message first_info;
5913 var integer ts_nr := g_chan_nr.tn;
5914 var integer trx_nr := 0;
5915 var integer bts_nr := 0;
5916 var integer pcu_conn_id := -1;
5917
5918 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5919
5920 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5921 "RSL CHAN ACT");
5922
5923 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5924 alt {
5925 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5926 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005927 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005928 }
5929 [] RSL.receive { repeat; }
5930 }
5931
5932 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5933 "RF CHAN REL", true);
5934 setverdict(pass);
5935}
5936testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5937 var ConnHdlrPars pars;
5938 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005939 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005940
5941 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5942 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5943 vc_conn.done;
5944}
5945
5946/* 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 +07005947private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005948 var PCUIF_Message first_info;
5949 var integer ts_nr := g_chan_nr.tn;
5950 var integer trx_nr := 0;
5951 var integer bts_nr := 0;
5952 var integer pcu_conn_id := -1;
5953
5954 /* register for the TCH/F channel number */
5955 f_rslem_register(0, g_chan_nr);
5956
5957 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5958
5959 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5960
5961 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5962 "RSL CHAN ACT");
5963
5964 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5965
5966 setverdict(pass);
5967}
5968testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5969 var ConnHdlrPars pars;
5970 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005971 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005972
5973 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5974 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5975 vc_conn.done;
5976}
5977
5978
Harald Welte0472ab42018-03-12 15:02:26 +01005979/***********************************************************************
5980 * LAPDm / RLL related
5981 ***********************************************************************/
5982
5983private function f_tx_lapdm(template (value) LapdmFrame l,
5984 template (value) RslLinkId link_id) runs on ConnHdlr {
5985 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005986 var template (value) SacchL1Header l1h;
5987
5988 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005989 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005990 /* Compose dummy L1 header */
5991 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5992 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 +02005993 } else {
5994 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005995 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 +01005996 }
Harald Welte0472ab42018-03-12 15:02:26 +01005997}
5998
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005999private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006000 uint3_t sapi,
6001 RslLinkId link_id,
6002 octetstring l3,
6003 boolean exp
6004}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006005private type record of RllTestCase RllTestCases;
6006private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
6007 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006008 sapi := sapi,
6009 link_id := id,
6010 l3 := l3,
6011 exp := exp
6012}
6013
6014/* execute the same callback function with a set of different parameters (tcs) on a
6015 * variety of logical channels */
6016private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6017 var ConnHdlrPars pars;
6018 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006019 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006020
6021 /* test on each of the channels we have */
6022 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6023 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6024
6025 /* test each of the test cases on the current channel */
6026 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6027 pars.spec.rll := tcs[j];
6028 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6029 vc_conn := f_start_handler(fn, pars);
6030 vc_conn.done;
6031 }
6032 }
6033
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006035}
6036
6037/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6038private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6039 var RllTestCase tc := g_pars.spec.rll;
6040 timer T := 3.0;
6041
6042 f_l1_tune(L1CTL);
6043 RSL.clear;
6044
6045 /* activate the logical channel */
6046 f_est_dchan();
6047 L1CTL.clear;
6048
6049 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6050 T.start;
6051 alt {
6052 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6053 if (tc.exp) {
6054 setverdict(pass);
6055 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006057 }
6058 }
6059 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6060 if (tc.exp) {
6061 setverdict(pass);
6062 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006063 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006064 }
6065 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006066 /* We also expect to receive the measurements */
6067 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006068 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006069 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006070 }
6071 [not tc.exp] T.timeout {
6072 setverdict(pass);
6073 }
6074 }
6075
6076 f_rsl_chan_deact();
6077 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6078 f_rslem_unregister(0, g_chan_nr);
6079}
6080testcase TC_rll_est_ind() runs on test_CT {
6081 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006082 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006083 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006084 /* normal SAPI0 establishment */
6085 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006086 /* SAPI 3 doesn't support contention resolution */
6087 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6088 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6089 /* normal SAPI3 establishment on main DCCH */
6090 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6091 /* normal SAPI3 establishment on SACCH */
6092 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6093 };
6094 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6095}
6096
6097/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6098private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6099 var RllTestCase tc := g_pars.spec.rll;
6100 var L1ctlDlMessage dl;
6101 timer T := 3.0;
6102
6103 f_l1_tune(L1CTL);
6104 RSL.clear;
6105
6106 /* activate the logical channel */
6107 f_est_dchan();
6108 L1CTL.clear;
6109
6110 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6111 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6112 T.start;
6113 alt {
6114 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6115 var LapdmFrame lapdm;
6116 var octetstring l2 := dl.payload.data_ind.payload;
6117 if (dl.dl_info.link_id.c == SACCH) {
6118 /* remove L1 header */
6119 l2 := substr(l2, 2, lengthof(l2)-2);
6120 }
6121 lapdm.ab := dec_LapdmFrameAB(l2);
6122 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6123 setverdict(pass);
6124 } else {
6125 repeat;
6126 }
6127 }
6128 [] L1CTL.receive { repeat; }
6129 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006130 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006131 }
6132 }
6133
6134 f_rsl_chan_deact();
6135 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6136 f_rslem_unregister(0, g_chan_nr);
6137}
6138testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6139 var RllTestCases tcs := {
6140 /* normal SAPI3 establishment on main DCCH */
6141 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6142 };
6143 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6144}
6145testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6146 var RllTestCases tcs := {
6147 /* normal SAPI3 establishment on SACCH */
6148 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6149 }
6150 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6151}
6152
6153/* altstep to receive a LAPDm frame matching the given template */
6154private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6155 var L1ctlDlMessage dl;
6156 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6157 var LapdmFrame lapdm;
6158 var octetstring l2 := dl.payload.data_ind.payload;
6159 if (dl.dl_info.link_id.c == SACCH) {
6160 /* remove L1 header */
6161 l2 := substr(l2, 2, lengthof(l2)-2);
6162 }
6163 if (ischosen(exp.ab)) {
6164 lapdm.ab := dec_LapdmFrameAB(l2);
6165 } else if (ischosen(exp.b4)) {
6166 lapdm.b4 := dec_LapdmFrameB4(l2);
6167 } else if (ischosen(exp.bbis)) {
6168 lapdm.bbis := dec_LapdmFrameBbis(l2);
6169 }
6170 log("Rx LAPDm ", lapdm);
6171 if (match(lapdm, exp)) {
6172 setverdict(pass);
6173 } else {
6174 repeat;
6175 }
6176 }
6177 [] L1CTL.receive { repeat; }
6178}
6179private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6180 timer T := t;
6181 T.start;
6182 alt {
6183 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006184 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006185 }
6186 [] as_l1_exp_lapdm(exp);
6187 }
6188}
6189
6190/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6191private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6192 /* send SABM from MS -> BTS */
6193 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6194 /* expect RLL EST IND on Abis */
6195 alt {
6196 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6197 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6198 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006200 }
6201 [] RSL.receive { repeat; }
6202 }
6203 /* expect UA from BTS -> MS */
6204 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6205}
6206
6207/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6208private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6209 var RllTestCase tc := g_pars.spec.rll;
6210
6211 f_l1_tune(L1CTL);
6212 RSL.clear;
6213
6214 /* activate the logical channel */
6215 f_est_dchan();
6216 L1CTL.clear;
6217
6218 /* first establish the link-layer */
6219 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6220
6221 /* then send the DISC */
6222 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6223 /* ... and expect the REL IND on the RSL side */
6224 alt {
6225 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6226 setverdict(pass);
6227 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006228 /* We also expect to receive the measurements */
6229 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006230 }
6231
6232 /* release the channel */
6233 f_rsl_chan_deact();
6234 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6235 f_rslem_unregister(0, g_chan_nr);
6236}
6237testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6238 var RllTestCases tcs := {
6239 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6240 };
6241 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6242}
6243
6244testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6245 var RllTestCases tcs := {
6246 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6247 };
6248 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6249}
6250testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6251 var RllTestCases tcs := {
6252 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6253 };
6254 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6255}
6256testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6257 var RllTestCases tcs := {
6258 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6259 };
6260 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6261}
6262
6263/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6264private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6265 var RllTestCase tc := g_pars.spec.rll;
6266 f_l1_tune(L1CTL);
6267 RSL.clear;
6268
6269 /* activate the logical channel */
6270 f_est_dchan();
6271 L1CTL.clear;
6272
6273 /* first establish the link-layer */
6274 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6275
6276 /* then send the REL REQ via RSL */
6277 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6278 /* ... and expect the DISC on the Um side */
6279 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006280 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006281 /* FIXME: send a UA in resposne to the DISC */
6282 }
6283 }
6284
6285 /* release the channel */
6286 f_rsl_chan_deact();
6287 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6288 f_rslem_unregister(0, g_chan_nr);
6289}
6290testcase TC_rll_rel_req() runs on test_CT {
6291 var RllTestCases tcs := {
6292 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6293 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6294 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6295 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6296 };
6297 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6298}
6299
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006300/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006301testcase TC_rll_data_req() runs on test_CT {
6302}
6303
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006304/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006305testcase TC_rll_data_ind() runs on test_CT {
6306}
6307
6308/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6309private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6310 var RllTestCase tc := g_pars.spec.rll;
6311
6312 f_l1_tune(L1CTL);
6313 RSL.clear;
6314
6315 f_est_dchan();
6316 L1CTL.clear;
6317
6318 /* Send UNITDATA REQ on RSL side */
6319 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6320 /* Expect it to arrive on the other side */
6321 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006322 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006323 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006324 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006325 }
6326
6327 /* release the channel */
6328 f_rsl_chan_deact();
6329 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6330 f_rslem_unregister(0, g_chan_nr);
6331}
6332testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6333 var octetstring l3 := f_rnd_octstring(15);
6334 var RllTestCases tcs := {
6335 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6336 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6337 };
6338 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6339}
6340testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6341 var octetstring l3 := f_rnd_octstring(19);
6342 var RllTestCases tcs := {
6343 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6344 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6345 };
6346 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6347}
6348
6349/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6350private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6351 var RllTestCase tc := g_pars.spec.rll;
6352
6353 f_l1_tune(L1CTL);
6354 RSL.clear;
6355
6356 f_est_dchan();
6357 L1CTL.clear;
6358
6359 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006360 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006361 /* Expdct RLL UNITDATA IND on RSL side */
6362 alt {
6363 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6364 setverdict(pass);
6365 }
6366 [] RSL.receive { repeat; }
6367 }
6368
6369 /* release the channel */
6370 f_rsl_chan_deact();
6371 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6372 f_rslem_unregister(0, g_chan_nr);
6373}
6374testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006375 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006376 var RllTestCases tcs := {
6377 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6378 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6379 };
6380 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6381}
6382testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6383 var octetstring l3 := f_rnd_octstring(18);
6384 var RllTestCases tcs := {
6385 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6386 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6387 };
6388 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6389}
6390
Harald Weltee613f962018-04-18 22:38:16 +02006391/***********************************************************************
6392 * Encryption Related
6393 ***********************************************************************/
6394
6395/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006396private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006397 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6398 if (link_id.c == SACCH) {
6399 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6400 } else {
6401 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6402 }
6403}
6404
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006405/* Expect (or not expect) other kinds of messages */
6406private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6407 [exp_any] RSL.receive { repeat; }
6408 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006410 }
6411}
6412
Harald Weltee613f962018-04-18 22:38:16 +02006413/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006414private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006415 RslLinkId link_id,
6416 octetstring l3,
6417 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006418 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006419) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006420 timer T := 3.0;
6421 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6422 T.start;
6423 /* Expect RLL UNITDATA IND on RSL side */
6424 alt {
6425 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6426 setverdict(pass);
6427 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006428 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006429 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006430 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006431 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006432 }
Harald Weltee613f962018-04-18 22:38:16 +02006433 }
6434}
6435
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006436/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6437private function f_data_mo(
6438 RslLinkId link_id,
6439 boolean p, uint3_t nr, uint3_t ns,
6440 octetstring l3,
6441 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006442 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006443) runs on ConnHdlr {
6444 timer T := 3.0;
6445 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6446 T.start;
6447 /* Expect RLL DATA IND on RSL side */
6448 alt {
6449 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6450 setverdict(pass);
6451 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006452 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006453 [] as_rsl_any_ind(exp_any);
6454 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006456 }
6457 }
6458}
6459
Harald Weltee613f962018-04-18 22:38:16 +02006460/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006461private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006462 f_l1_tune(L1CTL);
6463 f_est_dchan(true);
6464
6465 /* now we actually need to transmit some data both ways to check if the encryption works */
6466 var L1ctlDlMessage dl;
6467
Stefan Sperling603d98e2018-07-25 16:47:28 +02006468 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006469 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6470
6471 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6472 f_unitdata_mt(link_id, l3);
6473
6474 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6475 f_unitdata_mo(link_id, l3);
6476
6477 /* release the channel */
6478 f_rsl_chan_deact();
6479 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6480 f_rslem_unregister(0, g_chan_nr);
6481}
6482testcase TC_chan_act_a51() runs on test_CT {
6483 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6484 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6485 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6486}
6487testcase TC_chan_act_a52() runs on test_CT {
6488 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6489 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6490 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6491}
6492testcase TC_chan_act_a53() runs on test_CT {
6493 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6494 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6495 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6496}
6497
Eric Wildf1827a72019-05-28 17:37:35 +02006498/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6499 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 +07006500private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006501 f_l1_tune(L1CTL);
6502 f_est_dchan(true);
6503
6504 /* now we actually need to transmit some data both ways to check if the encryption works */
6505 var L1ctlDlMessage dl;
6506
6507 var octetstring l3 := f_rnd_octstring(20);
6508 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6509
6510 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6511 f_unitdata_mt(link_id, l3);
6512
6513 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6514 f_unitdata_mo(link_id, l3);
6515
6516 var RSL_Message rsl;
6517 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6518
6519 /* modify key to break proper encryption */
6520 g_pars.encr.key := f_rnd_octstring(8);
6521 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6522 rsl.ies := rsl.ies & { ei };
6523 RSL.send(rsl);
6524
6525 timer T0 := 1.0;
6526 T0.start;
6527 /* Expect RSL MODIFY ACK */
6528 alt {
6529 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6530 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6531 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6532 }
6533 [] T0.timeout {
6534 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6535 }
6536 }
6537
6538 var octetstring l3msg := f_rnd_octstring(15);
6539 timer T1 := 3.0;
6540 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6541 due to broken encryption */
6542 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6543 T1.start;
6544 alt {
6545 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6546 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6547 }
6548 [] T1.timeout {
6549 setverdict(pass);
6550 }
6551 }
6552
6553 /* release the channel */
6554 f_rsl_chan_deact();
6555 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6556 f_rslem_unregister(0, g_chan_nr);
6557}
6558testcase TC_rsl_modify_encr() runs on test_CT {
6559 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6560 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6561 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6562}
Harald Weltee613f962018-04-18 22:38:16 +02006563
6564/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006565private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006566 /* L3 payload doesn't matter, as it is passed transparently */
6567 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6568 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6569 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6570
6571 f_l1_tune(L1CTL);
6572
6573 /* first establish a dedicated channel in the clear */
6574 f_est_dchan(false);
6575
6576 /* Establish ABM */
6577 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6578
6579 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6580 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6581 /* expect the L3 to arrive still unencrypted on the MS side */
6582 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6583
6584 /* configure L1 to apply ciphering */
6585 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6586 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6587
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006588 /* send first ciphered I-frame in response and expect it on RSL */
6589 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006590
6591 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6592 * and hence enable encryption also on the downlink */
6593
6594 /* expect bi-directional communication work in encrypted mode */
6595 f_unitdata_mo(link_id, f_rnd_octstring(15));
6596 f_unitdata_mt(link_id, f_rnd_octstring(15));
6597
6598 /* release the channel */
6599 f_rsl_chan_deact();
6600 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6601 f_rslem_unregister(0, g_chan_nr);
6602}
6603testcase TC_encr_cmd_a51() runs on test_CT {
6604 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6605 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6606 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6607}
6608testcase TC_encr_cmd_a52() runs on test_CT {
6609 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6610 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6611 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6612}
6613testcase TC_encr_cmd_a53() runs on test_CT {
6614 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6615 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6616 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6617}
6618
6619private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6620 var LapdmFrame lf;
6621 var octetstring reenc;
6622
6623 /* decode the LAPDm frame */
6624 if (ischosen(exp_match.ab)) {
6625 lf.ab := dec_LapdmFrameAB(enc);
6626 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006628 }
6629
6630 /* check if decoder result matches expectation */
6631 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006633 } else {
6634 log(name, ": matched");
6635 setverdict(pass);
6636 }
6637
6638 /* test if re-encoded frame equals original input */
6639 reenc := enc_LapdmFrame(lf);
6640 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006641 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006642 } else {
6643 setverdict(pass);
6644 }
6645}
6646
6647testcase TC_lapdm_selftest() runs on test_CT {
6648 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6649 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6650 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6651 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6652 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6653 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6654 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6655}
6656
Stefan Sperling4880be42018-08-07 18:12:59 +02006657/***********************************************************************
6658 * DTX Related (see GSM 05.08, section 8.3)
6659 ***********************************************************************/
6660
6661/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006662private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006663 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6664 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6665 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6666 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6667}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006668private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006669 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6670 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6671}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006672private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006673 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6674 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6675 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6676 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6677}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006678private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006679 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6680 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6681 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6682 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6683 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6684 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6685 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6686 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6687}
6688
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006689private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006690 var L1ctlDlMessage dl;
6691 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6692 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6693 var GsmFrameNumber first_fn;
6694 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006695 var integer nfill_frames_sacch := 0;
6696 var integer nfill_frames_nonsacch := 0;
6697 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006698 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6699 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006700 const integer frame_dtx_tchf_mod := 104;
6701 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6702 * which operates in terms of blocks rather than frames. */
6703 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6704 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006705 timer T := 5.0;
6706
6707 f_l1_tune(L1CTL);
6708 RSL.clear;
6709 L1CTL.clear;
6710
6711 /* activate TCHF signalling channel */
6712 f_est_dchan(false);
6713
6714 T.start;
6715 alt {
6716 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6717 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6718 var octetstring l2 := dl.payload.data_ind.payload;
6719
6720 if (is_first_frame) {
6721 is_first_frame := false;
6722 first_fn := dl.dl_info.frame_nr;
6723 }
6724
6725 if (dl.dl_info.link_id.c == SACCH) {
6726 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6727 if (not match(l2_fill_frame_sacch, l2)) {
6728 repeat;
6729 }
6730 } else if (not match(l2_fill_frame, l2)) {
6731 repeat;
6732 }
6733
6734 if (dtxd) {
6735 if (not f_g_chan_is_tchf()) {
6736 T.stop;
6737 f_rsl_chan_deact();
6738 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received fill frame on non-TCH/F channel; DTX is only allowed on TCH/F!");
Stefan Sperling4880be42018-08-07 18:12:59 +02006740 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006741 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006742 T.stop;
6743 f_rsl_chan_deact();
6744 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006745
6746 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6747 * 2 SACCH, 1 TCH/F */
6748 expected_fill_frames := 3;
6749
6750 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6751 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6752 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006753 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006754 } else {
6755 setverdict(pass);
6756 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006757 } else {
6758 if (dl.dl_info.link_id.c == SACCH) {
6759 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006760 repeat;
6761 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006762 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6763 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6764 * we should only see the subset of frames numbers which correspond to a block boundary.
6765 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6766 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6767 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6768 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6769 repeat;
6770 }
6771 }
6772 log("Received DTX TCH fill frame with bad frame number: ", fn,
6773 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6774 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6775 f_rsl_chan_deact();
6776 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006777 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006778 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006779 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006780 if (dl.dl_info.link_id.c == SACCH) {
6781 nfill_frames_sacch := nfill_frames_sacch + 1;
6782 } else {
6783 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6784 }
6785 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006786 T.stop;
6787 if (f_g_chan_is_tchf()) {
6788 /* Without DTX we can expect 25 fill frames for every 104 frames.
6789 * (24 FACCH + 1 SACCH filling) */
6790 expected_fill_frames := 25;
6791 } else if (f_g_chan_is_tchh()) {
6792 /* We can expect 2 fill frames for every 104 frames. */
6793 expected_fill_frames := 2;
6794 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6795 /* We can expect 5 fill frames for every 104 frames. */
6796 expected_fill_frames := 5;
6797 } else {
6798 f_rsl_chan_deact();
6799 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006801 }
6802
6803 f_rsl_chan_deact();
6804 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006805
6806 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006807 setverdict(pass);
6808 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006809 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6810 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006812 }
6813 } else {
6814 repeat;
6815 }
6816 }
6817 }
6818 [] L1CTL.receive { repeat; }
6819 [] T.timeout {
6820 f_rsl_chan_deact();
6821 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006823 }
6824 }
6825}
6826
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006827private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006828 f_test_l2_fill_frames(false);
6829}
6830
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006831private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006832 f_test_l2_fill_frames(true);
6833}
6834
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006835private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006836 var ConnHdlr vc_conn;
6837 var ConnHdlrPars pars;
6838 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006839 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006840 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6841 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6842 if (dtxd) {
6843 if (i >= 4) { /* DTX is only allowed on TCH/F */
6844 break;
6845 }
6846 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6847 } else {
6848 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6849 }
6850 vc_conn.done;
6851 }
6852}
6853
6854/* Verify that L2 fill frames are sent on TCH in signaling mode if
6855 * there is nothing to transmit while DTX is disabled on downlink. */
6856testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6857 f_tch_sign_l2_fill_frame(false);
6858}
6859
6860/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6861 * there is nothing to transmit while DTX is enabled on downlink. */
6862testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6863 f_tch_sign_l2_fill_frame(true);
6864}
Harald Welte0472ab42018-03-12 15:02:26 +01006865
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006866testcase TC_chopped_ipa_ping() runs on test_CT {
6867 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6868}
6869
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006870testcase TC_chopped_ipa_payload() runs on test_CT {
6871 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6872}
6873
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006874
6875/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6876 * Return value: Measurement Report to be sent (encoded octetstring). */
6877type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6878 runs on ConnHdlr return octetstring;
6879
6880private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6881runs on ConnHdlr {
6882 var L1ctlDlMessage l1_dl;
6883 var SacchL1Header l1h;
6884 var octetstring l2;
6885
6886 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6887 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6888 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6889 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6890
6891 /* Pass it to the user specified call-back function */
6892 l2 := cb.apply(l1h, num_blocks);
6893 /* Send a Measurement Report generated by the call-back */
6894 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6895 l1_dl.dl_info.link_id,
6896 l1h, l2));
6897
6898 /* Shall we keep going? */
6899 num_blocks := num_blocks - 1;
6900 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6901 if (num_blocks > 0) { repeat; }
6902 }
6903 [] L1CTL.receive { repeat; }
6904}
6905
6906private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6907runs on ConnHdlr return octetstring {
6908 /* Command the L1 to apply received parameters */
6909 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6910
6911 /* Dummy measurement report (the results are invalid) */
6912 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6913}
6914
6915private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6916runs on ConnHdlr return octetstring {
6917 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6918 setverdict(fail, "Unexpected MS Power level change: ",
6919 g_pars.l1_pars.ms_power_level, " -> ",
6920 l1h.ms_power_lvl);
6921 }
6922
6923 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6924}
6925
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07006926private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
6927runs on ConnHdlr return octetstring {
6928 /* UL RSSI oscillation driven by SACCH block number */
6929 if (num_blocks rem 2 == 0) {
6930 f_trxc_fake_rssi(-100);
6931 } else {
6932 f_trxc_fake_rssi(-50);
6933 }
6934
6935 /* Make sure that MS power level remains constant */
6936 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
6937}
6938
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006939/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6940private function f_TC_ms_pwr_ctrl_constant(charstring id)
6941runs on ConnHdlr {
6942 var integer num_blocks := 8;
6943 timer T := int2float(num_blocks);
6944
6945 f_l1_tune(L1CTL);
6946 RSL.clear;
6947
6948 /* These IEs are needed for autonomous MS power control */
6949 var template (value) RSL_IE_List ies := {
6950 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6951 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6952 }),
6953 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6954 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6955 })
6956 };
6957
6958 /* Ensure that 'rx-current' equals 'rx-target' */
6959 f_trxc_fake_rssi(mp_uplink_power_target);
6960
6961 /* Establish a dedicated channel */
6962 f_est_dchan(more_ies := valueof(ies));
6963
6964 L1CTL.clear;
6965 T.start;
6966 alt {
6967 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
6968 [] T.timeout {
6969 setverdict(fail, "Not all SACCH blocks were processed in time, ",
6970 num_blocks, " were not handled");
6971 }
6972 }
6973}
6974testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
6975 var ConnHdlr vc_conn;
6976 var ConnHdlrPars pars;
6977
6978 f_init();
6979
6980 /* Explicitly configure the Uplink power target (in dBm) */
6981 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
6982
6983 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
6984 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6985 log(testcasename(), ": starting on ", pars.chan_nr);
6986
6987 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
6988 pars, trxc_comp := true);
6989 vc_conn.done;
6990 }
6991
6992 /* No need to reset Uplink power parameters - the IUT restarts anyway */
6993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6994}
6995
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07006996/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
6997private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
6998runs on ConnHdlr {
6999 var integer num_blocks := 16;
7000 timer T := int2float(num_blocks);
7001
7002 f_l1_tune(L1CTL);
7003 RSL.clear;
7004
7005 /* These IEs are needed for autonomous MS power control */
7006 var template (value) RSL_IE_List ies := {
7007 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7008 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7009 }),
7010 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7011 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7012 })
7013 };
7014
7015 /* Ensure that 'rx-current' equals 'rx-target' */
7016 f_trxc_fake_rssi(mp_uplink_power_target);
7017
7018 /* Establish a dedicated channel */
7019 f_est_dchan(more_ies := valueof(ies));
7020
7021 L1CTL.clear;
7022 T.start;
7023 alt {
7024 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7025 [] T.timeout {
7026 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7027 num_blocks, " were not handled");
7028 }
7029 }
7030}
7031testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7032 var ConnHdlr vc_conn;
7033 var ConnHdlrPars pars;
7034
7035 f_init();
7036
7037 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7038 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7039 /* Explicitly configure the Uplink power range (target and delte) */
7040 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7041 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7042
7043 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7044 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7045 log(testcasename(), ": starting on ", pars.chan_nr);
7046
7047 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7048 pars, trxc_comp := true);
7049 vc_conn.done;
7050 }
7051
7052 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7053 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7054}
7055
Harald Welte0472ab42018-03-12 15:02:26 +01007056/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7057/* protocol error as per 44.006 */
7058/* link layer failure (repetition of I-frame N200 times without ACK */
7059/* repetition of SABM or DISC N200 times without ACK */
7060/* receptiom of SABM in multi-frame established state */
7061
7062
Harald Welte68e495b2018-02-25 00:05:57 +01007063/* TODO Areas:
7064
7065* channel activation
7066** with BS_Power / MS_Power, bypassing power control loop
7067** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007068** with timing advance from initial activation on
7069* mode modify
7070** encryption
7071** multirate
7072* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007073** unsupported algorithm
7074* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007075* BS Power Control
7076* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007077* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007078* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007079** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007080* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007081** DATA_IND from BTS->PCU
7082** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007083
7084*/
Harald Welte70767382018-02-21 12:16:40 +01007085
7086control {
7087 execute( TC_chan_act_stress() );
7088 execute( TC_chan_act_react() );
7089 execute( TC_chan_deact_not_active() );
7090 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007091 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007092 execute( TC_sacch_filling() );
7093 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007094 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007095 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007096 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007097 execute( TC_sacch_chan_act_ho_async() );
7098 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007099 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007100 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007101 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007102 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007103 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007104 execute( TC_rach_load_idle_thresh0() );
7105 execute( TC_rach_load_idle_below_thresh() );
7106 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007107 execute( TC_meas_res_speech_tchf() );
7108 execute( TC_meas_res_speech_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007109 execute( TC_meas_res_sign_tchf() );
7110 execute( TC_meas_res_sign_tchh() );
7111 execute( TC_meas_res_sign_sdcch4() );
7112 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007113 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007114 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007115 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007116 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007117 execute( TC_rsl_bs_pwr_static_ass() );
7118 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007119 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007120 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007121 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007122 execute( TC_rsl_ms_pwr_dyn_up() );
7123 execute( TC_rsl_ms_pwr_dyn_down() );
7124 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7125 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007126 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007127 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007128 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007129 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007130 execute( TC_paging_imsi_80percent() );
7131 execute( TC_paging_tmsi_80percent() );
7132 execute( TC_paging_imsi_200percent() );
7133 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007134 execute( TC_rsl_protocol_error() );
7135 execute( TC_rsl_mand_ie_error() );
7136 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007137 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007138 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007139 execute( TC_si_sched_2bis() );
7140 execute( TC_si_sched_2ter() );
7141 execute( TC_si_sched_2ter_2bis() );
7142 execute( TC_si_sched_2quater() );
7143 execute( TC_si_sched_13() );
7144 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007145 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007146 execute( TC_ipa_crcx_twice_not_active() );
7147 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007148 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007149 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007150
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007151 if (mp_pcu_socket != "") {
7152 execute( TC_pcu_act_req() );
7153 execute( TC_pcu_act_req_wrong_ts() );
7154 execute( TC_pcu_act_req_wrong_bts() );
7155 execute( TC_pcu_act_req_wrong_trx() );
7156 execute( TC_pcu_deact_req() );
7157 execute( TC_pcu_deact_req_wrong_ts() );
7158 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007159 if (mp_l1_supports_gprs) {
7160 execute( TC_pcu_data_req_pdtch() );
7161 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007162 execute( TC_pcu_data_req_wrong_bts() );
7163 execute( TC_pcu_data_req_wrong_trx() );
7164 execute( TC_pcu_data_req_wrong_ts() );
7165 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007166 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007167 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007168 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007169 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007170 execute( TC_pcu_data_req_imm_ass_pch() );
7171 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007172 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007173 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007174 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007175 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007176 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007177 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007178 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007179 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007180 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007181 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007182 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007183 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007184 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007185 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007186 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007187 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007188 execute( TC_dyn_osmo_pdch_act_deact() );
7189 execute( TC_dyn_osmo_pdch_double_act() );
7190 execute( TC_dyn_ipa_pdch_act_deact() );
7191 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7192
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007193 if (PCUIF_Types.mp_pcuif_version >= 10) {
7194 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007195 execute( TC_pcu_socket_nsvc_ipv4() );
7196 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007197 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007198 } else {
7199 log("PCU socket path not available, skipping PCU tests");
7200 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007201
Harald Welte3d04ae62018-04-04 20:29:05 +02007202 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007203 execute( TC_dyn_osmo_pdch_tchf_act() );
7204 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007205 execute( TC_dyn_ipa_pdch_tchf_act() );
7206 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007207
7208 execute( TC_rll_est_ind() );
7209 execute( TC_rll_est_req_DCCH_3() );
7210 execute( TC_rll_est_req_ACCH_3() );
7211 execute( TC_rll_rel_ind_DCCH_0() );
7212 execute( TC_rll_rel_ind_DCCH_3() );
7213 execute( TC_rll_rel_ind_ACCH_0() );
7214 execute( TC_rll_rel_ind_ACCH_3() );
7215 execute( TC_rll_rel_req() );
7216 execute( TC_rll_unit_data_req_DCCH() );
7217 execute( TC_rll_unit_data_req_ACCH() );
7218 execute( TC_rll_unit_data_ind_DCCH() );
7219 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007220
7221 execute( TC_chan_act_a51() );
7222 execute( TC_chan_act_a52() );
7223 execute( TC_chan_act_a53() );
7224 execute( TC_encr_cmd_a51() );
7225 execute( TC_encr_cmd_a52() );
7226 execute( TC_encr_cmd_a53() );
7227
Harald Welteee25aae2019-05-19 14:32:37 +02007228 execute( TC_err_rep_wrong_mdisc() );
7229 execute( TC_err_rep_wrong_msg_type() );
7230 execute( TC_err_rep_wrong_sequence() );
7231
Harald Weltee613f962018-04-18 22:38:16 +02007232 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007233
7234 execute( TC_tch_sign_l2_fill_frame() );
7235 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007236
7237 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007238 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007239
7240 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007241 execute( TC_ms_pwr_ctrl_pf_ewma() );
Harald Welte70767382018-02-21 12:16:40 +01007242}
7243
7244
7245}