blob: cc384332b2921986fd9f285c205a3e8f9ce286e1 [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}
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003007testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3008 var template RSL_IE_ChannelMode ch_mode;
3009 var ConnHdlr vc_conn;
3010 var ConnHdlrPars pars;
3011 f_init();
3012 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3013 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3014 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3015 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3016 pars.l1_pars.toa256_enabled := true;
3017 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3018 pcu_comp := false, trxc_comp := true);
3019 vc_conn.done;
3020 }
3021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3022}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003023
Harald Welte70767382018-02-21 12:16:40 +01003024testcase TC_meas_res_sign_tchf() runs on test_CT {
3025 var ConnHdlr vc_conn;
3026 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003027 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003028 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003029 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003030 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3031 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003032 vc_conn.done;
3033 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003035}
3036testcase TC_meas_res_sign_tchh() runs on test_CT {
3037 var ConnHdlr vc_conn;
3038 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003039 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003040 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003041 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003042 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3043 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003044 vc_conn.done;
3045 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003046 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003047}
3048testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3049 var ConnHdlr vc_conn;
3050 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003051 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003052 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3053 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003054 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3055 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003056 vc_conn.done;
3057 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003058 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003059}
3060testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3061 var ConnHdlr vc_conn;
3062 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003063 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003064 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3065 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003066 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3067 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003068 vc_conn.done;
3069 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003071}
Harald Welte685d5982018-02-27 20:42:05 +01003072testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3073 var ConnHdlr vc_conn;
3074 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003075 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003076 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3077 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003078 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003079 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003080 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3081 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003082 vc_conn.done;
3083 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003085}
3086
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003087/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3088 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003089private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003090 var L1ctlDlMessage l1_dl;
3091 var RSL_IE_MS_Power ms_power;
3092 var RSL_Message rsl;
3093 var uint5_t power_level := 0;
3094
3095 f_l1_tune(L1CTL);
3096 RSL.clear;
3097
3098 f_est_dchan();
3099
3100 ms_power.reserved := 0;
3101 ms_power.fpc_epc := false;
3102
3103 /* Send the first power control command. This will disable any BTS/TRX
3104 * internal power control and switch the MS (which is not in scope of
3105 * this test) to a constant power level. We start with a power level
3106 * of 0 */
3107 ms_power.power_level := power_level;
3108 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3109 RSL.send(rsl);
3110
3111 alt {
3112
3113 /* Pick all SACCH blocks for checking */
3114 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3115
3116 /* The first byte of the L1 header contains the power level.
3117 * The reserved bits and the fpc bit is set to 0, so we may
3118 * compare directly. */
3119 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3120 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3121 }
3122
3123 /* Signal a new power level via RSL for the next turn. */
3124 if (power_level < 31) {
3125 power_level := power_level + 1;
3126 ms_power.power_level := power_level;
3127 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3128 RSL.send(rsl);
3129 repeat;
3130 }
3131
3132 }
3133
3134 /* Ignore all other blocks */
3135 [] L1CTL.receive { repeat; }
3136
3137 }
3138
3139 f_rsl_chan_deact();
3140 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3141
3142 setverdict(pass);
3143}
3144
3145testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3146 var ConnHdlr vc_conn;
3147 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003148 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003149
3150 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3151 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3152 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3153 vc_conn.done;
3154 }
3155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3156}
Harald Welte70767382018-02-21 12:16:40 +01003157
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003158/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003159TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003160private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003161 var L1ctlDlMessage l1_dl;
3162 var uint5_t ta_to_test := 16;
3163
3164
3165 f_l1_tune(L1CTL);
3166 RSL.clear;
3167
3168 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003169 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003170
3171 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3172
3173
3174 alt {
3175
3176 /* Pick all SACCH blocks for checking */
3177 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3178
3179 /* The second byte of the L1 header contains the TA. */
3180 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3181 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3182 }
3183
3184 }
3185
3186 /* Ignore all other blocks */
3187 [] L1CTL.receive { repeat; }
3188
3189 }
3190
3191 f_rsl_chan_deact();
3192 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3193
3194 setverdict(pass);
3195}
3196
3197testcase TC_rsl_chan_initial_ta() runs on test_CT {
3198 var ConnHdlr vc_conn;
3199 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003200 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003201 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003202 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3203 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003204 vc_conn.done;
3205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3206}
3207
Eric Wilde57e1a62019-05-28 13:30:55 +02003208/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003209private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003210 var L1ctlDlMessage l1_dl;
3211 var uint5_t ms_power_level := 7;
3212
3213 var RSL_IE_MS_Power ms_power;
3214 ms_power.reserved := 0;
3215 ms_power.fpc_epc := false;
3216 ms_power.power_level := ms_power_level;
3217
3218 f_l1_tune(L1CTL);
3219 RSL.clear;
3220
3221 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3222
3223 timer T := 1.0;
3224 T.start;
3225 alt {
3226 /* Pick all SACCH blocks for checking */
3227 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3228 /* The first byte of the L1 header contains the power level.. */
3229 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3230 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3231 }
3232 }
3233 /* Ignore all other blocks */
3234 [] L1CTL.receive { repeat; }
3235 [] T.timeout {
3236 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3237 }
3238 }
3239
3240 f_rsl_chan_deact();
3241 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3242 setverdict(pass);
3243}
3244
3245testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3246 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3247 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3248}
3249
Harald Welte0472ab42018-03-12 15:02:26 +01003250/* 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 +01003251private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003252 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003253 RSL.clear;
3254
3255 f_est_dchan();
3256 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003257 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003258
3259 timer T := 40.0;
3260 T.start;
3261 alt {
3262 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3263 setverdict(pass)
3264 }
3265 [] RSL.receive { repeat };
3266 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003267 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003268 }
3269 }
3270 f_rsl_chan_deact();
3271}
3272testcase TC_conn_fail_crit() runs on test_CT {
3273 var ConnHdlr vc_conn;
3274 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003275 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003276 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3277 pars.t_guard := 60.0;
3278 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3279 vc_conn.done;
3280}
3281
Harald Welte93640c62018-02-25 16:59:33 +01003282/***********************************************************************
3283 * Paging
3284 ***********************************************************************/
3285
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003286private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003287 if (tmsi == 'FFFFFFFF'O) {
3288 return true;
3289 } else {
3290 return false;
3291 }
3292}
Harald Welte70767382018-02-21 12:16:40 +01003293
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003294private type record allowedFn { integer frame_nr }
3295private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3296private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3297private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3298private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3299private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3300private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3301private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3302private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3303private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003304{
3305 var integer frame_nr_51;
3306 frame_nr_51 := frame_nr mod 51
3307
3308 var allowedFn fn_check;
3309 fn_check.frame_nr := frame_nr_51;
3310
3311 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003312 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003313 return;
3314 }
3315
3316 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3317 return;
3318 }
3319 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3320 return;
3321 }
3322 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3323 return;
3324 }
3325 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3326 return;
3327 }
3328 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3329 return;
3330 }
3331 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3332 return;
3333 }
3334 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3335 return;
3336 }
3337 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3338 return;
3339 }
3340
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003342 return;
3343}
3344
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003345private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3346 inout integer num_paging_rcv_ids,
3347 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003348runs on test_CT {
3349 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003350 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003351 repeat;
3352 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003353 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003354 var octetstring without_plen :=
3355 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3356 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003357
3358 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3359
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003360 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3361 /* Ignore empty RR Paging Request (PCH filling) messages.
3362 * TODO: does it make sense to count them? */
3363 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003364 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3365 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003366 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003367 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3368 }
3369 } else if (match(rr, tr_PAGING_REQ2)) {
3370 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3371 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3372 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3373 }
3374 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3375 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3376 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003377 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003378 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3379 }
3380 } else if (match(rr, tr_PAGING_REQ3)) {
3381 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3382 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3383 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3384 }
3385 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3386 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3387 }
3388 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3389 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3390 }
3391 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3392 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3393 }
3394 }
3395 repeat;
3396 }
3397}
3398
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003399private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003400 boolean combined_ccch,
3401 integer bs_ag_blks_res,
3402 float load_factor,
3403 boolean exp_load_ind,
3404 boolean exp_overload,
3405 boolean use_tmsi
3406}
3407
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003408private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003409 integer num_paging_sent,
3410 integer num_paging_rcv_msgs,
3411 integer num_paging_rcv_ids,
3412 integer num_overload
3413}
3414
Harald Welte68e495b2018-02-25 00:05:57 +01003415/* Helper function for paging related testing */
3416private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003417 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003418 f_init_l1ctl();
3419 f_l1_tune(L1CTL);
3420
3421 var PagingTestState st := {
3422 num_paging_sent := 0,
3423 num_paging_rcv_msgs := 0,
3424 num_paging_rcv_ids := 0,
3425 num_overload := 0
3426 };
3427
3428 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3429 var float max_pch_imsi_per_sec;
3430 if (cfg.use_tmsi) {
3431 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3432 } else {
3433 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3434 }
3435 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3436 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003437 var float time_total := 20.0;
3438 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3439 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003440
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003441 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3442 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003443
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003444 timer T_itv := 0.0;
3445 T_itv.start;
3446 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003447 alt {
3448 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003449 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003450 st.num_overload := st.num_overload + 1;
3451 repeat;
3452 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003453 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003455 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003456 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003457 log("Rx LOAD_IND");
3458 /* FIXME: analyze/verify interval + contents */
3459 repeat;
3460 }
3461 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003462 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003463 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003464 [] T_itv.timeout {
3465 /* Send paging cmds based on elapsed time */
3466 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3467 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003468 var MobileIdentityV mi;
3469
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003470 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003471 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003472 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003473 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003474 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003475 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003476
3477 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003478 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 +02003479
3480 st.num_paging_sent := st.num_paging_sent + 1;
3481 }
3482 if (st.num_paging_sent < pkt_total) {
3483 /* Wait for interval to next PAGING COMMAND */
3484 var float time_now := T_total.read;
3485 var float next_sched := int2float(st.num_paging_sent)*interval;
3486 if (next_sched > time_now) {
3487 T_itv.start(next_sched - time_now);
3488 } else {
3489 T_itv.start(0.0);
3490 }
3491 } else {
3492 /* We are done, no need to keep counting */
3493 T_total.stop;
3494 }
3495 }
3496 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003497 }
3498 }
3499
3500 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3501 timer T_wait := 18.0;
3502 T_wait.start;
3503 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003504 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003505 [] L1CTL.receive { repeat; }
3506 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003507 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3508 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003509 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003510 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003511 }
Harald Welte68e495b2018-02-25 00:05:57 +01003512 }
3513
3514 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3515 " rcvd_ids=", st.num_paging_rcv_ids);
3516 return st;
3517}
3518
3519/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3520 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3521 * - that CCCH LOAD IND (PCH) are being generated
3522 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3523testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003524 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003525 var PagingTestCfg cfg := {
3526 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003527 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003528 load_factor := 0.8,
3529 exp_load_ind := true,
3530 exp_overload := false,
3531 use_tmsi := false
3532 };
3533 var PagingTestState st := f_TC_paging(cfg);
3534 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3536 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003537 } else {
3538 setverdict(pass);
3539 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003541}
3542
3543/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3544 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3545 * - that CCCH LOAD IND (PCH) are being generated
3546 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3547testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003548 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003549 var PagingTestCfg cfg := {
3550 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003551 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003552 load_factor := 0.8,
3553 exp_load_ind := true,
3554 exp_overload := false,
3555 use_tmsi := true
3556 };
3557 var PagingTestState st := f_TC_paging(cfg);
3558 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3560 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003561 } else {
3562 setverdict(pass);
3563 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003565}
3566
3567/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3568 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3569 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3570 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3571testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003572 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003573 var PagingTestCfg cfg := {
3574 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003575 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003576 load_factor := 2.0,
3577 exp_load_ind := true,
3578 exp_overload := true,
3579 use_tmsi := false
3580 };
3581 var PagingTestState st := f_TC_paging(cfg);
3582 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3583 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003584 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003585 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003586 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 +01003587 } else {
3588 setverdict(pass);
3589 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003591}
3592
3593/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3594 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3595 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3596 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3597testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003598 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003599 var PagingTestCfg cfg := {
3600 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003601 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003602 load_factor := 2.0,
3603 exp_load_ind := true,
3604 exp_overload := true,
3605 use_tmsi := true
3606 };
3607 var PagingTestState st := f_TC_paging(cfg);
3608 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3609 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003610 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003611 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003612 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 +01003613 } else {
3614 setverdict(pass);
3615 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003617}
3618
3619
Harald Welte93640c62018-02-25 16:59:33 +01003620/***********************************************************************
3621 * Immediate Assignment / AGCH
3622 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003623private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003624 len := 0,
3625 ma := ''B
3626}
Harald Welte93640c62018-02-25 16:59:33 +01003627
Harald Weltee8d750e2018-06-10 21:41:35 +02003628private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3629 return int2str(num_tx) & " sent, "
3630 & int2str(num_rx) & " received, "
3631 & int2str(num_del) & " deleted";
3632}
3633
3634private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3635 var L1ctlDlMessage l1_dl;
3636 timer T := 10.0;
3637 var integer num_tx := 0;
3638 var integer num_rx := 0;
3639 var integer num_del := 0;
3640 var charstring res_str;
3641 var float rx_ratio;
3642
Harald Welte10474062019-05-30 16:48:17 +02003643 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003644 f_init_l1ctl();
3645 f_l1_tune(L1CTL);
3646
3647 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003648 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003649 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3650 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003651 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003652 num_tx := num_tx+1;
3653 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003654 }
3655 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003656 T.start;
3657 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003658 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003659 num_del := num_del+1;
3660 repeat;
3661 }
3662 [] RSL_CCHAN.receive {
3663 repeat;
3664 }
3665 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003666 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3667 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3668 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003669 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003670 } else {
3671 num_rx := num_rx+1;
3672 }
3673 repeat;
3674 }
3675 [] L1CTL.receive { repeat; }
3676 [] T.timeout { }
3677 }
3678 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3679 log("AGCH test: " & res_str);
3680 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003681 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003682 }
3683 rx_ratio := int2float(num_rx) / int2float(num_tx);
3684 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003685 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 +02003686 } else {
3687 setverdict(pass);
3688 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003690}
3691
Harald Weltee8d750e2018-06-10 21:41:35 +02003692/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3693testcase TC_imm_ass_1000_20ms() runs on test_CT {
3694 f_TC_imm_ass(1000, 0.02, 0.25);
3695}
3696
3697/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3698testcase TC_imm_ass_200_0ms() runs on test_CT {
3699 f_TC_imm_ass(200, 0.0, 0.05);
3700}
3701
3702/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3703testcase TC_imm_ass_200_76ms() runs on test_CT {
3704 f_TC_imm_ass(150, 0.076, 1.00);
3705}
3706
3707
3708
Harald Welte48494ca2018-02-25 16:59:50 +01003709/***********************************************************************
3710 * BCCH
3711 ***********************************************************************/
3712
3713/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003714private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003715 GsmFrameNumber frame_number,
3716 SystemInformation si
3717}
3718
3719/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003720private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003721
3722/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003723private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003724
3725/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003726private function f_si_vecslot_contains(SystemInformationVector arr,
3727 RrMessageType key,
3728 boolean bcch_ext := false)
3729return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003730 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3731 var integer fn_mod51 := arr[i].frame_number mod 51;
3732 if (not bcch_ext and fn_mod51 == 2 or
3733 bcch_ext and fn_mod51 == 6) {
3734 if (arr[i].si.header.message_type == key) {
3735 return true;
3736 }
3737 }
3738 }
3739 return false;
3740}
3741
3742/* 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 +07003743private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3744 integer tc, RrMessageType key,
3745 boolean ext_bcch := false)
3746{
Harald Welte48494ca2018-02-25 16:59:50 +01003747 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003749 }
3750}
3751
3752/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003753private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3754 RrMessageType key)
3755return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003756 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3757 if (f_si_vecslot_contains(arr[tc], key) or
3758 f_si_vecslot_contains(arr[tc], key, true)) {
3759 return true;
3760 }
3761 }
3762 return false;
3763}
3764
3765/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003766private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3767 RrMessageType key,
3768 boolean bcch_ext := false,
3769 integer n := 1, integer m := 4)
3770return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003771 var integer count := 0;
3772 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3774 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003775 }
3776 for (var integer i:= 0; i < m; i := i + 1) {
3777 var integer fn_mod51 := arr[i].frame_number mod 51;
3778 if (not bcch_ext and fn_mod51 == 2 or
3779 bcch_ext and fn_mod51 == 6) {
3780 if (arr[i].si.header.message_type == key) {
3781 count := count + 1;
3782 }
3783 }
3784 }
3785 if (count >= n) {
3786 return true;
3787 } else {
3788 return false;
3789 }
3790}
3791
3792/* 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 +07003793private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3794 integer tc, RrMessageType key,
3795 boolean ext_bcch := false,
3796 integer n, integer m)
3797{
Harald Welte48494ca2018-02-25 16:59:50 +01003798 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003800 }
3801}
3802
3803/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003804private function f_si_vecslot_contains_only(SystemInformationVector arr,
3805 RrMessageType key,
3806 boolean bcch_ext := false)
3807return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003808 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3809 var integer fn_mod51 := arr[i].frame_number mod 51;
3810 if (not bcch_ext and fn_mod51 == 2 or
3811 bcch_ext and fn_mod51 == 6) {
3812 if (arr[i].si.header.message_type != key) {
3813 return false;
3814 }
3815 }
3816 }
3817 return true;
3818}
3819
3820/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003821private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3822 integer tc, RrMessageType key,
3823 boolean ext_bcch := false)
3824{
Harald Welte48494ca2018-02-25 16:59:50 +01003825 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003827 }
3828}
3829
3830/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003831private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003832 boolean bcch_extended,
3833 boolean si1_present,
3834 boolean si2bis_present,
3835 boolean si2ter_present,
3836 boolean si2quater_present,
3837 boolean si7_present,
3838 boolean si8_present,
3839 boolean si9_present,
3840 boolean si13_present,
3841 boolean si13alt_present,
3842 boolean si15_present,
3843 boolean si16_present,
3844 boolean si17_present,
3845 boolean si2n_present,
3846 boolean si21_present,
3847 boolean si22_present
3848}
3849
3850/* 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 +07003851private function f_validate_si_scheduling(SystemInformationConfig cfg,
3852 SystemInformationVectorPerTc si_per_tc)
3853{
Harald Welte48494ca2018-02-25 16:59:50 +01003854 var integer i;
3855 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3856 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003858 }
3859 }
3860 if (cfg.si1_present) {
3861 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3862 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3863 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3864 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3865 /* make sure *ALL* contain SI1 */
3866 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3867 }
3868 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3869 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3870 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3871 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3872 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3873 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3874
3875 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3876 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3877 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3878 * consecutive occurrences of TC = 4. */
3879 if (cfg.si2bis_present and not cfg.si2ter_present) {
3880 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3881 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3882 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3883 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3884 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3885 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3886 }
3887
3888 if (cfg.si7_present or cfg.si8_present) {
3889 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3890 * if System Information type 4 does not contain all information needed for cell
3891 * selection and reselection. */
3892 if (not cfg.bcch_extended) {
3893 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3894 }
3895 if (cfg.si7_present) {
3896 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3897 }
3898 if (cfg.si8_present) {
3899 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3900 }
3901 }
3902
3903 if (cfg.si2quater_present) {
3904 /* iii) System information type 2 quater is sent if needed, as determined by the system
3905 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3906 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3907 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3908 * within any of 4 consecutive occurrences of TC = 5. */
3909 if (not (cfg.bcch_extended)) {
3910 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3911 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3912 } else {
3913 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3914 }
3915 } else {
3916 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3917 }
3918 }
3919 if (cfg.si9_present) {
3920 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3921 * in system information type 3 as defined in 3GPP TS 44.018. */
3922 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3923 }
3924 if (cfg.si13_present) {
3925 /* vii) System Information type 13 is only related to the GPRS service. System Information
3926 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3927 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3928 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3929 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3930 * within any of 4 consecutive occurrences of TC=4. */
3931 if (not cfg.bcch_extended) {
3932 log("not-bccch-extended");
3933 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3934 } else {
3935 log("bccch-extended");
3936 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3937 }
3938 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003940 }
3941 }
3942 if (cfg.si16_present or cfg.si17_present) {
3943 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3944 * should not be sent in a cell where network sharing is used (see rule xv). */
3945 if (cfg.si22_present) {
3946 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3947 }
3948 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003949 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003950 }
3951 if (not cfg.bcch_extended) {
3952 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3953 }
3954 if (cfg.si16_present) {
3955 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3956 }
3957 if (cfg.si17_present) {
3958 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3959 }
3960 }
3961
3962 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3963 * broadcast information. The frequency with which they are sent is determined by the
3964 * system operator. System Information type 9 identifies the scheduling of System
3965 * Information type 18 and 20 messages. */
3966
3967 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3968 * Information Type 19 is present, then its scheduling shall be indicated in System
3969 * Information Type 9. */
3970
3971 if (cfg.si15_present) {
3972 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3973 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3974 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3975 * 4 consecutive occurrences of TC = 1. */
3976 if (not cfg.bcch_extended) {
3977 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3978 } else {
3979 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3980 }
3981 }
3982 if (cfg.si13alt_present) {
3983 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3984 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3985 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3986 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3987 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3988 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3989 * of TC = 4. */
3990 if (cfg.si13_present) {
3991 testcase.stop("Error: Cannot have SI13alt and SI13");
3992 }
3993 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003994 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003995 }
3996 if (not cfg.bcch_extended) {
3997 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3998 } else {
3999 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4000 }
4001 }
4002 if (cfg.si2n_present) {
4003 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4004 * as determined by the system operator. In the case that the message is sent on the
4005 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4006 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4007 * consecutive occurrences of TC = 4. */
4008 if (not cfg.bcch_extended) {
4009 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4010 } else {
4011 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4012 }
4013 }
4014 if (cfg.si21_present) {
4015 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4016 * determined by the system operator. If Extended Access Barring is in use in the cell
4017 * then this message is sent at least once within any of 4 consecutive occurrences of
4018 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4019 * cell then this message shall only be sent on BCCH Ext. */
4020 if (not cfg.bcch_extended) {
4021 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4022 } else {
4023 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4024 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004025 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004026 }
4027 }
4028 }
4029 if (cfg.si22_present) {
4030 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4031 * should not be sent in a cell where SoLSA is used (see rule viii). System
4032 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4033 * =2 and TC=6. */
4034 if (cfg.si16_present or cfg.si17_present) {
4035 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4036 }
4037 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4038 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004040 }
4041 if (not cfg.bcch_extended) {
4042 testcase.stop("Error: SI22 requires BCCH Extd!");
4043 } else {
4044 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4045 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4046 }
4047 }
4048}
4049
4050/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004051private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4052return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004053 timer T := duration;
4054 var SystemInformationVectorPerTc si_per_tc;
4055 var L1ctlDlMessage l1_dl;
4056
4057 /* initialize all per-TC vectors empty */
4058 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4059 si_per_tc[i] := {};
4060 }
4061
4062 /* flush all previous L1 queued msgs */
4063 pt.clear;
4064
4065 T.start;
4066 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004067 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004068 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4069 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4070 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004071 repeat;
4072 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004073
Harald Welte48494ca2018-02-25 16:59:50 +01004074 var integer tc := f_gsm_compute_tc(sig.frame_number);
4075 log("SI received at TC=", tc, ": ", sig.si);
4076 /* append to the per-TC bucket */
4077 si_per_tc[tc] := si_per_tc[tc] & { sig };
4078 repeat;
4079 }
4080 [] pt.receive { repeat; }
4081 [] T.timeout { }
4082 }
4083
4084 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4085 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4086 }
4087 log("si_per_tc=", si_per_tc);
4088 return si_per_tc;
4089}
4090
4091/* helper function: Set given SI via RSL + validate scheduling.
4092 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004093private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004094 var SystemInformationVectorPerTc si_per_tc;
4095 f_init_l1ctl();
4096 f_l1_tune(L1CTL);
4097
4098 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004099 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004100 f_validate_si_scheduling(si_cfg, si_per_tc);
4101
4102 setverdict(pass);
4103}
4104
4105testcase TC_si_sched_default() runs on test_CT {
4106 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004107 /* 2+3+4 are mandatory and set in f_init() */
4108 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004109 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004110}
4111
4112testcase TC_si_sched_1() runs on test_CT {
4113 f_init();
4114 si_cfg.si1_present := true;
4115 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004116 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004118}
4119
4120testcase TC_si_sched_2bis() runs on test_CT {
4121 f_init();
4122 si_cfg.si2bis_present := true;
4123 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4124 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004125 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004126}
4127
4128testcase TC_si_sched_2ter() runs on test_CT {
4129 f_init();
4130 si_cfg.si2ter_present := true;
4131 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4132 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004134}
4135
4136testcase TC_si_sched_2ter_2bis() runs on test_CT {
4137 f_init();
4138 si_cfg.si2bis_present := true;
4139 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4140 si_cfg.si2ter_present := true;
4141 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4142 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004143 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004144}
4145
4146testcase TC_si_sched_2quater() runs on test_CT {
4147 f_init();
4148 si_cfg.si2quater_present := true;
4149 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004150 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004152}
4153
4154testcase TC_si_sched_13() runs on test_CT {
4155 f_init();
4156 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004157 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004158 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004159 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004160}
4161
4162testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4163 f_init();
4164 si_cfg.si2bis_present := true;
4165 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4166 si_cfg.si2ter_present := true;
4167 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4168 si_cfg.si2quater_present := true;
4169 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4170 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004171 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004172 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004174}
4175
4176
Harald Welte68e495b2018-02-25 00:05:57 +01004177testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004178 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004179 /* FIXME: enable / disable individual BCCH info */
4180 //ts_RSL_BCCH_INFO(si_type, info);
4181 /* expect no ERROR REPORT after either of them *
4182 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004183 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004184}
4185
Harald Welte93640c62018-02-25 16:59:33 +01004186/***********************************************************************
4187 * Low-Level Protocol Errors / ERROR REPORT
4188 ***********************************************************************/
4189
Harald Welte01d982c2018-02-25 01:31:40 +01004190private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4191 timer T := 5.0;
4192 T.start;
4193 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004194 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004195 setverdict(pass);
4196 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004197 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004199 }
4200 [] RSL_CCHAN.receive {
4201 repeat;
4202 }
4203 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004204 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004205 }
4206 }
4207}
4208
4209/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4210testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004211 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004212 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4213 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004214 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004215
4216 f_exp_err_rep(RSL_ERR_PROTO);
4217}
4218
4219/* Provoke a mandatory IE error and match on ERROR REPORT */
4220testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004221 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004222
4223 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4224 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004225 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004226
4227 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4228}
4229
4230/* Provoke an IE content error and match on ERROR REPORT */
4231testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004232 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004233 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4234 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004235 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004236
4237 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4238}
4239
Harald Welteee25aae2019-05-19 14:32:37 +02004240/* attempt to activate channel with wrong RSL Message Discriminator IE */
4241function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4242 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4243 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4244 RSL.send(rsl);
4245 f_rslem_unregister(0, g_chan_nr);
4246}
4247testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4248 var ConnHdlr vc_conn;
4249 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4250
Harald Welte10474062019-05-30 16:48:17 +02004251 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004252
4253 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4254 vc_conn.done;
4255 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4256
4257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4258}
4259
4260/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004261private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004262 var template (value) RSL_Message rsl_tx;
4263 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4264 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4265 RSL.send(rsl_tx);
4266 f_rslem_unregister(0, g_chan_nr);
4267}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004268private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004269 var template (value) RSL_Message rsl_tx;
4270 /* we first have to activate the dedicated channel */
4271 f_rsl_chan_act(g_pars.chan_mode);
4272 /* ... to then send an invalid RLL message */
4273 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4274 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4275 RSL.send(rsl_tx);
4276 f_rslem_unregister(0, g_chan_nr);
4277}
4278testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4279 var ConnHdlr vc_conn;
4280 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4281 var template (value) RSL_Message rsl_tx;
4282
Harald Welte10474062019-05-30 16:48:17 +02004283 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004284
4285 /* Common Channel with wrong message type */
4286 RSL_CCHAN.clear;
4287 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4288 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004289 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004290 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4291
4292 /* TRX Management */
4293 RSL_CCHAN.clear;
4294 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4295 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004296 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004297 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4298
4299 /* Dedicated Channel */
4300 RSL_CCHAN.clear;
4301 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4302 vc_conn.done;
4303 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4304
4305 /* RLL */
4306 RSL_CCHAN.clear;
4307 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4308 vc_conn.done;
4309 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4310}
4311
4312/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004313private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004314 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4315 f_rslem_unregister(0, g_chan_nr);
4316}
4317testcase TC_err_rep_wrong_sequence() runs on test_CT {
4318 var ConnHdlr vc_conn;
4319 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4320
Harald Welte10474062019-05-30 16:48:17 +02004321 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004322
4323 RSL_CCHAN.clear;
4324 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4325 vc_conn.done;
4326 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4327}
4328
Harald Welte93640c62018-02-25 16:59:33 +01004329/***********************************************************************
4330 * IPA CRCX/MDCX/DLCS media stream handling
4331 ***********************************************************************/
4332
Harald Weltea871a382018-02-25 02:03:14 +01004333/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004334private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004335 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4336 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004337}
4338testcase TC_ipa_dlcx_not_active() runs on test_CT {
4339 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004340 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004341 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4342 vc_conn.done;
4343}
Harald Welte68e495b2018-02-25 00:05:57 +01004344
Harald Weltea3f1df92018-02-25 12:49:55 +01004345/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004346private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004347 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4348 "IPA CRCX ACK");
4349 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4350 "IPA CRCX NACK");
4351}
4352testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4353 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004354 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004355 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4356 vc_conn.done;
4357}
4358
4359/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004360private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004361 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4362 "IPA CRCX ACK");
4363 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4364 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4365 var uint7_t rtp_pt2 := f_rnd_int(127);
4366 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4367 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4368 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4369 "IPA MDCX ACK");
4370 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4371 "IPA DLCX ACK");
4372}
4373testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4374 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004375 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004376 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4377 vc_conn.done;
4378}
4379
Harald Welte3ae11da2018-02-25 13:36:06 +01004380/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004381private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004382 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4383 "IPA CRCX ACK");
4384 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4385 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4386 var uint7_t rtp_pt2 := f_rnd_int(127);
4387 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4388 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4389 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4390 "IPA MDCX ACK");
4391 /* Second MDCX */
4392 remote_ip := f_rnd_int(c_UINT32_MAX);
4393 remote_port := f_rnd_int(c_UINT16_MAX);
4394 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4395 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4396 "IPA MDCX ACK");
4397 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4398 "IPA DLCX ACK");
4399}
4400testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4401 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004402 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004403 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4404 vc_conn.done;
4405}
4406
Harald Welte9912eb52018-02-25 13:30:15 +01004407/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004408private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004409 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4410 "IPA CRCX NACK");
4411}
4412testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4413 var ConnHdlrPars pars;
4414 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004415 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004416
4417 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4418 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4419 vc_conn.done;
4420
4421 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4422 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4423 vc_conn.done;
4424}
4425
Harald Weltea3f1df92018-02-25 12:49:55 +01004426
Harald Welte883340c2018-02-28 18:59:29 +01004427/***********************************************************************
4428 * PCU Socket related tests
4429 ***********************************************************************/
4430
Harald Welte07bd2d22019-05-25 11:03:30 +02004431/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004432friend 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 +01004433runs on test_CT {
4434 timer T := 3.0;
4435
4436 /* we don't expect any RTS.req before PDCH are active */
4437 T.start;
4438 alt {
4439 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004440 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004441 }
4442 [] PCU.receive { repeat; }
4443 [] T.timeout { }
4444 }
4445
4446 /* Send PDCH activate request for known PDCH timeslot */
4447 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4448
4449 /* we now expect RTS.req for this timeslot (only) */
4450 T.start;
4451 alt {
4452 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4453 setverdict(pass);
4454 }
4455 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4456 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004457 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004458 }
4459 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004461 }
4462 [] PCU.receive { repeat; }
4463 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004465 }
4466 [not exp_success] T.timeout {
4467 setverdict(pass);
4468 }
4469 }
4470}
4471
Harald Welte07bd2d22019-05-25 11:03:30 +02004472/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004473friend 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 +01004474runs on test_CT {
4475 timer T := 3.0;
4476
4477 /* Send PDCH activate request for known PDCH timeslot */
4478 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 +02004479 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4480 * when it will actually have been executed in the BTS */
4481 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004482 PCU.clear;
4483 /* we now expect no RTS.req for this timeslot */
4484 T.start;
4485 alt {
4486 [] 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 +02004487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004488 }
4489 [] PCU.receive { repeat; }
4490 [] T.timeout {
4491 setverdict(pass);
4492 }
4493 }
4494}
4495
Harald Weltead033dc2019-05-25 17:28:16 +02004496friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004497 f_init();
4498 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4499}
4500
Harald Welte883340c2018-02-28 18:59:29 +01004501/* PDCH activation via PCU socket; check for presence of RTS.req */
4502testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004503 f_init_pcu_test();
4504
Harald Welte883340c2018-02-28 18:59:29 +01004505 f_TC_pcu_act_req(0, 0, 7, true);
4506}
4507
4508/* PDCH activation via PCU socket on non-PDCU timeslot */
4509testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004510 f_init_pcu_test();
4511
Harald Welte883340c2018-02-28 18:59:29 +01004512 f_TC_pcu_act_req(0, 0, 1, false);
4513}
4514
4515/* PDCH activation via PCU socket on wrong BTS */
4516testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004517 f_init_pcu_test();
4518
Harald Welte883340c2018-02-28 18:59:29 +01004519 f_TC_pcu_act_req(23, 0, 7, false);
4520}
4521
4522/* PDCH activation via PCU socket on wrong TRX */
4523testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004524 f_init_pcu_test();
4525
Harald Welte883340c2018-02-28 18:59:29 +01004526 f_TC_pcu_act_req(0, 23, 7, false);
4527}
4528
4529/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4530testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004531 f_init_pcu_test();
4532
Harald Welte883340c2018-02-28 18:59:29 +01004533 /* Activate PDCH */
4534 f_TC_pcu_act_req(0, 0, 7, true);
4535 f_sleep(1.0);
4536 /* and De-Activate again */
4537 f_TC_pcu_deact_req(0, 0, 7);
4538}
4539
4540/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4541testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004542 f_init_pcu_test();
4543
Harald Welte883340c2018-02-28 18:59:29 +01004544 f_TC_pcu_deact_req(0, 0, 1);
4545}
4546
4547/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4548testcase TC_pcu_ver_si13() runs on test_CT {
4549 const octetstring si13 := '00010203040506070909'O;
4550 var PCUIF_send_data sd;
4551 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004552 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004553
4554 /* Set SI13 via RSL */
4555 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004556
Harald Welte883340c2018-02-28 18:59:29 +01004557 T.start;
4558 alt {
4559 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4560 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4561 setverdict(pass);
4562 } else {
4563 repeat;
4564 }
4565 }
4566 [] PCU.receive { repeat; }
4567 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004569 }
4570 }
4571}
4572
4573private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4574
4575/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004576friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004577 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4578runs on test_CT
4579{
4580 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4581 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4582}
4583
4584/* 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 +02004585friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4586 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004587runs on test_CT
4588{
4589 var PCUIF_send_data sd;
4590
4591 timer T := 3.0;
4592 T.start;
4593 alt {
4594 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4595 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4596 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4597 sd.data.u.rts_req.fn, sapi, data);
4598 }
4599 [] PCU.receive { repeat; }
4600 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004601 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004602 }
4603 }
4604}
4605
4606/* Send DATA.req on invalid BTS */
4607testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004608 var TfiUsfArr tua := f_TfiUsfArrInit();
4609 var octetstring data := '0000'O & f_rnd_octstring(21);
4610
4611 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004612
Harald Welte883340c2018-02-28 18:59:29 +01004613 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004614 f_TfiUsfArrSet(tua, 7, 0);
4615 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4616 f_sleep(1.0);
4617
4618 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004619}
4620
4621/* Send DATA.req on invalid TRX */
4622testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004623 var TfiUsfArr tua := f_TfiUsfArrInit();
4624 var octetstring data := '0000'O & f_rnd_octstring(21);
4625
4626 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004627
Harald Welte883340c2018-02-28 18:59:29 +01004628 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004629 f_TfiUsfArrSet(tua, 7, 0);
4630 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4631 f_sleep(1.0);
4632
4633 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004634}
4635
4636/* Send DATA.req on invalid timeslot */
4637testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004638 var TfiUsfArr tua := f_TfiUsfArrInit();
4639 var octetstring data := '0000'O & f_rnd_octstring(21);
4640
4641 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004642
Harald Welte883340c2018-02-28 18:59:29 +01004643 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004644 f_TfiUsfArrSet(tua, 7, 0);
4645 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4646 f_sleep(1.0);
4647
4648 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004649}
4650
4651/* Send DATA.req on timeslot that hasn't been activated */
4652testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004653 var TfiUsfArr tua := f_TfiUsfArrInit();
4654 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004655
Harald Welte7162a612019-05-26 12:56:09 +02004656 f_virtphy_common();
4657
4658 f_TfiUsfArrSet(tua, 7, 0);
4659 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4660 f_sleep(1.0);
4661
4662 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004663}
4664
Harald Weltead033dc2019-05-25 17:28:16 +02004665private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004666 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4667 boolean wait_rts := true)
4668runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004669 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004670 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004671
4672 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004673 if (wait_rts) {
4674 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4675 } else {
4676 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4677 }
Harald Weltead033dc2019-05-25 17:28:16 +02004678
4679 T.start;
4680 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004681 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004682 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4683 setverdict(pass);
4684 }
Harald Welte7162a612019-05-26 12:56:09 +02004685 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4686 setverdict(fail, "Received unexpected ", rx_dl);
4687 }
Harald Weltead033dc2019-05-25 17:28:16 +02004688 [] L1CTL.receive {
4689 repeat;
4690 }
Harald Welte7162a612019-05-26 12:56:09 +02004691 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004692 setverdict(fail, "Timeout waiting for ", data);
4693 }
Harald Welte7162a612019-05-26 12:56:09 +02004694 [not expect_data] T.timeout {
4695 setverdict(pass);
4696 }
Harald Weltead033dc2019-05-25 17:28:16 +02004697 }
4698}
4699
4700private function f_disable_dynamic_ts() runs on test_CT
4701{
4702 f_init_vty_bsc();
4703 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4704 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4705 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4706 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004707 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004708}
4709
4710private function f_virtphy_common() runs on test_CT {
4711 f_disable_dynamic_ts();
4712 f_init_l1ctl();
4713 f_l1_tune(L1CTL);
4714}
4715
4716testcase TC_pcu_data_req_pdtch() runs on test_CT {
4717 var TfiUsfArr tua := f_TfiUsfArrInit();
4718 var octetstring data := '0000'O & f_rnd_octstring(21);
4719
4720 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004721
Harald Welte883340c2018-02-28 18:59:29 +01004722 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004723 f_TfiUsfArrSet(tua, 7, 0);
4724 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4725 f_sleep(1.0);
4726
4727 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004728}
4729
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004730/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004731testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004732 var TfiUsfArr tua := f_TfiUsfArrInit();
4733 var octetstring data := '0000'O & f_rnd_octstring(21);
4734
4735 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004736
Harald Welte883340c2018-02-28 18:59:29 +01004737 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004738 f_TfiUsfArrSet(tua, 7, 0);
4739 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4740 f_sleep(1.0);
4741
4742 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004743}
4744
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004745private function f_TC_pcu_ptcch_ul(uint16_t ra)
4746runs on test_CT {
4747 var template PCUIF_Message pcu_rach_ind;
4748 var PCUIF_send_data sd;
4749 var GsmFrameNumber fn;
4750 timer T;
4751
4752 /* Send an Access Burst on PTCCH/U over the Um-interface */
4753 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4754 chan_nr := ts_RslChanNr_PDCH(7),
4755 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4756
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004757 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4758 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004759
4760 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4761 T.start(52.0 * 4.615 / 1000.0);
4762 alt {
4763 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4764 log("Rx an Access Burst on the PCU interface: ", sd.data);
4765 setverdict(pass);
4766 T.stop;
4767 }
4768 [] PCU.receive { repeat; }
4769 [] T.timeout {
4770 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4771 /* Keep going, that's not the end of the world */
4772 }
4773 }
4774}
4775
4776testcase TC_pcu_ptcch() runs on test_CT {
4777 var L1ctlDlMessage dl;
4778 var octetstring data;
4779 timer T;
4780
4781 f_init_pcu_test();
4782 f_init_l1ctl();
4783 f_l1_tune(L1CTL);
4784
4785 /* Activate PDCH channel on TS7 */
4786 f_TC_pcu_act_req(0, 0, 7, true);
4787
4788 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004789 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004790 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004791 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004792 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004793
4794 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4795 for (var integer i := 0; i < 16; i := i + 1) {
4796 log("Sending an Access Burst towards the L1CTL interface");
4797 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4798 }
4799
4800 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4801 data := f_rnd_octstring(23);
4802
4803 /* Verify PTCCH/D: send a random data block, make sure it's received */
4804 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4805 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4806
4807 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4808 * let's give it more time in case if we miss the beginning. */
4809 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4810 alt {
4811 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4812 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4813 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4814 frame := data)) -> value dl {
4815 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4816 setverdict(pass);
4817 T.stop;
4818 }
4819 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4820 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4821 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4822 l2_data := data)) -> value dl {
4823 log("Rx PTCCH/D data block on L1CTL: ", dl);
4824 setverdict(pass);
4825 T.stop;
4826 }
4827 [] L1CTL.receive { repeat; }
4828 [] T.timeout {
4829 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4830 }
4831 }
4832}
4833
Harald Welte883340c2018-02-28 18:59:29 +01004834/* Send AGCH from PCU; check it appears on Um side */
4835testcase TC_pcu_data_req_agch() runs on test_CT {
4836 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004837 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004838 f_init_l1ctl();
4839 f_l1_tune(L1CTL);
4840
4841 f_TC_pcu_act_req(0, 0, 7, true);
4842 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4843
4844 T.start;
4845 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004846 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004847 setverdict(pass);
4848 }
4849 [] L1CTL.receive { repeat; }
4850 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004852 }
4853 }
4854}
4855
Harald Welte928622b2019-05-26 13:22:59 +02004856/* Send AGCH from PCU; check it appears on Um side */
4857testcase TC_pcu_data_req_pch() runs on test_CT {
4858 timer T := 3.0;
4859 f_init_pcu_test();
4860 f_init_l1ctl();
4861 f_l1_tune(L1CTL);
4862
4863 f_TC_pcu_act_req(0, 0, 7, true);
4864 /* three characters prefix: last 3 digits of IMSI as ASCII */
4865 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4866
4867 T.start;
4868 alt {
4869 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4870 setverdict(pass);
4871 }
4872 [] L1CTL.receive { repeat; }
4873 [] T.timeout {
4874 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4875 }
4876 }
4877}
4878
Harald Welte883340c2018-02-28 18:59:29 +01004879/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4880testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4881 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004882 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004883 f_init_l1ctl();
4884 f_l1_tune(L1CTL);
4885
4886 /* append 3 last imsi digits so BTS can compute pagng group */
4887 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4888
4889 timer T := 0.5;
4890 T.start;
4891 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004892 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004893 /* TODO: verify paging group */
4894 setverdict(pass);
4895 }
4896 [] L1CTL.receive { repeat; }
4897 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004899 }
4900 }
4901}
4902
4903/* Send RACH from Um side, expect it to show up on PCU socket */
4904testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004905 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004906 f_init_l1ctl();
4907 f_l1_tune(L1CTL);
4908
4909 var GsmFrameNumber fn_last := 0;
4910 for (var integer i := 0; i < 1000; i := i+1) {
4911 var OCT1 ra := f_rnd_ra_ps();
4912 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4913 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004914 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004915 }
4916 fn_last := fn;
4917
4918 timer T := 2.0;
4919 T.start;
4920 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004921 [] 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 +01004922 T.stop;
4923 }
4924 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004925 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004926 }
4927 [] PCU.receive { repeat; }
4928 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004930 }
4931 }
4932 }
4933 setverdict(pass);
4934}
4935
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004936/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4937 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4938testcase TC_pcu_ext_rach_content() runs on test_CT {
4939 var template PCUIF_Message pcu_rach_ind;
4940 var GsmFrameNumber fn_last := 0;
4941 var L1ctlRachSynchSeq synch_seq;
4942 var PCUIF_BurstType pcu_bt;
4943 var GsmFrameNumber fn;
4944 var BIT11 ra11;
4945
4946 f_init_pcu_test();
4947 f_init_l1ctl();
4948 f_l1_tune(L1CTL);
4949
4950 for (var integer i := 0; i < 1000; i := i+1) {
4951 /* We need to test both TS1 & TS2 */
4952 if (i rem 2 == 0) {
4953 synch_seq := RACH_SYNCH_SEQ_TS1;
4954 pcu_bt := BURST_TYPE_1;
4955 } else {
4956 synch_seq := RACH_SYNCH_SEQ_TS2;
4957 pcu_bt := BURST_TYPE_2;
4958 }
4959
4960 ra11 := f_rnd_ra11_ps();
4961 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4962 if (fn == fn_last) {
4963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4964 "Two RACH in same FN?!?");
4965 }
4966 fn_last := fn;
4967
4968 /* Compose the expected message */
4969 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004970 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004971 ra := bit2int(ra11),
4972 is_11bit := 1,
4973 burst_type := pcu_bt,
4974 fn := fn);
4975
4976 timer T := 2.0;
4977 T.start;
4978 alt {
4979 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4980 T.stop;
4981 }
4982 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4984 }
4985 [] PCU.receive { repeat; }
4986 [] T.timeout {
4987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4988 }
4989 }
4990 }
4991 setverdict(pass);
4992}
4993
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004994private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4995runs on test_CT {
4996 var template PCUIF_send_data sdt;
4997 var PCUIF_send_data sd;
4998 var int16_t lqual_cb;
4999 timer T := 1.0;
5000
5001 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5002 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5003
5004 /* Send a random PDTCH frame over Um */
5005 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5006 '0000'O & f_rnd_octstring(21)));
5007
5008 T.start;
5009 alt {
5010 /* If expected link quality is above the threshold */
5011 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5012 lqual_cb := sd.data.u.data_ind.lqual_cb;
5013 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5014
5015 /* Make sure the actual link quality matches the expected value */
5016 if (not match(lqual_cb, lqual_cb_exp)) {
5017 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5018 "expected value ", lqual_cb_exp));
5019 } else {
5020 setverdict(pass);
5021 }
5022 }
5023 /* If expected link quality is below the threshold */
5024 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5025 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5026 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5027 }
5028 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5029 [] PCU.receive { repeat; }
5030 [lqual_cb_exp < thresh] T.timeout {
5031 log("Rx nothing, as expected");
5032 setverdict(pass);
5033 }
5034 [lqual_cb_exp >= thresh] T.timeout {
5035 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5036 "Timeout waiting for PCUIF_DATA.ind");
5037 }
5038 }
5039}
5040
5041/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5042testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
5043 f_init_pcu_test();
5044 PCU.clear;
5045
5046 f_init_l1ctl();
5047 f_l1_tune(L1CTL);
5048
5049 /* Activate a PDCH channel on TS7 */
5050 f_TC_pcu_act_req(0, 0, 7, true);
5051
5052 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005053 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005054 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005055 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005056 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005057
5058 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5059 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5060 var TrxcMessage ret;
5061
5062 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5063 valueof(ts_TRXC_FAKE_CI(i)));
5064
5065 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5066 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5067 }
5068}
5069
Harald Welte883340c2018-02-28 18:59:29 +01005070/* Send PAGING via RSL, expect it to shw up on PCU socket */
5071testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005072 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01005073
5074 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005075 var MobileIdentityLV mi_lv;
5076 var octetstring mi_lv_enc;
5077 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005078 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005079
Harald Welte883340c2018-02-28 18:59:29 +01005080 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005081 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005082 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005083 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005084 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005085
5086 /* Fancy encoding for PCUIF */
5087 mi_lv := valueof(ts_MI_LV(mi));
5088 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5089 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005090
5091 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005092 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005093 T.start;
5094 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005095 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005096 }
5097 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005098 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005099 }
5100 [] PCU.receive { repeat; }
5101 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005102 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005103 }
5104 }
5105 }
5106 setverdict(pass);
5107}
5108
Harald Welted66c9b82019-05-25 09:03:15 +02005109/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5110testcase TC_pcu_time_ind() runs on test_CT {
5111 var PCUIF_send_data pcu_sd;
5112 var integer num_time_ind := 0;
5113 var integer first_fn, last_fn;
5114 var float test_duration := 5.0;
5115 timer T;
5116
5117 f_init_pcu_test();
5118 f_TC_pcu_act_req(0, 0, 7, true);
5119
5120 PCU.clear;
5121 T.start(test_duration);
5122 alt {
5123 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5124 num_time_ind := num_time_ind + 1;
5125 if (not isbound(first_fn)) {
5126 first_fn := pcu_sd.data.u.time_ind.fn;
5127 }
5128 last_fn := pcu_sd.data.u.time_ind.fn;
5129 repeat;
5130 }
5131 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5132 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5133 repeat;
5134 }
5135 [] PCU.receive {
5136 repeat;
5137 }
5138 [] T.timeout {}
5139 }
5140 var integer fn_expired := last_fn - first_fn;
5141 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5142
5143 /* verify the number of frames expired matches our expectation */
5144 const float c_GSM_FN_DURATION_MS := 4.61538;
5145 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005146 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005147 if (not match(fn_expired, t_fn_expected)) {
5148 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5149 }
5150
5151 /* There are three TIME.ind in every fn MOD 13 */
5152 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5153 /* Add some tolerance */
5154 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5155 if (not match(num_time_ind, t_time_ind_exp)) {
5156 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5157 }
5158
5159 setverdict(pass);
5160}
5161
Harald Welte4832c862019-05-25 14:57:18 +02005162/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5163testcase TC_pcu_rts_req() runs on test_CT {
5164 var PCUIF_send_data pcu_sd;
5165 var integer first_fn, last_fn;
5166 var integer num_rts_pdtch := 0;
5167 var integer num_rts_ptcch := 0;
5168 var float test_duration := 5.0;
5169 timer T;
5170
5171 f_init_pcu_test();
5172 f_TC_pcu_act_req(0, 0, 7, true);
5173
5174 PCU.clear;
5175 T.start(test_duration);
5176 alt {
5177 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5178 -> value pcu_sd {
5179 num_rts_pdtch := num_rts_pdtch + 1;
5180 if (not isbound(first_fn)) {
5181 first_fn := pcu_sd.data.u.rts_req.fn;
5182 }
5183 last_fn := pcu_sd.data.u.rts_req.fn;
5184 repeat;
5185 }
5186 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5187 -> value pcu_sd {
5188 num_rts_ptcch := num_rts_ptcch + 1;
5189 if (not isbound(first_fn)) {
5190 first_fn := pcu_sd.data.u.rts_req.fn;
5191 }
5192 last_fn := pcu_sd.data.u.rts_req.fn;
5193 repeat;
5194 }
5195 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5196 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5197 repeat;
5198 }
5199 [] PCU.receive {
5200 repeat;
5201 }
5202 [] T.timeout {}
5203 }
5204 var integer fn_expired := last_fn - first_fn;
5205 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5206 ", num_rts_ptcch=", num_rts_ptcch);
5207
5208 /* verify the number of frames expired matches our expectation */
5209 const float c_GSM_FN_DURATION_MS := 4.61538;
5210 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005211 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005212 if (not match(fn_expired, t_fn_expected)) {
5213 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5214 }
5215
5216 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5217 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5218 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5219 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5220 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5221 t_ptcch_exp);
5222 }
5223
5224 /* We have 12 PDTCH blocks every 52-multiframe */
5225 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5226 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5227 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5228 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5229 t_pdtch_exp);
5230 }
5231
5232 setverdict(pass);
5233}
5234
Harald Welte07bd2d22019-05-25 11:03:30 +02005235/* test for generating Abis side OML ALERT from the PCU */
5236testcase TC_pcu_oml_alert() runs on test_CT {
5237 var PCUIF_send_data pcu_sd;
5238 var integer num_time_ind := 0;
5239 var integer first_fn, last_fn;
5240 var float test_duration := 5.0;
5241 timer T;
5242
5243 f_init_pcu_test();
5244 f_TC_pcu_act_req(0, 0, 7, true);
5245
5246 /* re-connect CTRL port from BTS to BSC */
5247 f_ipa_ctrl_stop();
5248 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5249
5250 /* Send that OML Alert */
5251 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5252
5253 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5254 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5255 setverdict(pass);
5256}
5257
Harald Welteeaa9a862019-05-26 23:01:08 +02005258/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5259private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5260 var PCUIF_Message first_info;
5261 var integer pcu_conn_id := -1;
5262 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5263 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5264 var OCT4 tlli := '01020304'O;
5265 var OCT1 cause := '23'O;
5266 timer T := 5.0;
5267
5268 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5269
5270 f_l1_tune(L1CTL);
5271 RSL.clear;
5272
5273 f_est_dchan();
5274 L1CTL.clear;
5275
5276 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5277
5278 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5279 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5280 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5281
5282 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5283 T.start;
5284 alt {
5285 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5286 setverdict(pass);
5287 }
5288 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5289 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5290 }
5291 [] PCU.receive {
5292 repeat;
5293 }
5294 [] T.timeout {
5295 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5296 }
5297 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005298
5299 /* release the channel */
5300 f_rsl_chan_deact();
5301 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5302 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005303}
5304testcase TC_pcu_rr_suspend() runs on test_CT {
5305 var ConnHdlrPars pars;
5306 var ConnHdlr vc_conn;
5307
5308 f_init();
5309
5310 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5311 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5312 vc_conn.done;
5313}
Harald Welte07bd2d22019-05-25 11:03:30 +02005314
Harald Weltea2e0e942019-05-27 18:12:53 +02005315/* Ensure that PCUIF socket can accept only a single connection */
5316testcase TC_pcu_socket_connect_multi() runs on test_CT {
5317 timer T := 5.0;
5318
5319 /* this (among other things) establishes the first connection to the PCUIF socket */
5320 f_init();
5321
5322 /* try to establish a second connection, expect it to fail */
5323 PCU.send(UD_connect:{mp_pcu_socket, -1});
5324 T.start;
5325 alt {
5326 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5327 setverdict(pass);
5328 }
5329 [] PCU.receive(UD_connect_result:?) {
5330 setverdict(fail, "Unexpected unix domain connect result");
5331 }
5332 [] T.timeout {
5333 setverdict(pass);
5334 }
5335 }
5336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5337}
5338
Harald Weltec8effb72019-05-27 18:23:04 +02005339/* Ensure that PCUIF socket can disconnect + reconnect */
5340testcase TC_pcu_socket_reconnect() runs on test_CT {
5341 /* this (among other things) establishes the first connection to the PCUIF socket */
5342 f_init();
5343
5344 f_sleep(1.0);
5345
5346 f_pcuif_close(PCU, g_pcu_conn_id);
5347 g_pcu_conn_id := -1;
5348
5349 f_sleep(1.0);
5350
5351 /* re-connect */
5352 PCU.clear;
5353 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5354 setverdict(pass);
5355
5356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5357}
5358
Harald Weltebe030482019-05-27 22:29:35 +02005359/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005360private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5361runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005362 var L1ctlDlMessage l1_dl;
5363 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005364 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005365 timer T := 5.0;
5366 T.start;
5367 alt {
5368 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005369 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5370 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005371 repeat;
5372 }
5373 }
5374 [] pt.receive {
5375 repeat;
5376 }
5377 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5379 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005380 }
5381 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005382 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005383}
5384
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005385/* Check if GPRS Indicator is present in RR System Information of a given type */
5386private function f_si_has_gprs_indicator(RrMessageType si_type)
5387runs on test_CT return boolean {
5388 var SystemInformation si := f_get_si(L1CTL, si_type);
5389
5390 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005391 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005392 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005393 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005394 }
5395
5396 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5397 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005398}
5399
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005400/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5401private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5402runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005403 /* don't call f_init() as this would connect PCU socket */
5404 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005405
5406 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005407 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005408 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005409
5410 f_init_l1ctl();
5411 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005412 f_sleep(2.0);
5413 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005414
5415 if (f_si_has_gprs_indicator(si_type)) {
5416 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005417 } else {
5418 setverdict(pass);
5419 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005420
Harald Weltebe030482019-05-27 22:29:35 +02005421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5422}
5423
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005424testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5425 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5426}
Harald Weltebe030482019-05-27 22:29:35 +02005427
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005428testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5429 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5430}
5431
5432/* Ensure that GPRS capability is advertised after PCU socket connect */
5433private function f_TC_pcu_socket_connect(RrMessageType si_type)
5434runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005435 /* this (among other things) establishes the first connection to the PCUIF socket */
5436 f_init();
5437 f_init_l1ctl();
5438 f_l1_tune(L1CTL);
5439
5440 f_sleep(2.0);
5441 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005442
5443 if (not f_si_has_gprs_indicator(si_type)) {
5444 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005445 } else {
5446 setverdict(pass);
5447 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005448
Harald Weltebe030482019-05-27 22:29:35 +02005449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5450}
5451
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005452testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5453 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5454}
Harald Weltebe030482019-05-27 22:29:35 +02005455
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005456testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5457 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5458}
5459
5460/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5461private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5462runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005463 /* this (among other things) establishes the first connection to the PCUIF socket */
5464 f_init();
5465 f_init_l1ctl();
5466 f_l1_tune(L1CTL);
5467
5468 f_pcuif_close(PCU, g_pcu_conn_id);
5469 g_pcu_conn_id := -1;
5470
5471 f_sleep(1.0);
5472
5473 /* re-connect */
5474 PCU.clear;
5475 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5476
5477 f_sleep(2.0);
5478 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005479
5480 if (f_si_has_gprs_indicator(si_type)) {
5481 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005482 } else {
5483 setverdict(pass);
5484 }
5485
5486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5487}
5488
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005489testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5490 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5491}
5492
5493testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5494 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5495}
5496
Oliver Smithf5239c72019-08-28 10:01:25 +02005497/* 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) */
5498testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5499 var SystemInformation si3 := valueof(ts_SI3_default);
5500
5501 f_init();
5502
Harald Welte76220222020-10-11 20:32:44 +02005503 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5504 * information */
5505 timer T := 2.0;
5506 T.start;
5507 alt {
5508 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5509 [] T.timeout {}
5510 }
5511
Oliver Smithf5239c72019-08-28 10:01:25 +02005512 /* Verify cell_id */
5513 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5514 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5515 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005516 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5517 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5518 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005519 }
5520
5521 /* Verify LAC */
5522 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5523 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5524 if (lac_si3 != lac_pcu) {
5525 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5526 }
5527
5528 setverdict(pass);
5529}
Harald Welted66c9b82019-05-25 09:03:15 +02005530
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005531/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5532testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5533 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005534 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005535
5536 f_init();
5537
5538 info_ind := g_pcu_last_info.u.info_ind;
5539
5540 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5541 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5542 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5543 /* Skip inactive timeslots */
5544 continue;
5545 }
5546
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005547 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005548 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005549 else
5550 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005551
5552 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005553 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005554 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005555 hsn := fhp.maio_hsn.hsn,
5556 maio := fhp.maio_hsn.maio,
5557 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005558 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005559 } else {
5560 tr_ts := tr_PCUIF_InfoTrxTsH0;
5561 }
5562
5563 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5564 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5565 if (not match(ts, tr_ts)) {
5566 setverdict(fail, "Hopping parameters do not match: ",
5567 "received ", ts, " vs expected ", tr_ts);
5568 } else {
5569 setverdict(pass);
5570 }
5571 }
5572 }
5573}
5574
Alexander Couzens5283f552020-07-28 15:39:04 +02005575/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5576testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5577 f_init_vty_bsc();
5578 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5579 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5580
5581 f_init();
5582
5583 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5584 if (not ischosen(remote_addr.v10)) {
5585 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5586 log2str("Unexpected remote_addr: ", remote_addr));
5587 }
5588
5589 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5590 setverdict(fail, "Received address family is not IPv4");
5591 }
5592
5593 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5594 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5595 }
5596
5597 setverdict(pass);
5598}
5599
5600/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5601testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5602 f_init_vty_bsc();
5603 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5604
5605 f_init();
5606
5607 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5608 if (not ischosen(remote_addr.v10)) {
5609 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5610 log2str("Unexpected remote_addr: ", remote_addr));
5611 }
5612
5613 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5614 setverdict(fail, "Received address family is not IPv6");
5615 }
5616
5617 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5618 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5619 }
5620
5621 setverdict(pass);
5622}
5623
Harald Welte3d04ae62018-04-04 20:29:05 +02005624/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005625 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005626 ***********************************************************************/
5627
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005628private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5629 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005630runs on ConnHdlr {
5631 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005632
5633 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005634 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005635 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5636 repeat;
5637 }
5638 }
5639}
5640
5641private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5642runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005643 /* Expect BTS to immediately acknowledge activation as PDCH */
5644 PCU.clear;
5645 f_rsl_chan_act(g_pars.chan_mode);
5646 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005647 timer T_wait := 2.0;
5648 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005649 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005650 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005651 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005652 [] T_wait.timeout {
5653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5654 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5655 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005656 }
5657 /* try to activate this PDCH from the PCU point of view */
5658 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5659 /* FIXME: is there a response? */
5660}
5661
5662private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5663runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005664 /* Send RSL CHAN REL (deactivate) */
5665 PCU.clear;
5666 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5667 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005668 timer T_wait := 2.0;
5669 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005670 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005671 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005672 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005673 [] T_wait.timeout {
5674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5675 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5676 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005677 }
5678 /* Emulate PCU asking BTS to deactivate PDCH */
5679 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5680 alt {
5681 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5682 setverdict(pass);
5683 }
5684 [] RSL.receive { repeat; }
5685 }
5686}
5687
5688/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005689private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005690 var PCUIF_Message first_info;
5691 var integer ts_nr := g_chan_nr.tn;
5692 var integer trx_nr := 0;
5693 var integer bts_nr := 0;
5694 var integer pcu_conn_id := -1;
5695
5696 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5697
5698 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5699 f_sleep(3.0);
5700 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5701 setverdict(pass);
5702}
5703testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5704 var ConnHdlrPars pars;
5705 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005706 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005707
5708 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5709 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5710 vc_conn.done;
5711}
5712
5713/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005714private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005715 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005716 var integer pcu_conn_id := -1;
5717
5718 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5719
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005720 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5721 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5722 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005723 setverdict(pass);
5724}
5725testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5726 var ConnHdlrPars pars;
5727 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005728 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005729
5730 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5731 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5732 vc_conn.done;
5733}
5734
5735/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005736private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005737 var PCUIF_Message first_info;
5738 var integer ts_nr := g_chan_nr.tn;
5739 var integer trx_nr := 0;
5740 var integer bts_nr := 0;
5741 var integer pcu_conn_id := -1;
5742
5743 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5744
5745 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005746 /* Send a second Chan Activ and expect it to be NACKed */
5747 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5748 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005749 setverdict(pass);
5750}
5751testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5752 var ConnHdlrPars pars;
5753 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005754 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005755
5756 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5757 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5758 vc_conn.done;
5759}
5760
5761/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005762private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005763 var PCUIF_Message first_info;
5764 var integer ts_nr := g_chan_nr.tn;
5765 var integer trx_nr := 0;
5766 var integer bts_nr := 0;
5767 var integer pcu_conn_id := -1;
5768 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5769
5770 /* register for the TCH/F channel number */
5771 f_rslem_register(0, chan_nr);
5772
5773 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5774
5775 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5776 "RSL CHAN ACT");
5777 setverdict(pass);
5778}
5779testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5780 var ConnHdlrPars pars;
5781 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005782 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005783
5784 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5785 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5786 vc_conn.done;
5787}
5788
5789/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005790private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005791 var PCUIF_Message first_info;
5792 var integer ts_nr := g_chan_nr.tn;
5793 var integer trx_nr := 0;
5794 var integer bts_nr := 0;
5795 var integer pcu_conn_id := -1;
5796 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5797 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5798
5799 /* register for the TCH/H channel numbers */
5800 f_rslem_register(0, chan_nr[0]);
5801 f_rslem_register(0, chan_nr[1]);
5802
5803 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5804
5805 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5806 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5807 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5808 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5809 setverdict(pass);
5810}
5811testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5812 var ConnHdlrPars pars;
5813 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005814 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005815
5816 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5817 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5818 vc_conn.done;
5819}
5820
Harald Welte9bbbfb52018-04-05 09:33:19 +02005821/***********************************************************************
5822 * IPA Style Dynamic Timeslot Support
5823 ***********************************************************************/
5824
5825private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5826runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005827 /* Expect BTS to immediately acknowledge activation as PDCH */
5828 PCU.clear;
5829 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5830 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005831 timer T_wait := 2.0;
5832 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005833 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005834 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005835 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005836 [] T_wait.timeout {
5837 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5838 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5839 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005840 }
5841 /* try to activate this PDCH from the PCU point of view */
5842 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5843 /* FIXME: is there a response? */
5844
5845 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5846}
5847
5848private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5849runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005850 /* Send RSL CHAN REL (deactivate) */
5851 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5852 PCU.clear;
5853 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005854 timer T_wait := 2.0;
5855 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005856 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005857 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005858 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005859 [] T_wait.timeout {
5860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5861 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5862 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005863 }
5864 /* Emulate PCU asking BTS to deactivate PDCH */
5865 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5866 alt {
5867 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5868 setverdict(pass);
5869 }
5870 [] RSL.receive { repeat; }
5871 }
5872}
5873
5874/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005875private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005876 var PCUIF_Message first_info;
5877 var integer ts_nr := g_chan_nr.tn;
5878 var integer trx_nr := 0;
5879 var integer bts_nr := 0;
5880 var integer pcu_conn_id := -1;
5881
5882 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5883
5884 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5885 f_sleep(3.0);
5886 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5887
5888 setverdict(pass);
5889
5890}
5891testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5892 var ConnHdlrPars pars;
5893 var ConnHdlr vc_conn;
5894 f_init();
5895
5896 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5897 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5898 vc_conn.done;
5899}
5900
5901/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005902private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005903 var PCUIF_Message first_info;
5904 var integer ts_nr := g_chan_nr.tn;
5905 var integer trx_nr := 0;
5906 var integer bts_nr := 0;
5907 var integer pcu_conn_id := -1;
5908
5909 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5910
5911 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5912 "RSL CHAN ACT");
5913 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5914 "RF CHAN REL", true);
5915 setverdict(pass);
5916}
5917testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5918 var ConnHdlrPars pars;
5919 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005920 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005921
5922 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5923 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5924 vc_conn.done;
5925}
5926
5927/* 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 +07005928private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005929 var PCUIF_Message first_info;
5930 var integer ts_nr := g_chan_nr.tn;
5931 var integer trx_nr := 0;
5932 var integer bts_nr := 0;
5933 var integer pcu_conn_id := -1;
5934
5935 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5936
5937 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5938 "RSL CHAN ACT");
5939
5940 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5941 alt {
5942 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5943 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005945 }
5946 [] RSL.receive { repeat; }
5947 }
5948
5949 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5950 "RF CHAN REL", true);
5951 setverdict(pass);
5952}
5953testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5954 var ConnHdlrPars pars;
5955 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005956 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005957
5958 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5959 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5960 vc_conn.done;
5961}
5962
5963/* 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 +07005964private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005965 var PCUIF_Message first_info;
5966 var integer ts_nr := g_chan_nr.tn;
5967 var integer trx_nr := 0;
5968 var integer bts_nr := 0;
5969 var integer pcu_conn_id := -1;
5970
5971 /* register for the TCH/F channel number */
5972 f_rslem_register(0, g_chan_nr);
5973
5974 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5975
5976 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5977
5978 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5979 "RSL CHAN ACT");
5980
5981 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5982
5983 setverdict(pass);
5984}
5985testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5986 var ConnHdlrPars pars;
5987 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005988 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005989
5990 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5991 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5992 vc_conn.done;
5993}
5994
5995
Harald Welte0472ab42018-03-12 15:02:26 +01005996/***********************************************************************
5997 * LAPDm / RLL related
5998 ***********************************************************************/
5999
6000private function f_tx_lapdm(template (value) LapdmFrame l,
6001 template (value) RslLinkId link_id) runs on ConnHdlr {
6002 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006003 var template (value) SacchL1Header l1h;
6004
6005 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006006 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006007 /* Compose dummy L1 header */
6008 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6009 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 +02006010 } else {
6011 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006012 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 +01006013 }
Harald Welte0472ab42018-03-12 15:02:26 +01006014}
6015
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006016private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006017 uint3_t sapi,
6018 RslLinkId link_id,
6019 octetstring l3,
6020 boolean exp
6021}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006022private type record of RllTestCase RllTestCases;
6023private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
6024 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006025 sapi := sapi,
6026 link_id := id,
6027 l3 := l3,
6028 exp := exp
6029}
6030
6031/* execute the same callback function with a set of different parameters (tcs) on a
6032 * variety of logical channels */
6033private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6034 var ConnHdlrPars pars;
6035 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006036 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006037
6038 /* test on each of the channels we have */
6039 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6040 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6041
6042 /* test each of the test cases on the current channel */
6043 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6044 pars.spec.rll := tcs[j];
6045 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6046 vc_conn := f_start_handler(fn, pars);
6047 vc_conn.done;
6048 }
6049 }
6050
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006051 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006052}
6053
6054/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6055private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6056 var RllTestCase tc := g_pars.spec.rll;
6057 timer T := 3.0;
6058
6059 f_l1_tune(L1CTL);
6060 RSL.clear;
6061
6062 /* activate the logical channel */
6063 f_est_dchan();
6064 L1CTL.clear;
6065
6066 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6067 T.start;
6068 alt {
6069 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6070 if (tc.exp) {
6071 setverdict(pass);
6072 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006074 }
6075 }
6076 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6077 if (tc.exp) {
6078 setverdict(pass);
6079 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006081 }
6082 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006083 /* We also expect to receive the measurements */
6084 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006085 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006087 }
6088 [not tc.exp] T.timeout {
6089 setverdict(pass);
6090 }
6091 }
6092
6093 f_rsl_chan_deact();
6094 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6095 f_rslem_unregister(0, g_chan_nr);
6096}
6097testcase TC_rll_est_ind() runs on test_CT {
6098 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006099 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006100 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006101 /* normal SAPI0 establishment */
6102 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006103 /* SAPI 3 doesn't support contention resolution */
6104 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6105 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6106 /* normal SAPI3 establishment on main DCCH */
6107 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6108 /* normal SAPI3 establishment on SACCH */
6109 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6110 };
6111 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6112}
6113
6114/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6115private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6116 var RllTestCase tc := g_pars.spec.rll;
6117 var L1ctlDlMessage dl;
6118 timer T := 3.0;
6119
6120 f_l1_tune(L1CTL);
6121 RSL.clear;
6122
6123 /* activate the logical channel */
6124 f_est_dchan();
6125 L1CTL.clear;
6126
6127 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6128 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6129 T.start;
6130 alt {
6131 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6132 var LapdmFrame lapdm;
6133 var octetstring l2 := dl.payload.data_ind.payload;
6134 if (dl.dl_info.link_id.c == SACCH) {
6135 /* remove L1 header */
6136 l2 := substr(l2, 2, lengthof(l2)-2);
6137 }
6138 lapdm.ab := dec_LapdmFrameAB(l2);
6139 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6140 setverdict(pass);
6141 } else {
6142 repeat;
6143 }
6144 }
6145 [] L1CTL.receive { repeat; }
6146 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006148 }
6149 }
6150
6151 f_rsl_chan_deact();
6152 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6153 f_rslem_unregister(0, g_chan_nr);
6154}
6155testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6156 var RllTestCases tcs := {
6157 /* normal SAPI3 establishment on main DCCH */
6158 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6159 };
6160 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6161}
6162testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6163 var RllTestCases tcs := {
6164 /* normal SAPI3 establishment on SACCH */
6165 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6166 }
6167 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6168}
6169
6170/* altstep to receive a LAPDm frame matching the given template */
6171private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6172 var L1ctlDlMessage dl;
6173 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6174 var LapdmFrame lapdm;
6175 var octetstring l2 := dl.payload.data_ind.payload;
6176 if (dl.dl_info.link_id.c == SACCH) {
6177 /* remove L1 header */
6178 l2 := substr(l2, 2, lengthof(l2)-2);
6179 }
6180 if (ischosen(exp.ab)) {
6181 lapdm.ab := dec_LapdmFrameAB(l2);
6182 } else if (ischosen(exp.b4)) {
6183 lapdm.b4 := dec_LapdmFrameB4(l2);
6184 } else if (ischosen(exp.bbis)) {
6185 lapdm.bbis := dec_LapdmFrameBbis(l2);
6186 }
6187 log("Rx LAPDm ", lapdm);
6188 if (match(lapdm, exp)) {
6189 setverdict(pass);
6190 } else {
6191 repeat;
6192 }
6193 }
6194 [] L1CTL.receive { repeat; }
6195}
6196private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6197 timer T := t;
6198 T.start;
6199 alt {
6200 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006201 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006202 }
6203 [] as_l1_exp_lapdm(exp);
6204 }
6205}
6206
6207/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6208private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6209 /* send SABM from MS -> BTS */
6210 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6211 /* expect RLL EST IND on Abis */
6212 alt {
6213 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6214 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6215 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006216 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006217 }
6218 [] RSL.receive { repeat; }
6219 }
6220 /* expect UA from BTS -> MS */
6221 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6222}
6223
6224/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6225private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6226 var RllTestCase tc := g_pars.spec.rll;
6227
6228 f_l1_tune(L1CTL);
6229 RSL.clear;
6230
6231 /* activate the logical channel */
6232 f_est_dchan();
6233 L1CTL.clear;
6234
6235 /* first establish the link-layer */
6236 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6237
6238 /* then send the DISC */
6239 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6240 /* ... and expect the REL IND on the RSL side */
6241 alt {
6242 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6243 setverdict(pass);
6244 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006245 /* We also expect to receive the measurements */
6246 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006247 }
6248
6249 /* release the channel */
6250 f_rsl_chan_deact();
6251 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6252 f_rslem_unregister(0, g_chan_nr);
6253}
6254testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6255 var RllTestCases tcs := {
6256 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6257 };
6258 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6259}
6260
6261testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6262 var RllTestCases tcs := {
6263 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6264 };
6265 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6266}
6267testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6268 var RllTestCases tcs := {
6269 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6270 };
6271 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6272}
6273testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6274 var RllTestCases tcs := {
6275 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6276 };
6277 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6278}
6279
6280/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6281private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6282 var RllTestCase tc := g_pars.spec.rll;
6283 f_l1_tune(L1CTL);
6284 RSL.clear;
6285
6286 /* activate the logical channel */
6287 f_est_dchan();
6288 L1CTL.clear;
6289
6290 /* first establish the link-layer */
6291 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6292
6293 /* then send the REL REQ via RSL */
6294 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6295 /* ... and expect the DISC on the Um side */
6296 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006297 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006298 /* FIXME: send a UA in resposne to the DISC */
6299 }
6300 }
6301
6302 /* release the channel */
6303 f_rsl_chan_deact();
6304 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6305 f_rslem_unregister(0, g_chan_nr);
6306}
6307testcase TC_rll_rel_req() runs on test_CT {
6308 var RllTestCases tcs := {
6309 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6310 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6311 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6312 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6313 };
6314 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6315}
6316
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006317/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006318testcase TC_rll_data_req() runs on test_CT {
6319}
6320
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006321/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006322testcase TC_rll_data_ind() runs on test_CT {
6323}
6324
6325/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6326private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6327 var RllTestCase tc := g_pars.spec.rll;
6328
6329 f_l1_tune(L1CTL);
6330 RSL.clear;
6331
6332 f_est_dchan();
6333 L1CTL.clear;
6334
6335 /* Send UNITDATA REQ on RSL side */
6336 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6337 /* Expect it to arrive on the other side */
6338 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006339 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006340 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006341 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006342 }
6343
6344 /* release the channel */
6345 f_rsl_chan_deact();
6346 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6347 f_rslem_unregister(0, g_chan_nr);
6348}
6349testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6350 var octetstring l3 := f_rnd_octstring(15);
6351 var RllTestCases tcs := {
6352 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6353 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6354 };
6355 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6356}
6357testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6358 var octetstring l3 := f_rnd_octstring(19);
6359 var RllTestCases tcs := {
6360 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6361 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6362 };
6363 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6364}
6365
6366/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6367private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6368 var RllTestCase tc := g_pars.spec.rll;
6369
6370 f_l1_tune(L1CTL);
6371 RSL.clear;
6372
6373 f_est_dchan();
6374 L1CTL.clear;
6375
6376 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006377 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006378 /* Expdct RLL UNITDATA IND on RSL side */
6379 alt {
6380 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6381 setverdict(pass);
6382 }
6383 [] RSL.receive { repeat; }
6384 }
6385
6386 /* release the channel */
6387 f_rsl_chan_deact();
6388 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6389 f_rslem_unregister(0, g_chan_nr);
6390}
6391testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006392 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006393 var RllTestCases tcs := {
6394 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6395 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6396 };
6397 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6398}
6399testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6400 var octetstring l3 := f_rnd_octstring(18);
6401 var RllTestCases tcs := {
6402 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6403 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6404 };
6405 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6406}
6407
Harald Weltee613f962018-04-18 22:38:16 +02006408/***********************************************************************
6409 * Encryption Related
6410 ***********************************************************************/
6411
6412/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006413private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006414 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6415 if (link_id.c == SACCH) {
6416 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6417 } else {
6418 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6419 }
6420}
6421
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006422/* Expect (or not expect) other kinds of messages */
6423private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6424 [exp_any] RSL.receive { repeat; }
6425 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006426 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006427 }
6428}
6429
Harald Weltee613f962018-04-18 22:38:16 +02006430/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006431private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006432 RslLinkId link_id,
6433 octetstring l3,
6434 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006435 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006436) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006437 timer T := 3.0;
6438 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6439 T.start;
6440 /* Expect RLL UNITDATA IND on RSL side */
6441 alt {
6442 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6443 setverdict(pass);
6444 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006445 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006446 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006447 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006449 }
Harald Weltee613f962018-04-18 22:38:16 +02006450 }
6451}
6452
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006453/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6454private function f_data_mo(
6455 RslLinkId link_id,
6456 boolean p, uint3_t nr, uint3_t ns,
6457 octetstring l3,
6458 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006459 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006460) runs on ConnHdlr {
6461 timer T := 3.0;
6462 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6463 T.start;
6464 /* Expect RLL DATA IND on RSL side */
6465 alt {
6466 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6467 setverdict(pass);
6468 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006469 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006470 [] as_rsl_any_ind(exp_any);
6471 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006472 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006473 }
6474 }
6475}
6476
Harald Weltee613f962018-04-18 22:38:16 +02006477/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006478private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006479 f_l1_tune(L1CTL);
6480 f_est_dchan(true);
6481
6482 /* now we actually need to transmit some data both ways to check if the encryption works */
6483 var L1ctlDlMessage dl;
6484
Stefan Sperling603d98e2018-07-25 16:47:28 +02006485 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006486 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6487
6488 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6489 f_unitdata_mt(link_id, l3);
6490
6491 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6492 f_unitdata_mo(link_id, l3);
6493
6494 /* release the channel */
6495 f_rsl_chan_deact();
6496 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6497 f_rslem_unregister(0, g_chan_nr);
6498}
6499testcase TC_chan_act_a51() runs on test_CT {
6500 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6501 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6502 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6503}
6504testcase TC_chan_act_a52() runs on test_CT {
6505 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6506 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6507 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6508}
6509testcase TC_chan_act_a53() runs on test_CT {
6510 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6511 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6512 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6513}
6514
Eric Wildf1827a72019-05-28 17:37:35 +02006515/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6516 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 +07006517private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006518 f_l1_tune(L1CTL);
6519 f_est_dchan(true);
6520
6521 /* now we actually need to transmit some data both ways to check if the encryption works */
6522 var L1ctlDlMessage dl;
6523
6524 var octetstring l3 := f_rnd_octstring(20);
6525 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6526
6527 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6528 f_unitdata_mt(link_id, l3);
6529
6530 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6531 f_unitdata_mo(link_id, l3);
6532
6533 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006534 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006535
6536 /* modify key to break proper encryption */
6537 g_pars.encr.key := f_rnd_octstring(8);
6538 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6539 rsl.ies := rsl.ies & { ei };
6540 RSL.send(rsl);
6541
6542 timer T0 := 1.0;
6543 T0.start;
6544 /* Expect RSL MODIFY ACK */
6545 alt {
6546 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6547 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6548 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6549 }
6550 [] T0.timeout {
6551 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6552 }
6553 }
6554
6555 var octetstring l3msg := f_rnd_octstring(15);
6556 timer T1 := 3.0;
6557 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6558 due to broken encryption */
6559 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6560 T1.start;
6561 alt {
6562 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6563 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6564 }
6565 [] T1.timeout {
6566 setverdict(pass);
6567 }
6568 }
6569
6570 /* release the channel */
6571 f_rsl_chan_deact();
6572 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6573 f_rslem_unregister(0, g_chan_nr);
6574}
6575testcase TC_rsl_modify_encr() runs on test_CT {
6576 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6577 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6578 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6579}
Harald Weltee613f962018-04-18 22:38:16 +02006580
6581/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006582private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006583 /* L3 payload doesn't matter, as it is passed transparently */
6584 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6585 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6586 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6587
6588 f_l1_tune(L1CTL);
6589
6590 /* first establish a dedicated channel in the clear */
6591 f_est_dchan(false);
6592
6593 /* Establish ABM */
6594 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6595
6596 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6597 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6598 /* expect the L3 to arrive still unencrypted on the MS side */
6599 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6600
6601 /* configure L1 to apply ciphering */
6602 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6603 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6604
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006605 /* send first ciphered I-frame in response and expect it on RSL */
6606 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006607
6608 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6609 * and hence enable encryption also on the downlink */
6610
6611 /* expect bi-directional communication work in encrypted mode */
6612 f_unitdata_mo(link_id, f_rnd_octstring(15));
6613 f_unitdata_mt(link_id, f_rnd_octstring(15));
6614
6615 /* release the channel */
6616 f_rsl_chan_deact();
6617 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6618 f_rslem_unregister(0, g_chan_nr);
6619}
6620testcase TC_encr_cmd_a51() runs on test_CT {
6621 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6622 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6623 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6624}
6625testcase TC_encr_cmd_a52() runs on test_CT {
6626 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6627 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6628 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6629}
6630testcase TC_encr_cmd_a53() runs on test_CT {
6631 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6632 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6633 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6634}
6635
6636private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6637 var LapdmFrame lf;
6638 var octetstring reenc;
6639
6640 /* decode the LAPDm frame */
6641 if (ischosen(exp_match.ab)) {
6642 lf.ab := dec_LapdmFrameAB(enc);
6643 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006645 }
6646
6647 /* check if decoder result matches expectation */
6648 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006650 } else {
6651 log(name, ": matched");
6652 setverdict(pass);
6653 }
6654
6655 /* test if re-encoded frame equals original input */
6656 reenc := enc_LapdmFrame(lf);
6657 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006659 } else {
6660 setverdict(pass);
6661 }
6662}
6663
6664testcase TC_lapdm_selftest() runs on test_CT {
6665 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6666 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6667 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6668 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6669 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6670 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6671 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6672}
6673
Stefan Sperling4880be42018-08-07 18:12:59 +02006674/***********************************************************************
6675 * DTX Related (see GSM 05.08, section 8.3)
6676 ***********************************************************************/
6677
6678/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006679private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006680 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6681 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6682 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6683 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6684}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006685private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006686 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6687 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6688}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006689private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006690 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6691 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6692 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6693 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6694}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006695private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006696 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6697 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6698 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6699 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6700 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6701 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6702 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6703 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6704}
6705
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006706private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006707 var L1ctlDlMessage dl;
6708 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6709 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6710 var GsmFrameNumber first_fn;
6711 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006712 var integer nfill_frames_sacch := 0;
6713 var integer nfill_frames_nonsacch := 0;
6714 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006715 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6716 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006717 const integer frame_dtx_tchf_mod := 104;
6718 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6719 * which operates in terms of blocks rather than frames. */
6720 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6721 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006722 timer T := 5.0;
6723
6724 f_l1_tune(L1CTL);
6725 RSL.clear;
6726 L1CTL.clear;
6727
6728 /* activate TCHF signalling channel */
6729 f_est_dchan(false);
6730
6731 T.start;
6732 alt {
6733 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6734 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6735 var octetstring l2 := dl.payload.data_ind.payload;
6736
6737 if (is_first_frame) {
6738 is_first_frame := false;
6739 first_fn := dl.dl_info.frame_nr;
6740 }
6741
6742 if (dl.dl_info.link_id.c == SACCH) {
6743 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6744 if (not match(l2_fill_frame_sacch, l2)) {
6745 repeat;
6746 }
6747 } else if (not match(l2_fill_frame, l2)) {
6748 repeat;
6749 }
6750
6751 if (dtxd) {
6752 if (not f_g_chan_is_tchf()) {
6753 T.stop;
6754 f_rsl_chan_deact();
6755 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006756 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 +02006757 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006758 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006759 T.stop;
6760 f_rsl_chan_deact();
6761 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006762
6763 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6764 * 2 SACCH, 1 TCH/F */
6765 expected_fill_frames := 3;
6766
6767 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6768 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6769 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006771 } else {
6772 setverdict(pass);
6773 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006774 } else {
6775 if (dl.dl_info.link_id.c == SACCH) {
6776 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006777 repeat;
6778 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006779 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6780 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6781 * we should only see the subset of frames numbers which correspond to a block boundary.
6782 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6783 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6784 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6785 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6786 repeat;
6787 }
6788 }
6789 log("Received DTX TCH fill frame with bad frame number: ", fn,
6790 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6791 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6792 f_rsl_chan_deact();
6793 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006795 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006796 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006797 if (dl.dl_info.link_id.c == SACCH) {
6798 nfill_frames_sacch := nfill_frames_sacch + 1;
6799 } else {
6800 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6801 }
6802 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006803 T.stop;
6804 if (f_g_chan_is_tchf()) {
6805 /* Without DTX we can expect 25 fill frames for every 104 frames.
6806 * (24 FACCH + 1 SACCH filling) */
6807 expected_fill_frames := 25;
6808 } else if (f_g_chan_is_tchh()) {
6809 /* We can expect 2 fill frames for every 104 frames. */
6810 expected_fill_frames := 2;
6811 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6812 /* We can expect 5 fill frames for every 104 frames. */
6813 expected_fill_frames := 5;
6814 } else {
6815 f_rsl_chan_deact();
6816 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006818 }
6819
6820 f_rsl_chan_deact();
6821 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006822
6823 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006824 setverdict(pass);
6825 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006826 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6827 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006829 }
6830 } else {
6831 repeat;
6832 }
6833 }
6834 }
6835 [] L1CTL.receive { repeat; }
6836 [] T.timeout {
6837 f_rsl_chan_deact();
6838 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006839 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006840 }
6841 }
6842}
6843
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006844private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006845 f_test_l2_fill_frames(false);
6846}
6847
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006848private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006849 f_test_l2_fill_frames(true);
6850}
6851
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006852private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006853 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02006854 var ConnHdlr vc_conn;
6855 var ConnHdlrPars pars;
6856 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006857 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006858 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02006859 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006860 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02006861 if (dtxd) {
6862 if (i >= 4) { /* DTX is only allowed on TCH/F */
6863 break;
6864 }
6865 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6866 } else {
6867 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6868 }
6869 vc_conn.done;
6870 }
6871}
6872
6873/* Verify that L2 fill frames are sent on TCH in signaling mode if
6874 * there is nothing to transmit while DTX is disabled on downlink. */
6875testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6876 f_tch_sign_l2_fill_frame(false);
6877}
6878
6879/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6880 * there is nothing to transmit while DTX is enabled on downlink. */
6881testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6882 f_tch_sign_l2_fill_frame(true);
6883}
Harald Welte0472ab42018-03-12 15:02:26 +01006884
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006885testcase TC_chopped_ipa_ping() runs on test_CT {
6886 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6887}
6888
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006889testcase TC_chopped_ipa_payload() runs on test_CT {
6890 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6891}
6892
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006893
6894/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6895 * Return value: Measurement Report to be sent (encoded octetstring). */
6896type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6897 runs on ConnHdlr return octetstring;
6898
6899private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6900runs on ConnHdlr {
6901 var L1ctlDlMessage l1_dl;
6902 var SacchL1Header l1h;
6903 var octetstring l2;
6904
6905 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6906 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6907 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6908 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6909
6910 /* Pass it to the user specified call-back function */
6911 l2 := cb.apply(l1h, num_blocks);
6912 /* Send a Measurement Report generated by the call-back */
6913 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6914 l1_dl.dl_info.link_id,
6915 l1h, l2));
6916
6917 /* Shall we keep going? */
6918 num_blocks := num_blocks - 1;
6919 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6920 if (num_blocks > 0) { repeat; }
6921 }
6922 [] L1CTL.receive { repeat; }
6923}
6924
6925private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6926runs on ConnHdlr return octetstring {
6927 /* Command the L1 to apply received parameters */
6928 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6929
6930 /* Dummy measurement report (the results are invalid) */
6931 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6932}
6933
6934private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6935runs on ConnHdlr return octetstring {
6936 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6937 setverdict(fail, "Unexpected MS Power level change: ",
6938 g_pars.l1_pars.ms_power_level, " -> ",
6939 l1h.ms_power_lvl);
6940 }
6941
6942 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6943}
6944
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07006945private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
6946runs on ConnHdlr return octetstring {
6947 /* UL RSSI oscillation driven by SACCH block number */
6948 if (num_blocks rem 2 == 0) {
6949 f_trxc_fake_rssi(-100);
6950 } else {
6951 f_trxc_fake_rssi(-50);
6952 }
6953
6954 /* Make sure that MS power level remains constant */
6955 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
6956}
6957
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006958/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6959private function f_TC_ms_pwr_ctrl_constant(charstring id)
6960runs on ConnHdlr {
6961 var integer num_blocks := 8;
6962 timer T := int2float(num_blocks);
6963
6964 f_l1_tune(L1CTL);
6965 RSL.clear;
6966
6967 /* These IEs are needed for autonomous MS power control */
6968 var template (value) RSL_IE_List ies := {
6969 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6970 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6971 }),
6972 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6973 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6974 })
6975 };
6976
6977 /* Ensure that 'rx-current' equals 'rx-target' */
6978 f_trxc_fake_rssi(mp_uplink_power_target);
6979
6980 /* Establish a dedicated channel */
6981 f_est_dchan(more_ies := valueof(ies));
6982
6983 L1CTL.clear;
6984 T.start;
6985 alt {
6986 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
6987 [] T.timeout {
6988 setverdict(fail, "Not all SACCH blocks were processed in time, ",
6989 num_blocks, " were not handled");
6990 }
6991 }
6992}
6993testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
6994 var ConnHdlr vc_conn;
6995 var ConnHdlrPars pars;
6996
6997 f_init();
6998
6999 /* Explicitly configure the Uplink power target (in dBm) */
7000 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7001
7002 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7003 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7004 log(testcasename(), ": starting on ", pars.chan_nr);
7005
7006 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7007 pars, trxc_comp := true);
7008 vc_conn.done;
7009 }
7010
7011 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7012 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7013}
7014
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007015/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7016private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7017runs on ConnHdlr {
7018 var integer num_blocks := 16;
7019 timer T := int2float(num_blocks);
7020
7021 f_l1_tune(L1CTL);
7022 RSL.clear;
7023
7024 /* These IEs are needed for autonomous MS power control */
7025 var template (value) RSL_IE_List ies := {
7026 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7027 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7028 }),
7029 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7030 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7031 })
7032 };
7033
7034 /* Ensure that 'rx-current' equals 'rx-target' */
7035 f_trxc_fake_rssi(mp_uplink_power_target);
7036
7037 /* Establish a dedicated channel */
7038 f_est_dchan(more_ies := valueof(ies));
7039
7040 L1CTL.clear;
7041 T.start;
7042 alt {
7043 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7044 [] T.timeout {
7045 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7046 num_blocks, " were not handled");
7047 }
7048 }
7049}
7050testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7051 var ConnHdlr vc_conn;
7052 var ConnHdlrPars pars;
7053
7054 f_init();
7055
7056 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7057 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7058 /* Explicitly configure the Uplink power range (target and delte) */
7059 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7060 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7061
7062 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7063 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7064 log(testcasename(), ": starting on ", pars.chan_nr);
7065
7066 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7067 pars, trxc_comp := true);
7068 vc_conn.done;
7069 }
7070
7071 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7073}
7074
Harald Welte0472ab42018-03-12 15:02:26 +01007075/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7076/* protocol error as per 44.006 */
7077/* link layer failure (repetition of I-frame N200 times without ACK */
7078/* repetition of SABM or DISC N200 times without ACK */
7079/* receptiom of SABM in multi-frame established state */
7080
7081
Harald Welte68e495b2018-02-25 00:05:57 +01007082/* TODO Areas:
7083
7084* channel activation
7085** with BS_Power / MS_Power, bypassing power control loop
7086** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007087** with timing advance from initial activation on
7088* mode modify
7089** encryption
7090** multirate
7091* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007092** unsupported algorithm
7093* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007094* BS Power Control
7095* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007096* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007097* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007098** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007099* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007100** DATA_IND from BTS->PCU
7101** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007102
7103*/
Harald Welte70767382018-02-21 12:16:40 +01007104
7105control {
7106 execute( TC_chan_act_stress() );
7107 execute( TC_chan_act_react() );
7108 execute( TC_chan_deact_not_active() );
7109 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007110 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007111 execute( TC_sacch_filling() );
7112 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007113 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007114 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007115 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007116 execute( TC_sacch_chan_act_ho_async() );
7117 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007118 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007119 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007120 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007121 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007122 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007123 execute( TC_rach_load_idle_thresh0() );
7124 execute( TC_rach_load_idle_below_thresh() );
7125 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007126 execute( TC_meas_res_speech_tchf() );
7127 execute( TC_meas_res_speech_tchh() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07007128 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01007129 execute( TC_meas_res_sign_tchf() );
7130 execute( TC_meas_res_sign_tchh() );
7131 execute( TC_meas_res_sign_sdcch4() );
7132 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007133 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007134 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007135 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007136 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007137 execute( TC_rsl_bs_pwr_static_ass() );
7138 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007139 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007140 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007141 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007142 execute( TC_rsl_ms_pwr_dyn_up() );
7143 execute( TC_rsl_ms_pwr_dyn_down() );
7144 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7145 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007146 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007147 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007148 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007149 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007150 execute( TC_paging_imsi_80percent() );
7151 execute( TC_paging_tmsi_80percent() );
7152 execute( TC_paging_imsi_200percent() );
7153 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007154 execute( TC_rsl_protocol_error() );
7155 execute( TC_rsl_mand_ie_error() );
7156 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007157 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007158 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007159 execute( TC_si_sched_2bis() );
7160 execute( TC_si_sched_2ter() );
7161 execute( TC_si_sched_2ter_2bis() );
7162 execute( TC_si_sched_2quater() );
7163 execute( TC_si_sched_13() );
7164 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007165 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007166 execute( TC_ipa_crcx_twice_not_active() );
7167 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007168 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007169 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007170
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007171 if (mp_pcu_socket != "") {
7172 execute( TC_pcu_act_req() );
7173 execute( TC_pcu_act_req_wrong_ts() );
7174 execute( TC_pcu_act_req_wrong_bts() );
7175 execute( TC_pcu_act_req_wrong_trx() );
7176 execute( TC_pcu_deact_req() );
7177 execute( TC_pcu_deact_req_wrong_ts() );
7178 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007179 if (mp_l1_supports_gprs) {
7180 execute( TC_pcu_data_req_pdtch() );
7181 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007182 execute( TC_pcu_data_req_wrong_bts() );
7183 execute( TC_pcu_data_req_wrong_trx() );
7184 execute( TC_pcu_data_req_wrong_ts() );
7185 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007186 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007187 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007188 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007189 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007190 execute( TC_pcu_data_req_imm_ass_pch() );
7191 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007192 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007193 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007194 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007195 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007196 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007197 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007198 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007199 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007200 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007201 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007202 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007203 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007204 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007205 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007206 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007207 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007208 execute( TC_dyn_osmo_pdch_act_deact() );
7209 execute( TC_dyn_osmo_pdch_double_act() );
7210 execute( TC_dyn_ipa_pdch_act_deact() );
7211 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7212
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007213 if (PCUIF_Types.mp_pcuif_version >= 10) {
7214 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007215 execute( TC_pcu_socket_nsvc_ipv4() );
7216 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007217 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007218 } else {
7219 log("PCU socket path not available, skipping PCU tests");
7220 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007221
Harald Welte3d04ae62018-04-04 20:29:05 +02007222 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007223 execute( TC_dyn_osmo_pdch_tchf_act() );
7224 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007225 execute( TC_dyn_ipa_pdch_tchf_act() );
7226 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007227
7228 execute( TC_rll_est_ind() );
7229 execute( TC_rll_est_req_DCCH_3() );
7230 execute( TC_rll_est_req_ACCH_3() );
7231 execute( TC_rll_rel_ind_DCCH_0() );
7232 execute( TC_rll_rel_ind_DCCH_3() );
7233 execute( TC_rll_rel_ind_ACCH_0() );
7234 execute( TC_rll_rel_ind_ACCH_3() );
7235 execute( TC_rll_rel_req() );
7236 execute( TC_rll_unit_data_req_DCCH() );
7237 execute( TC_rll_unit_data_req_ACCH() );
7238 execute( TC_rll_unit_data_ind_DCCH() );
7239 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007240
7241 execute( TC_chan_act_a51() );
7242 execute( TC_chan_act_a52() );
7243 execute( TC_chan_act_a53() );
7244 execute( TC_encr_cmd_a51() );
7245 execute( TC_encr_cmd_a52() );
7246 execute( TC_encr_cmd_a53() );
7247
Harald Welteee25aae2019-05-19 14:32:37 +02007248 execute( TC_err_rep_wrong_mdisc() );
7249 execute( TC_err_rep_wrong_msg_type() );
7250 execute( TC_err_rep_wrong_sequence() );
7251
Harald Weltee613f962018-04-18 22:38:16 +02007252 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007253
7254 execute( TC_tch_sign_l2_fill_frame() );
7255 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007256
7257 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007258 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007259
7260 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007261 execute( TC_ms_pwr_ctrl_pf_ewma() );
Harald Welte70767382018-02-21 12:16:40 +01007262}
7263
7264
7265}