blob: 79931a3290bad6f769d967923b32afa3eb7e51e5 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Alexander Couzens5283f552020-07-28 15:39:04 +020038import from Native_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020040import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010041
42import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010043import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010044import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020045import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010046import from RSL_Emulation all;
47
48import from IPL4asp_Types all;
49import from TRXC_Types all;
50import from TRXC_CodecPort all;
51import from TRXC_CodecPort_CtrlFunct all;
52
Harald Welte883340c2018-02-28 18:59:29 +010053import from PCUIF_Types all;
54import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020055import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010056
Harald Welte7484fc42018-02-24 14:09:45 +010057import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010058import from MobileL3_RRM_Types all;
59import from MobileL3_Types all;
60import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020061import from L3_Common all;
62import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010063
Harald Welte8da48242018-02-27 20:41:32 +010064import from Osmocom_VTY_Functions all;
65import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020066import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010067
Harald Welte505cf9b2018-09-15 17:47:23 +030068friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020069friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020070friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010071friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030072
Harald Welte70767382018-02-21 12:16:40 +010073/* The tests assume a BTS with the following timeslot configuration:
74 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020075 * TS1 : TCH/F
76 * TS2 : TCH/F
77 * TS3 : TCH/F_PDCH (IPA Style)
78 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010079 * TS5 : TCH/H
80 * TS6 : SDCCH/8
81 * TS7 : PDCH
82 */
83
84modulepar {
85 charstring mp_rsl_ip := "127.0.0.2";
86 integer mp_rsl_port := 3003;
87 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +070088 integer mp_trx1_arfcn := 873;
89 integer mp_trx2_arfcn := 875;
90 integer mp_trx3_arfcn := 877;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070091 charstring mp_bts_trxc_ip := "127.0.0.1";
92 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010093 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020094 charstring mp_ctrl_ip := "127.0.0.1";
95 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020096 charstring mp_bsc_ctrl_ip := "127.0.0.1";
97 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020098 integer mp_tolerance_rxqual := 1;
99 integer mp_tolerance_rxlev := 3;
100 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200101 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200102 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200103 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200104 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
105 integer mp_bts_tx_pwr_att_exp := 20; /* Expected Tx Power attenuation wrt to Tx Nominal Output Power, in dB */
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200106 integer mp_ms_actual_ta_exp := 0;
107 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700108 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700109 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100110 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200111 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200112 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200113 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
114 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700115 /* how many transceivers do we expect to connect */
116 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700117 /* frequency hopping status */
118 boolean mp_freq_hop_enabled := false;
119 /* frequency hopping parameters */
120 FreqHopConfig mp_fh_config;
Harald Welte70767382018-02-21 12:16:40 +0100121}
122
Harald Welte629cc6b2018-03-11 17:19:05 +0100123type record of RslChannelNr ChannelNrs;
124
Harald Welte70767382018-02-21 12:16:40 +0100125type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100126 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100127 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100128 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100129 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100130 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100131 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100132
133 /* L1CTL port (for classic tests) */
134 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100135
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700136 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700137 port TRXC_CODEC_PT BTS_TRXC;
138 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100139
Harald Weltef50e3ae2018-09-10 10:27:56 +0200140 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100141 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200142 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100143
Harald Welte883340c2018-02-28 18:59:29 +0100144 /* PCU Interface of BTS */
145 port PCUIF_CODEC_PT PCU;
146 var integer g_pcu_conn_id;
147 /* Last PCU INFO IND we received */
148 var PCUIF_Message g_pcu_last_info;
149
Harald Welte48494ca2018-02-25 16:59:50 +0100150 /* SI configuration */
151 var SystemInformationConfig si_cfg := {
152 bcch_extended := false,
153 si1_present := false,
154 si2bis_present := false,
155 si2ter_present := false,
156 si2quater_present := false,
157 si7_present := false,
158 si8_present := false,
159 si9_present := false,
160 si13_present := false,
161 si13alt_present := false,
162 si15_present := false,
163 si16_present := false,
164 si17_present := false,
165 si2n_present := false,
166 si21_present := false,
167 si22_present := false
168 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100169
170 /* all logical channels available on the BTS */
171 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100172 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100173}
174
175/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200176type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100177 port L1CTL_PT L1CTL;
178
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700179 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700180 port TRXC_CODEC_PT BTS_TRXC;
181 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100182
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200183 /* port to be initialized optionally to access BSC VTY */
184 port TELNETasp_PT BSCVTY;
185
Harald Welte70767382018-02-21 12:16:40 +0100186 timer g_Tguard;
187 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
188
189 var ConnHdlrPars g_pars;
190 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100191 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200192
193 /* PCU Interface of BTS */
194 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100195}
196
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700197private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700198 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200199 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700200 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200201 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700202 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200203 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700204 timer T;
205
Harald Welte70767382018-02-21 12:16:40 +0100206 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
207 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
208
209 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
210 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
211 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
212
213 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
214 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700215
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700216 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700217 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700218 T.start(mp_ipa_up_timeout);
219 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700220 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700221 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
222 /* Make sure that all transceivers use unique stream ID */
223 if (trx_mask[enum2int(ev.sid)] == '1'B) {
224 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
225 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
226 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700227
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700228 trx_mask[enum2int(ev.sid)] := '1'B;
229 trx_count := trx_count + 1;
230
231 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200232 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700233 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200234 /* This message (RF RESource INDication) is sent by the IUT itself */
235 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
236 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
238 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
239 }
240 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
242 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
243 }
244
245 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
246 rfind_count := rfind_count + 1;
247 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
248 if (rfind_count < mp_transceiver_num) { repeat; }
249 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700250 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
251 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
252 [] T.timeout {
253 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
254 "Timeout waiting for RSL bring up");
255 }
256 }
Harald Welte70767382018-02-21 12:16:40 +0100257}
258
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700259friend type record FreqHopPars {
260 /* Whether frequency hopping is in use */
261 boolean enabled,
262 /* Mobile Allocation Index Offset / Hopping Sequence Number */
263 MaioHsn maio_hsn,
264 /* MA bitmap to be indicated in RR Immediate Assignment */
265 MobileAllocationLV ma_map,
266 /* The actual Mobile Allocation (ARFCN list) to be used */
267 L1ctlMA ma
268};
269
Harald Welte70767382018-02-21 12:16:40 +0100270type record ConnHdlrPars {
271 RslChannelNr chan_nr,
272 RSL_IE_ChannelMode chan_mode,
273 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100274 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200275 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200276 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700277 BtsBand bts0_band optional,
278
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700279 /* Frequency hopping parameters */
280 FreqHopPars fhp
281};
Harald Welte0472ab42018-03-12 15:02:26 +0100282
283/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700284private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100285 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100286}
287
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700288private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100289 max_retrans := RACH_MAX_RETRANS_7,
290 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100291 cell_barr_access := false,
292 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100293 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100294};
295
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700296private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100297 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200298 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100299 acs := '0'B,
300 neci := true,
301 rxlev_access_min := 0
302}
303
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700304private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100305 mcc_mnc := '262F42'H,
306 lac := 42
307}
308
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700309private template (value) GPRSIndicator ts_GPRSIndicator_def := {
310 ra_colour := 0,
311 si13_pos := '0'B
312}
313
314private template (value) SI3RestOctets ts_SI3RestOctets_def
315modifies ts_SI3RestOctets := {
316 gprs_ind := {
317 presence := CSN1_H,
318 ind := ts_GPRSIndicator_def
319 }
320}
321
322private template (value) SI4RestOctets ts_SI4RestOctets_def
323modifies ts_SI4RestOctets := {
324 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700325 presence := CSN1_H,
326 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700327 }
328}
329
Harald Welte7484fc42018-02-24 14:09:45 +0100330/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700331private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100332 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100333 payload := {
334 si3 := {
335 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100336 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100337 ctrl_chan_desc := {
338 msc_r99 := true,
339 att := true,
340 bs_ag_blks_res := 1,
341 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100342 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100343 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
344 spare := '00'B,
345 bs_pa_mfrms := 0, /* 2 multiframes */
346 t3212 := 1 /* 6 minutes */
347 },
Harald Welte82ccef72018-02-25 16:17:33 +0100348 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100349 dn_ind := false,
350 pwrc := false,
351 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100352 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100353 },
Harald Weltef10153f2018-02-25 16:34:05 +0100354 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100355 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200356 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100357 }
358 }
359}
Harald Welte70767382018-02-21 12:16:40 +0100360
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700361private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100362 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100363 payload := {
364 si2 := {
365 bcch_freq_list := '00000000000000000000000000000000'O,
366 ncc_permitted := '11111111'B,
367 rach_control := ts_RachCtrl_default
368 }
369 }
370}
371
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700372private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100373 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100374 payload := {
375 si4 := {
376 lai := ts_LAI_default,
377 cell_sel_par := ts_CellSelPar_default,
378 rach_control := ts_RachCtrl_default,
379 cbch_chan_desc := omit,
380 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200381 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100382 }
383 }
384}
385
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700386private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100387runs on test_CT {
388 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700389 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100390}
391
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700392private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100393runs on test_CT {
394 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
395 log("Setting ", rsl_si_type, ": ", si_dec);
396 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
397}
398
Harald Welte505cf9b2018-09-15 17:47:23 +0300399friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100400 map(self:BTSVTY, system:BTSVTY);
401 f_vty_set_prompts(BTSVTY);
402 f_vty_transceive(BTSVTY, "enable");
403}
404
Harald Welte505cf9b2018-09-15 17:47:23 +0300405friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200406 map(self:BSCVTY, system:BSCVTY);
407 f_vty_set_prompts(BSCVTY, "OsmoBSC");
408 f_vty_transceive(BSCVTY, "enable");
409}
410
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200411friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
412 map(self:BSCVTY, system:BSCVTY);
413 f_vty_set_prompts(BSCVTY, "OsmoBSC");
414 f_vty_transceive(BSCVTY, "enable");
415}
416
Harald Welte883340c2018-02-28 18:59:29 +0100417/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200418private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
419 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100420 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200421 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
422 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100423 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200424 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100426 }
427}
428
Harald Weltef26de0b2018-04-04 20:28:05 +0200429private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
430 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100431 timer T := 2.0;
432 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100433 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200434 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100435 return;
436 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200437 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100438
439 T.start;
440 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200441 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100442 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100444 }
445 }
446}
447
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700448private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
449 out integer trxc_conn_id) {
450 var Result res;
451
452 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
453 "", -1, -1, { udp := {} }, {});
454 if (not ispresent(res.connId)) {
455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
456 "Could not connect to the control (TRXC) interface " &
457 "of FakeTRX, check your configuration");
458 }
459 trxc_conn_id := res.connId;
460}
461
Harald Welte70767382018-02-21 12:16:40 +0100462/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700463friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200464 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100465 g_AllChannels := {
466 /* TS 1..4: TCH/F */
467 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
468 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
469 /* TS 5: TCH/H */
470 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
471 /* TS 0: SDCCH/4 */
472 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
473 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
474 /* TS 6: SDCCH/8 */
475 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
476 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
477 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
478 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
479 };
480
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200481 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700482 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200483 g_AllChanTypes := {
484 /* TS 1..4: TCH/F */
485 valueof(ts_RslChanNr_Bm(1)),
486 /* TS 5: TCH/H */
487 valueof(ts_RslChanNr_Lm(5,1)),
488 /* TS 0: SDCCH/4 */
489 valueof(ts_RslChanNr_SDCCH4(0,2)),
490 /* TS 6: SDCCH/8 */
491 valueof(ts_RslChanNr_SDCCH8(6,4))
492 };
493 } else {
494 g_AllChanTypes := {
495 /* TS 1..4: TCH/F */
496 valueof(ts_RslChanNr_Bm(1)),
497 /* TS 0: SDCCH/4 */
498 valueof(ts_RslChanNr_SDCCH4(0,2)),
499 /* TS 6: SDCCH/8 */
500 valueof(ts_RslChanNr_SDCCH8(6,4))
501 };
502 }
Harald Welte70767382018-02-21 12:16:40 +0100503 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100504 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100505 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200506 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100507
508 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100509 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
510 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
511 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
512 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100513
Harald Weltef26de0b2018-04-04 20:28:05 +0200514 map(self:PCU, system:PCU);
515 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100516
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700517 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100518 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700519
520 /* Init TRXC interface to FakeTRX */
521 map(self:BTS_TRXC, system:BTS_TRXC);
522 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
523
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700524 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700525 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700526 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700527 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
528 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100529 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200530
531 /* Wait some extra time to make sure the BTS emits a stable carrier.
532 * (this is only relevant when running the tests with a physical BTS.) */
533 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100534}
535
Harald Welte68e495b2018-02-25 00:05:57 +0100536/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700537friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100538 map(self:L1CTL, system:L1CTL);
539 f_connect_reset(L1CTL);
540}
541
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700542private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100543
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700544private type record length(8) of FreqHopGroups FreqHopConfig;
545
546private type record of FreqHopGroup FreqHopGroups;
547private type record FreqHopGroup {
548 uint6_t hsn,
549 FreqHopGroupItems trx_maio
550};
551
552private type record of FreqHopGroupItem FreqHopGroupItems;
553private type record FreqHopGroupItem {
554 uint8_t trx_nr,
555 uint6_t maio
556};
557
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700558friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
559 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700560{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700561 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700562 var integer i, j;
563
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700564 fhp.enabled := false;
565
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700566 for (i := 0; i < lengthof(groups); i := i + 1) {
567 var FreqHopGroup g := groups[i];
568 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
569 var FreqHopGroupItem gi := g.trx_maio[j];
570 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700571 fhp.maio_hsn.maio := gi.maio;
572 fhp.maio_hsn.hsn := g.hsn;
573 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700574 break;
575 }
576 }
577
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700578 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700579 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700580 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
581 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
582 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700583
584 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700585 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
586 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700587 fhp.ma := fhp.ma & { l1ctl_ma_def[gi.trx_nr] };
588 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700589 }
590
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700591 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700592 break; /* We're done */
593 }
594 }
595}
596
Harald Welte70767382018-02-21 12:16:40 +0100597/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700598friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
599 boolean pcu_comp := false,
600 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100601runs on test_CT return ConnHdlr {
602 var charstring id := testcasename();
603 var ConnHdlr vc_conn;
604
605 vc_conn := ConnHdlr.create(id);
606 /* connect to RSL Emulation main component */
607 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
608 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700609
610 /* The ConnHdlr component may want to talk to some ports directly,
611 * so we disconnect it from the test_CT and connect it to the component.
612 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200613 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200614 unmap(self:PCU, system:PCU);
615 map(vc_conn:PCU, system:PCU);
616 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700617 if (trxc_comp) {
618 unmap(self:BTS_TRXC, system:BTS_TRXC);
619 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
620 }
Harald Welte70767382018-02-21 12:16:40 +0100621
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700622 /* Obtain frequency hopping parameters for a given timeslot */
623 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700624 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700625 }
626
Harald Welte70767382018-02-21 12:16:40 +0100627 vc_conn.start(f_handler_init(fn, id, pars));
628 return vc_conn;
629}
630
Harald Welte70767382018-02-21 12:16:40 +0100631private altstep as_Tguard() runs on ConnHdlr {
632 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200633 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100634 }
635}
636
Harald Welte990a3612019-05-27 14:02:13 +0200637friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
638 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100639}
640
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700641private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100642 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700643 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100644}
645
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700646private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100647 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700648 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100649}
650
651/* first function started in ConnHdlr component */
652private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
653runs on ConnHdlr {
654 g_pars := pars;
655 g_chan_nr := pars.chan_nr;
656
657 map(self:L1CTL, system:L1CTL);
658 f_connect_reset(L1CTL);
659
Harald Welted48c0c72019-06-05 10:01:15 +0200660 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700661 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100662 }
Harald Welte70767382018-02-21 12:16:40 +0100663
664 g_Tguard.start(pars.t_guard);
665 activate(as_Tguard());
666
667 f_rslem_register(0, pars.chan_nr);
668
669 /* call the user-supplied test case function */
670 fn.apply(id);
671}
672
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700673private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
674 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200675runs on ConnHdlr return RSL_Message {
676 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100677 timer T := 3.0;
678 RSL.send(tx);
679 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100680 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200681 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100682 T.stop;
683 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100684 }
Harald Welte1eba3742018-02-25 12:48:14 +0100685 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100687 }
Harald Welte21240e62018-03-11 21:43:35 +0100688 [not ignore_other] as_l1_sacch();
689 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700690 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700691 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100692 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100694 }
Harald Welte21240e62018-03-11 21:43:35 +0100695 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100696 }
Harald Welteb1726c92018-03-30 11:56:38 +0200697 return rx;
698}
699
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700700friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
701 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200702runs on ConnHdlr {
703 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100704}
705
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700706friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
707 boolean encr_enable := false,
708 RSL_IE_List more_ies := {},
709 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
710runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200711 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200712 if (encr_enable) {
713 /* append encryption related IEs, if requested */
714 var RSL_IE_EncryptionInfo encr_info;
715 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
716 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
717encr_info})) };
718 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200719 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200720 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100721}
722
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700723friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100724 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100725 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100726}
727
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700728/* Default Mobile Allocation to be used for frequency hopping */
729private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
730 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
731
Harald Welte2f2b2b72019-05-31 22:24:57 +0200732friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100733 template RSL_IE_ChannelMode chan_mode,
734 float t_guard := 20.0) := {
735 chan_nr := valueof(chan_nr),
736 chan_mode := valueof(chan_mode),
737 t_guard := t_guard,
738 l1_pars := {
739 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100740 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100741 meas_ul := {
742 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200743 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100744 rxqual := 0
745 },
746 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200747 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100748 rxqual := 0
749 }
750 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200751 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100752 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200753 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200754 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100755 },
Harald Weltee613f962018-04-18 22:38:16 +0200756 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200757 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700758 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700759 fhp := {
760 enabled := false,
761 maio_hsn := ts_HsnMaio(0, 0),
762 ma_map := c_MA_null,
763 ma := l1ctl_ma_def
764 }
Harald Welte70767382018-02-21 12:16:40 +0100765}
766
Harald Welte93640c62018-02-25 16:59:33 +0100767/***********************************************************************
768 * Channel Activation / Deactivation
769 ***********************************************************************/
770
Harald Welte70767382018-02-21 12:16:40 +0100771/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700772private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100773 for (var integer i := 0; i < 500; i := i+1) {
774 f_rsl_chan_act(g_pars.chan_mode);
775 f_rsl_chan_deact();
776 }
777 setverdict(pass);
778}
779testcase TC_chan_act_stress() runs on test_CT {
780 var ConnHdlr vc_conn;
781 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200782 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100783 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
784 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200785 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100786}
787
788/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700789private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100790 f_rsl_chan_act(g_pars.chan_mode);
791 /* attempt to activate the same lchan again -> expect reject */
792 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
793 alt {
794 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200795 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100796 }
797 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
798 setverdict(pass);
799 }
800 }
801 f_rsl_chan_deact();
802}
803testcase TC_chan_act_react() runs on test_CT {
804 var ConnHdlr vc_conn;
805 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100806 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100807 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
808 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100810}
811
812/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700813private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100814 timer T := 3.0;
815 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
816 T.start;
817 alt {
818 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
819 setverdict(pass);
820 }
821 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100823 }
824 }
825}
826testcase TC_chan_deact_not_active() runs on test_CT {
827 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100828 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100829 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
830 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200831 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100832}
833
834/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700835private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100836 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
837 alt {
838 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200839 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100840 }
841 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
842 setverdict(pass);
843 }
844 }
845}
846private type record WrongChanNrCase {
847 RslChannelNr chan_nr,
848 charstring description
849}
850private type record of WrongChanNrCase WrongChanNrCases;
851private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
852 chan_nr := chan_nr,
853 description := desc
854}
855
856testcase TC_chan_act_wrong_nr() runs on test_CT {
857 var ConnHdlr vc_conn;
858 var ConnHdlrPars pars;
859
Harald Welte294b0a22018-03-10 23:26:48 +0100860 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100861
862 var WrongChanNrCases wrong := {
863 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
864 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
865 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
866 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
867 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
868 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
869 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
870 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
871 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
872 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
873 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
874 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
875 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
876 };
877
878 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
879 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
880 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
881 vc_conn.done;
882 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200883 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100884}
885
Harald Weltee613f962018-04-18 22:38:16 +0200886/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200887friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200888 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200889 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200890
891 /* test on each of the channels we have */
892 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
893 pars.chan_nr := valueof(g_AllChanTypes[i]);
894
895 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
896 vc_conn := f_start_handler(fn, pars);
897 vc_conn.done;
898 }
899
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200901}
902
Harald Welte93640c62018-02-25 16:59:33 +0100903/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100904 * SACCH handling
905 ***********************************************************************/
906
907private function f_exp_sacch(boolean exp) runs on ConnHdlr {
908 timer T_sacch := 3.0;
909 T_sacch.start;
910 alt {
911 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200912 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100913 }
914 [not exp] T_sacch.timeout {
915 setverdict(pass);
916 }
917 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
918 setverdict(pass);
919 }
920 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200921 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100922 }
923 [] L1CTL.receive { repeat; }
924 [] RSL.receive { repeat; }
925 }
926}
927
928/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
929private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
930 f_l1_tune(L1CTL);
931 RSL.clear;
932
933 /* activate the logical channel */
934 f_est_dchan();
935 L1CTL.clear;
936
937 /* check that SACCH actually are received as expected */
938 f_exp_sacch(true);
939
940 /* deactivate SACCH on the logical channel */
941 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
942 f_sleep(1.0);
943 L1CTL.clear;
944
945 /* check that no SACCH are received anymore */
946 f_exp_sacch(false);
947
948 /* release the channel */
949 f_rsl_chan_deact();
950 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
951}
952testcase TC_deact_sacch() runs on test_CT {
953 var ConnHdlr vc_conn;
954 var ConnHdlrPars pars;
955 f_init();
956 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
957 //for (var integer i := 0; i < 1; i := i+1) {
958 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
959 log(testcasename(), ": Starting for ", g_AllChannels[i]);
960 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
961 vc_conn.done;
962 }
963 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100965}
966
Harald Welte55700662018-03-12 13:15:43 +0100967/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100968private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
969 var L1ctlDlMessage dl;
970 /* check that the specified SI5 value is actually sent */
971 timer T_sacch := 3.0;
972 L1CTL.clear;
973 T_sacch.start;
974 alt {
975 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
976 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
977 if (match(l3, l3_exp)) {
978 setverdict(pass);
979 } else {
980 repeat;
981 }
982 }
983 [] L1CTL.receive { repeat; }
984 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100986 }
987 }
988}
989
Harald Welte55700662018-03-12 13:15:43 +0100990/* verify that given SACCH payload is not present */
991private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
992 var L1ctlDlMessage dl;
993 /* check that the specified SI5 value is actually sent */
994 timer T_sacch := 3.0;
995 L1CTL.clear;
996 T_sacch.start;
997 alt {
998 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
999 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1000 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001001 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001002 } else {
1003 repeat;
1004 }
1005 }
1006 [] L1CTL.receive { repeat; }
1007 [] T_sacch.timeout {
1008 setverdict(pass);
1009 }
1010 }
1011}
1012
Harald Welte629cc6b2018-03-11 17:19:05 +01001013/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001014private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1015 /* Set a known default SACCH filling for SI5 */
1016 var octetstring si5 := f_rnd_octstring(19);
1017 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1018
1019 f_l1_tune(L1CTL);
1020 RSL.clear;
1021
1022 /* activate the logical channel */
1023 f_est_dchan();
1024
1025 /* check that the specified SI5 value is actually sent */
1026 f_sacch_present(si5);
1027
1028 /* release the channel */
1029 RSL.clear;
1030 f_rsl_chan_deact();
1031 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1032}
1033testcase TC_sacch_filling() runs on test_CT {
1034 var ConnHdlr vc_conn;
1035 var ConnHdlrPars pars;
1036 f_init();
1037 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1038 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1039 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1040 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1041 vc_conn.done;
1042 }
1043 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001045}
1046
Harald Welte629cc6b2018-03-11 17:19:05 +01001047/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001048private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1049 /* Set a known default SACCH filling for SI5 */
1050 var octetstring si5 := f_rnd_octstring(19);
1051 var octetstring si5_diff := f_rnd_octstring(19);
1052 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1053
1054 f_l1_tune(L1CTL);
1055 RSL.clear;
1056
1057 log("Activating channel, expecting standard SI5");
1058 /* activate the logical channel */
1059 f_est_dchan();
1060 /* check that the specified SI5 value is actually sent */
1061 f_sacch_present(si5);
1062
1063 /* set channel-specific different SI5 */
1064 log("Setting channel specific SACCH INFO, expecting it");
1065 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1066 /* check that the specified lchan-specific value is now used */
1067 f_sacch_present(si5_diff);
1068
1069 /* deactivate the channel and re-activate it, this should result in default SI5 */
1070 log("De-activating and re-activating channel, expecting standard SI5");
1071 f_rsl_chan_deact();
1072 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1073 /* Verify that the TRX-wide default SACCH filling is present again */
1074 f_sacch_present(si5);
1075
1076 /* release the channel */
1077 RSL.clear;
1078 f_rsl_chan_deact();
1079 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1080}
1081testcase TC_sacch_info_mod() runs on test_CT {
1082 var ConnHdlr vc_conn;
1083 var ConnHdlrPars pars;
1084 f_init();
1085 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1086 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1087 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1088 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1089 vc_conn.done;
1090 }
1091 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001092 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001093}
1094
Harald Welte075d84c2018-03-12 13:07:24 +01001095/* Test SACCH scheduling of multiple different SI message types */
1096private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1097 var octetstring si5 := f_rnd_octstring(19);
1098 var octetstring si5bis := f_rnd_octstring(19);
1099 var octetstring si5ter := f_rnd_octstring(19);
1100 var octetstring si6 := f_rnd_octstring(19);
1101
1102 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1103 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1104 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1105 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1106
1107 f_l1_tune(L1CTL);
1108 RSL.clear;
1109
1110 /* activate the logical channel */
1111 f_est_dchan();
1112 L1CTL.clear;
1113
1114 /* check that SACCH actually are received as expected */
1115 f_sacch_present(si5);
1116 f_sacch_present(si5bis);
1117 f_sacch_present(si5ter);
1118 f_sacch_present(si6);
1119
1120 /* release the channel */
1121 f_rsl_chan_deact();
1122 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1123}
1124testcase TC_sacch_multi() runs on test_CT {
1125 var ConnHdlr vc_conn;
1126 var ConnHdlrPars pars;
1127 f_init();
1128 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1129 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1130 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1131 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1132 vc_conn.done;
1133 }
1134 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001136}
1137
Harald Welte55700662018-03-12 13:15:43 +01001138/* Test if SACH information is modified as expected */
1139private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1140 var octetstring si5 := f_rnd_octstring(19);
1141 var octetstring si6 := f_rnd_octstring(19);
1142
1143 /* First, configure both SI5 and SI6 to be transmitted */
1144 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1145 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1146
1147 f_l1_tune(L1CTL);
1148 RSL.clear;
1149
1150 /* activate the logical channel */
1151 f_est_dchan();
1152 L1CTL.clear;
1153
1154 /* check that SACCH actually are received as expected */
1155 f_sacch_present(si5);
1156 f_sacch_present(si6);
1157
1158 /* disable SI6 */
1159 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1160
1161 /* check that SI5 is still transmitted */
1162 f_sacch_present(si5);
1163 /* check if SI6 is now gone */
1164 f_sacch_missing(si6);
1165
1166 /* release the channel */
1167 f_rsl_chan_deact();
1168 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1169}
1170testcase TC_sacch_multi_chg() runs on test_CT {
1171 var ConnHdlr vc_conn;
1172 var ConnHdlrPars pars;
1173 f_init();
1174 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1175 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1176 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1177 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1178 vc_conn.done;
1179 }
1180 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001182}
1183
Harald Weltec8d363c2019-05-19 20:36:48 +02001184/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1185private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1186 var octetstring si5 := f_rnd_octstring(19);
1187 var octetstring si6 := f_rnd_octstring(19);
1188 var octetstring si5_specific := f_rnd_octstring(19);
1189 var octetstring si6_specific := f_rnd_octstring(19);
1190
1191 /* First, configure both SI5 and SI6 to be transmitted */
1192 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1193 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1194
1195 f_l1_tune(L1CTL);
1196 RSL.clear;
1197
1198 /* activate channel with different SACCH filling */
1199 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1200 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1201 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1202 }));
1203 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1204 RSL_IE_Body:{sacch_info := sacch_info})) };
1205 f_est_dchan(more_ies := addl_ies);
1206
1207 /* check that SACCH actually are received as expected */
1208 f_sacch_present(si5_specific);
1209 f_sacch_present(si6_specific);
1210
1211 /* release the channel */
1212 f_rsl_chan_deact();
1213 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1214}
1215testcase TC_sacch_chan_act() runs on test_CT {
1216 var ConnHdlr vc_conn;
1217 var ConnHdlrPars pars;
1218 f_init();
1219
1220 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1221 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1222 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1223 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1224 vc_conn.done;
1225 }
1226 /* TODO: do the above in parallel, rather than sequentially? */
1227 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1228}
1229
Harald Welte8b01c792019-05-19 22:51:25 +02001230/* verify that SACCH DL transmission is started only if MS power IE present
1231 * see section 4.1.3 of 3GPP TS 48.058 */
1232private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1233 var octetstring si5 := f_rnd_octstring(19);
1234
1235 f_l1_tune(L1CTL);
1236 RSL.clear;
1237
1238 /* Step 1: Activate ASYNC HO channel without MS power IE */
1239
1240 /* Activate channel on BTS side */
1241 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1242 /* don't perform immediate assignment here, as we're testing non-IA case */
1243 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001244 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001245
1246 /* Verify that no DL SACCH is being received */
1247 f_sacch_missing(?);
1248
1249 f_rsl_chan_deact();
1250 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1251
1252
1253 /* Step 2: Activate ASYNC HO channel with MS power IE */
1254
1255 /* Activate channel on BTS side */
1256 var RSL_IE_List addl_ies := {
1257 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1258 };
1259 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1260 /* don't perform immediate assignment here, as we're testing non-IA case */
1261 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001262 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001263
1264 /* Verify that DL SACCH is being received */
1265 f_sacch_present(si5);
1266
1267 f_rsl_chan_deact();
1268 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1269}
1270testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1271 var ConnHdlr vc_conn;
1272 var ConnHdlrPars pars;
1273 f_init();
1274
1275 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1276 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1277 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1278 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1279 vc_conn.done;
1280 }
1281 /* TODO: do the above in parallel, rather than sequentially? */
1282 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1283}
1284
1285/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1286 * see section 4.1.4 of 3GPP TS 48.058 */
1287private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1288 var octetstring si5 := f_rnd_octstring(19);
1289 var RSL_IE_List addl_ies;
1290
1291 f_l1_tune(L1CTL);
1292 RSL.clear;
1293
1294 /* Step 1: Activate SYNC HO channel without MS power IE */
1295
1296 /* Activate channel on BTS side */
1297 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1298 /* don't perform immediate assignment here, as we're testing non-IA case */
1299 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001300 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001301
1302 /* Verify that no DL SACCH is being received */
1303 f_sacch_missing(?);
1304
1305 f_rsl_chan_deact();
1306 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1307
1308
1309 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1310
1311 /* Activate channel on BTS side */
1312 addl_ies := {
1313 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1314 };
1315 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1316 /* don't perform immediate assignment here, as we're testing non-IA case */
1317 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001318 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001319
1320 /* Verify that no DL SACCH is being received */
1321 f_sacch_missing(?);
1322
1323 f_rsl_chan_deact();
1324 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1325
1326
1327 /* Step 2b: Activate SYNC HO channel with TA IE */
1328
1329 /* Activate channel on BTS side */
1330 addl_ies := {
1331 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1332 };
1333 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1334 /* don't perform immediate assignment here, as we're testing non-IA case */
1335 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001336 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001337
1338 /* Verify that no DL SACCH is being received */
1339 f_sacch_missing(?);
1340
1341 f_rsl_chan_deact();
1342 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1343
1344
1345 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1346
1347 /* Activate channel on BTS side */
1348 addl_ies := {
1349 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1350 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1351 };
1352 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1353 /* don't perform immediate assignment here, as we're testing non-IA case */
1354 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001355 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001356
1357 /* Verify that DL SACCH is being received */
1358 f_sacch_present(si5);
1359
1360 f_rsl_chan_deact();
1361 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1362}
1363testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1364 var ConnHdlr vc_conn;
1365 var ConnHdlrPars pars;
1366 f_init();
1367
1368 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1369 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1370 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1371 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1372 vc_conn.done;
1373 }
1374 /* TODO: do the above in parallel, rather than sequentially? */
1375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1376}
Harald Welte629cc6b2018-03-11 17:19:05 +01001377
1378
1379/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001380 * RACH Handling
1381 ***********************************************************************/
1382
Harald Welte8c24c2b2018-02-26 08:31:31 +01001383/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001384private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001385 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001386 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001387 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001388
Harald Welte8c24c2b2018-02-26 08:31:31 +01001389 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001390 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001391 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001392 var OCT1 ra := f_rnd_ra_emerg();
1393 if (emerg == true) {
1394 ra := f_rnd_ra_emerg();
1395 } else {
1396 ra := f_rnd_ra_cs();
1397 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001398 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1399 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001400 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001401 }
1402 fn_last := fn;
1403
1404 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001405 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001406 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001407 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001408 T.stop;
1409 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001410 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001411 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001412 }
1413 [] RSL_CCHAN.receive { repeat; }
1414 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001415 test_failed := true;
1416 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001417 }
1418 }
1419 }
Maxba06feb2019-03-05 10:52:46 +01001420 if (test_failed) {
1421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001422 }
Maxba06feb2019-03-05 10:52:46 +01001423 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001425}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001426
Philipp Maier16ade782020-07-08 21:36:00 +02001427/* Normal variant */
1428testcase TC_rach_content() runs on test_CT {
1429 f_TC_rach_content(emerg := false);
1430}
1431
1432/* Emergency call variant */
1433testcase TC_rach_content_emerg() runs on test_CT {
1434 f_TC_rach_content(emerg := true);
1435}
1436
Harald Welte8c24c2b2018-02-26 08:31:31 +01001437/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1438testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001439 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001440 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001441 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001442 f_l1_tune(L1CTL);
1443
1444 var GsmFrameNumber fn_last := 0;
1445 for (var integer i := 0; i < 1000; i := i+1) {
1446 var OCT1 ra := f_rnd_ra_cs();
1447 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1448 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001450 }
1451 fn_last := fn;
1452 }
1453 var integer rsl_chrqd := 0;
1454 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001455 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001456 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001457 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001458 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001459 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001460 repeat;
1461 }
1462 [] RSL_CCHAN.receive { repeat; }
1463 [] T.timeout { }
1464 }
1465 if (rsl_chrqd == 1000) {
1466 setverdict(pass);
1467 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001469 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001470 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001471}
1472
Harald Welte3453ab42019-05-24 21:19:58 +02001473private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1474 var charstring bts_str := "bts " & int2str(bts_nr);
1475 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1476}
1477
1478/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1479private template integer tr_rach_slots_per_interval := (90 .. 130);
1480
1481/* Expect 0 RACH load on an idle BTS that has just started up */
1482testcase TC_rach_load_idle_thresh0() runs on test_CT {
1483 var ASP_RSL_Unitdata rx_ud;
1484
1485 f_init_vty_bsc();
1486 /* send load indications even at 0% load */
1487 f_vty_load_ind_thresh(0);
1488 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1489 f_sleep(2.0);
1490
1491 f_init();
1492
Harald Weltee37f9a52020-10-11 20:45:23 +02001493 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1494 alt {
1495 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1496 [] RSL_CCHAN.receive { repeat }
1497 }
1498
Harald Welte3453ab42019-05-24 21:19:58 +02001499 timer T := 5.0;
1500 T.start;
1501 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001502 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
Harald Welte3453ab42019-05-24 21:19:58 +02001503 setverdict(pass);
1504 repeat;
1505 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001506 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001507 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1508 repeat;
1509 }
1510 [] RSL_CCHAN.receive {
1511 repeat;
1512 }
1513 [] T.timeout { }
1514 }
1515
1516 f_vty_load_ind_thresh(10);
1517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1518}
1519
1520/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1521testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1522 var ASP_RSL_Unitdata rx_ud;
1523
1524 f_init_vty_bsc();
1525 f_init();
1526
1527 timer T := 5.0;
1528 T.start;
1529 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001530 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001531 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1532 repeat;
1533 }
1534 [] RSL_CCHAN.receive {
1535 repeat;
1536 }
1537 [] T.timeout {
1538 setverdict(pass);
1539 }
1540 }
1541
1542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1543}
1544
1545/* Expect 0 RACH load on an idle BTS that has just started up */
1546testcase TC_rach_load_count() runs on test_CT {
1547 var ASP_RSL_Unitdata rx_ud;
1548 var integer load_access_count := 0;
1549
1550 f_init_vty_bsc();
1551 /* send load indications even at 0% load */
1552 f_vty_load_ind_thresh(0);
1553 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1554 f_sleep(2.0);
1555 f_init();
1556
1557 f_init_l1ctl();
1558 f_sleep(1.0);
1559 f_l1_tune(L1CTL);
1560
Harald Welte52ae1682020-10-11 20:45:55 +02001561 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1562 alt {
1563 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1564 [] RSL_CCHAN.receive { repeat }
1565 }
1566
Harald Welte3453ab42019-05-24 21:19:58 +02001567 var GsmFrameNumber fn_last := 0;
1568 for (var integer i := 0; i < 1000; i := i+1) {
1569 var OCT1 ra := f_rnd_ra_cs();
1570 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1571 if (fn == fn_last) {
1572 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1573 }
1574 fn_last := fn;
1575 }
1576
1577 timer T := 5.0;
1578 T.start;
1579 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001580 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001581 -> value rx_ud {
1582 var RSL_IE_Body ie;
1583 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1584 load_access_count := load_access_count + ie.rach_load.access_count;
1585 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1586 setverdict(fail, "Access count cannot be < Busy count");
1587 }
1588 repeat;
1589 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001590 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001591 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1592 repeat;
1593 }
1594 [] RSL_CCHAN.receive {
1595 repeat;
1596 }
1597 [] T.timeout { }
1598 }
1599 if (load_access_count == 1000) {
1600 setverdict(pass);
1601 } else {
1602 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1603 }
1604
1605 f_vty_load_ind_thresh(10);
1606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1607}
1608
Harald Welte54a2a2d2018-02-26 09:14:05 +01001609private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001610 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001611 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001612 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001613 f_sleep(0.5);
1614
1615 /* Transmit RACH request + wait for confirmation */
1616 var OCT1 ra := f_rnd_ra_cs();
1617 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1618
1619 /* Check for expected result */
1620 timer T := 1.5;
1621 T.start;
1622 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001623 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001624 setverdict(pass);
1625 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001626 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001628 }
1629 [] RSL_CCHAN.receive { repeat; }
1630 [not expect_pass] T.timeout {
1631 setverdict(pass);
1632 }
1633 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001634 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001635 }
1636 }
1637}
1638
1639/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1640testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001641 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001642 f_init_l1ctl();
1643 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001644 f_sleep(1.0);
1645
1646 /* default max-ta is 63 (full range of GSM timing advance */
1647
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001648 /* We allow early arrival up to 2 symbols */
1649 f_rach_toffs(-1*256, true);
1650 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001651 f_rach_toffs(-10*256, false);
1652
1653 /* 0 / 32 / 63 bits is legal / permitted */
1654 f_rach_toffs(0, true);
1655 f_rach_toffs(32*256, true);
1656 f_rach_toffs(63*256, true);
1657
1658 /* more than 63 bits is not legal / permitted */
1659 f_rach_toffs(64*256, false);
1660 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001662}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001663
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001664private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001665 var GsmFrameNumber fn;
1666 var RSL_Message rm;
1667
1668 f_l1_tune(L1CTL);
1669 RSL.clear;
1670
1671 /* Generate a random Handover Reference */
1672 var integer ho_ref := oct2int(f_rnd_octstring(1));
1673
1674 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1675 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1676 RSL_IE_Body:{ handover_ref := ho_ref }));
1677
1678 /* Activate a channel on the BTS side (no encryption) */
1679 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1680 act_type := t_RSL_IE_ActType_HO_SYNC);
1681
1682 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1683 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001684 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001685
1686 /* Send handover Access Burst */
1687 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1688
1689 /* TODO: test mismatching Handover Reference, and missing IE */
1690
1691 /* Wait for handover detection */
1692 timer T := 3.0;
1693 T.start;
1694 alt {
1695 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1696 log("Handover RACH has been detected: ", rm);
1697 setverdict(pass);
1698 }
1699 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1701 log2str("RSL_CHAN_RQD was not expected: ", rm));
1702 }
1703 [] RSL.receive { repeat; }
1704 [] T.timeout {
1705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1706 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1707 }
1708 }
1709
1710 /* Release the channel */
1711 f_rsl_chan_deact();
1712 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1713}
1714
1715/* Test handover RACH detection */
1716testcase TC_ho_rach() runs on test_CT {
1717 var ConnHdlrPars pars;
1718 var ConnHdlr vc_conn;
1719
1720 f_init();
1721
1722 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1723 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1724 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1725 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1726 vc_conn.done;
1727 }
1728
1729 /* TODO: do the above in parallel, rather than sequentially? */
1730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1731}
1732
Harald Welte93640c62018-02-25 16:59:33 +01001733/***********************************************************************
1734 * Measurement Processing / Reporting
1735 ***********************************************************************/
1736
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001737private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001738 spare := '0'B,
1739 lpd := 0,
1740 sapi := sapi,
1741 c_r := c_r,
1742 ea := true
1743}
1744
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001745private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001746 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001747 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001748 len := 0, /* overwritten */
1749 m := false,
1750 el := 1,
1751 payload := pl
1752}
1753
1754/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001755private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001756 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001757 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001758 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001759 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, mp_rxlev_exp, mp_rxlev_exp, 0, 0, omit));
Harald Welted879bd92018-03-12 15:01:23 +01001760 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001761 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001762
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001763 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1764 g_pars.l1_pars.ms_power_level, false,
1765 g_pars.l1_pars.ms_actual_ta);
1766
1767 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1768 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1769
1770 log("Sending Measurement Report: ", l1h, l2);
1771 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001772 repeat;
1773 }
1774}
1775
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001776private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001777 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001778 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001779 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1780 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001781 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1782 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001783 repeat;
1784 }
1785}
1786
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001787private altstep as_l1_tch_loop() runs on ConnHdlr {
1788 var L1ctlDlMessage l1_dl;
1789 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1790 log("TCH received: ", l1_dl.payload.traffic_ind.data);
1791 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1792 l1_dl.payload.traffic_ind.data));
1793 repeat;
1794 }
1795}
1796
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001797private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001798 uint6_t rxlev,
1799 uint3_t rxqual
1800}
1801
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001802private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001803 MeasElem full,
1804 MeasElem sub
1805}
1806
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001807private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001808 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001809 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001810 MeasElemFS meas_ul,
1811 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001812 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001813 uint5_t ms_power_level,
1814 uint8_t ms_actual_ta
1815}
1816
1817/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1818private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1819 return 63 + (toffs256s/256);
1820}
1821
Harald Welted5684392018-03-10 18:22:04 +01001822private function f_max(integer a, integer b) return integer {
1823 if (a > b) {
1824 return a;
1825 } else {
1826 return b;
1827 }
1828}
1829
1830private function f_min(integer a, integer b) return integer {
1831 if (a < b) {
1832 return a;
1833 } else {
1834 return b;
1835 }
1836}
1837
1838/* compute negative tolerance val-tolerance, ensure >= min */
1839private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1840 val := val - tolerance;
1841 return f_max(val, min);
1842}
1843
1844/* compute positive tolerance val+tolerance, ensure <= max */
1845private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1846 val := val + tolerance;
1847 return f_min(val, max);
1848}
1849
1850/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1851private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1852return template integer {
1853 var template integer ret;
1854 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1855 return ret;
1856}
1857
1858
Harald Welte70767382018-02-21 12:16:40 +01001859/* build a template for matching measurement results against */
1860private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1861 var ConnL1Pars l1p := g_pars.l1_pars;
1862 var template RSL_IE_UplinkMeas ul_meas := {
1863 len := 3,
1864 rfu := '0'B,
1865 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001866 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001867 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001868 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001869 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001870 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1871 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001872 supp_meas_info := omit
1873 };
Harald Welte685d5982018-02-27 20:42:05 +01001874 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001875 ul_meas.len := (3+8);
1876 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001877 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001878 toa256_min := ?,
1879 toa256_max := ?,
1880 toa256_std_dev := ?
1881 }
Harald Welte685d5982018-02-27 20:42:05 +01001882 }
Harald Welte70767382018-02-21 12:16:40 +01001883 var template RSL_IE_BS_Power bs_power := {
1884 reserved := 0,
1885 epc := false,
1886 fpc := false,
1887 power_level := l1p.bs_power_level
1888 };
1889 var template RSL_IE_L1Info l1_info := {
1890 ms_power_lvl := l1p.ms_power_level,
1891 fpc := false,
1892 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001893 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001894 };
1895 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001896 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001897 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1898 ?, t_toffs);
1899}
1900
Philipp Maierdd841d32019-12-17 14:44:54 +01001901/* build a template for matching measurement results that do not contain any
1902 * MS related measurement (l1_info, l3_info and ms timing offset). */
1903private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1904 var ConnL1Pars l1p := g_pars.l1_pars;
1905 var template RSL_IE_UplinkMeas ul_meas := {
1906 len := 3,
1907 rfu := '0'B,
1908 dtx_d := l1p.dtx_enabled,
1909 rxlev_f_u := ?,
1910 reserved1 := '00'B,
1911 rxlev_s_u := ?,
1912 reserved2 := '00'B,
1913 rxq_f_u := ?,
1914 rxq_s_u := ?,
1915 supp_meas_info := omit
1916 };
1917 if (l1p.toa256_enabled) {
1918 ul_meas.len := (3+8);
1919 ul_meas.supp_meas_info := {
1920 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1921 toa256_min := ?,
1922 toa256_max := ?,
1923 toa256_std_dev := ?
1924 }
1925 }
1926 var template RSL_IE_BS_Power bs_power := {
1927 reserved := 0,
1928 epc := false,
1929 fpc := false,
1930 power_level := l1p.bs_power_level
1931 };
1932
1933 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1934}
1935
Harald Welte70767382018-02-21 12:16:40 +01001936/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001937private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001938 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001939 var boolean chan_est := false;
1940
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001941 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001942
1943 /* Receive osmocom specific measurement reports. This is the normal
1944 * case. Here we verify that the measurement reports we sent are
1945 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001946 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1947 /* increment counter of next to-be-expected meas rep */
1948 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1949 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001950 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001951
1952 /* The following two cases may only happen in the beginning
1953 * of the channel establishment phase. Once we have received
1954 * the "our" measurement report the first time, the channel
1955 * is established and empty or hardcoded TRXCON reports must
1956 * not occur anymore. */
1957 chan_est := true;
1958
1959 repeat;
1960 }
1961
1962 /* When the BTS has established the channel, the MS might need slightly
1963 * more time to establish the channel and actually start sending. The
1964 * result is then a measurement report that just lacks the measurement
1965 * information of the MS. This is normal and we tolerate this behavior. */
1966 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1967 /* increment counter of next to-be-expected meas rep */
1968 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1969 /* Re-start the timer expecting the next MEAS RES */
1970 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001971 repeat;
1972 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001973
1974 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1975 * measurements if the TTCN3 side does not supply measurement input in
1976 * time. In those cases TRXCON will either use a cached measurement
1977 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1978 * report the templates above will not match. We tolerate this
1979 * behavior, but only once. */
1980 [chan_est == false] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001981 /* increment counter of next to-be-expected meas rep */
1982 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1983 if (g_first_meas_res) {
1984 g_first_meas_res := false;
1985 repeat;
1986 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001988 }
Harald Welte70767382018-02-21 12:16:40 +01001989 }
1990 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001992 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001993 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001994 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001995 }
1996}
1997
Harald Weltee613f962018-04-18 22:38:16 +02001998private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1999 select (rsl_alg_id) {
2000 case (RSL_ALG_ID_A5_0) { return 0; }
2001 case (RSL_ALG_ID_A5_1) { return 1; }
2002 case (RSL_ALG_ID_A5_2) { return 2; }
2003 case (RSL_ALG_ID_A5_3) { return 3; }
2004 case (RSL_ALG_ID_A5_4) { return 4; }
2005 case (RSL_ALG_ID_A5_5) { return 5; }
2006 case (RSL_ALG_ID_A5_6) { return 6; }
2007 case (RSL_ALG_ID_A5_7) { return 7; }
2008 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2010 /* Make compiler happy by calling mtc.stop here. It is already
2011 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002012 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002013 }
2014 }
2015}
2016
2017private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2018 select (rsl_alg_id) {
2019 case (RSL_ALG_ID_A5_1) { return '000'B; }
2020 case (RSL_ALG_ID_A5_2) { return '001'B; }
2021 case (RSL_ALG_ID_A5_3) { return '010'B; }
2022 case (RSL_ALG_ID_A5_4) { return '011'B; }
2023 case (RSL_ALG_ID_A5_5) { return '100'B; }
2024 case (RSL_ALG_ID_A5_6) { return '101'B; }
2025 case (RSL_ALG_ID_A5_7) { return '110'B; }
2026 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002027 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2028 /* Make compiler happy by calling mtc.stop here. It is already
2029 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002030 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002031 }
2032 }
2033}
2034
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002035/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2036private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2037 var GsmFrameNumber fn;
2038 timer T := 8.0;
2039
2040 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2041 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2042
2043 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2044 /* Send the actual RACH */
2045 fn := f_L1CTL_RACH(L1CTL, ra);
2046
2047 T.start;
2048 alt {
2049 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2050 [] T.timeout {
2051 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2052 }
2053 }
2054 T.stop
2055 return fn;
2056}
Harald Weltee613f962018-04-18 22:38:16 +02002057
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002058/* Tune to a dedicated channel: L1CTL only */
2059private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002060 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002061 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2062 7 /* TODO: mp_tsc */,
2063 mp_trx0_arfcn));
2064 } else {
2065 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2066 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002067 pars.fhp.maio_hsn.hsn,
2068 pars.fhp.maio_hsn.maio,
2069 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002070 }
2071}
2072
Harald Welte70767382018-02-21 12:16:40 +01002073/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002074private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002075 var GsmFrameNumber fn;
2076 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002077 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002078 var integer ra := 23;
2079
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002080 /* Send RACH request and wait for ChanReq */
2081 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002082
2083 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002084 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002085
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002086 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002087 if (g_pars.fhp.enabled) {
2088 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002089 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002090 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002091 }
2092
Harald Welte70767382018-02-21 12:16:40 +01002093 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002094 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.fhp.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01002095 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2096
2097 /* receive IMM.ASS on MS side */
2098 var ImmediateAssignment ia_um;
2099 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002100
2101 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2102 if (ch_desc.h != ia_um.chan_desc.h) {
2103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2104 }
2105
Harald Welte70767382018-02-21 12:16:40 +01002106 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002107 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002108 /* enable encryption, if requested */
2109 if (encr_enable) {
2110 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2111 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2112 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002113
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002114 /* Send TCH Mode Request to the L1 if needed */
2115 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2116 var L1ctlTchMode tch_mode;
2117
2118 select (g_pars.chan_mode.coding_alg_rate) {
2119 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2120 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2121 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2122 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2123 case else {
2124 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2125 " is not supported by the L1, falling back to signalling");
2126 tch_mode := L1CTL_CHAN_MODE_SIGN;
2127 }
2128 }
2129
2130 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2131 }
2132
Harald Weltefa45e9e2018-03-10 18:59:03 +01002133 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002134}
2135
2136/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002137private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002138 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002139 RSL.clear;
2140
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002141 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002142 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002143 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002144 }
Harald Welte70767382018-02-21 12:16:40 +01002145
2146 f_est_dchan();
2147
2148 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2149 * RSL measurement reports on Abis side */
2150 timer T := 8.0;
2151 T.start;
2152 alt {
2153 [] as_l1_sacch();
2154 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002155 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002156 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002157 [] L1CTL.receive { repeat; }
2158 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002159 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002160 * of any earlier errors, so if we reach this timeout, we're good */
2161 setverdict(pass);
2162 }
2163 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002165 }
2166 }
2167 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002168 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002169}
Harald Welte0472ab42018-03-12 15:02:26 +01002170
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002171/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2172private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002173 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002174 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2175 timer Tup := 10.0;
2176 Tup.start;
2177 alt {
2178 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2179 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2180 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002181
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002182 if (rx_lvl != max_rx_lvl) {
2183 repeat;
2184 }
2185 Tup.stop;
2186 }
2187 [] L1CTL.receive { repeat; }
2188 [] Tup.timeout {
2189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2190 log2str("Didn't reach full power ", max_rx_lvl));
2191 }
2192 }
2193 return max_rx_lvl;
2194}
2195
2196/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2197private function f_verify_ramp_up() runs on ConnHdlr {
2198 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002199 var integer initial_rx_lvl := -1;
2200 var integer last_rx_lvl := -1;
2201 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2202
2203 timer T := 2.0;
2204 alt {
2205 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2206 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2207 log("Received rx_level=", rx_lvl);
2208 if (initial_rx_lvl == -1) {
2209 initial_rx_lvl := rx_lvl;
2210 last_rx_lvl := rx_lvl;
2211
2212 /* Expect a somehow low value during first received messages */
2213 if (initial_rx_lvl >= max_rx_lvl / 2) {
2214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2215 log2str("Detected high initial tx power during ramp up: ",
2216 initial_rx_lvl , ", full power is", max_rx_lvl));
2217 }
2218 }
2219
2220 /* received Rx level bigger than maximum allowed power by CN */
2221 if (rx_lvl > max_rx_lvl) {
2222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2223 log2str("Detected Tx power higher than full power: ",
2224 rx_lvl , " > ", max_rx_lvl));
2225 }
2226
2227 /* Make sure it never decreases, since we are rumping up */
2228 if (last_rx_lvl > rx_lvl) {
2229 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2230 log2str("Detected Tx power decrease during ramp up: ",
2231 last_rx_lvl , " -> ", rx_lvl));
2232 }
2233
2234 if (rx_lvl == max_rx_lvl and not T.running) {
2235 /* We reached the maximum power, start timer and receive
2236 /* a few more to make sure we don't surpass it */
2237 log("Reached full power, wating a bit more until success");
2238 T.start;
2239 }
2240
2241 last_rx_lvl := rx_lvl;
2242 repeat;
2243 }
2244 [] L1CTL.receive { repeat; }
2245 [] T.timeout { }
2246 }
2247
2248 /* We didn't increase tx power during ramp up */
2249 if (initial_rx_lvl < last_rx_lvl) {
2250 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2251 } else {
2252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2253 log2str("No Tx power increase during whole ramp up: ",
2254 initial_rx_lvl , " -> ", last_rx_lvl));
2255 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002256}
2257
2258/* verify BTS ramps power down to rx_level 0 */
2259private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2260 var L1ctlDlMessage l1_dl;
2261 var integer last_rx_lvl := max_rx_lvl;
2262
2263 timer Tdown := 5.0;
2264 Tdown.start;
2265 alt {
2266 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2267 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2268 log("Received rx_level=", rx_lvl);
2269
2270 /* received Rx level bigger than maximum allowed power by CN */
2271 if (rx_lvl > max_rx_lvl) {
2272 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2273 log2str("Detected Tx power higher than full power: ",
2274 rx_lvl , " > ", max_rx_lvl));
2275 }
2276
2277 /* Make sure it never increases, since we are rumping down */
2278 if (last_rx_lvl < rx_lvl) {
2279 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2280 log2str("Detected Tx power increase during ramp up: ",
2281 last_rx_lvl , " -> ", rx_lvl));
2282 }
2283
2284 last_rx_lvl := rx_lvl;
2285 if (last_rx_lvl != 0) {
2286 repeat;
2287 }
2288 /* we reached power level 0, we are done */
2289 Tdown.stop;
2290 }
2291 [] L1CTL.receive { repeat; }
2292 [] Tdown.timeout { }
2293 }
2294
2295 /* We didn't increase tx power during ramp down */
2296 if (max_rx_lvl > last_rx_lvl) {
2297 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2298 } else {
2299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2300 log2str("No Tx power decrease during whole ramp down: ",
2301 max_rx_lvl , " -> ", last_rx_lvl));
2302 }
2303}
2304
2305/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002306private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002307 f_l1_tune(L1CTL);
2308 RSL.clear;
2309
2310 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002311
2312 setverdict(pass);
2313}
2314testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2315 var ConnHdlr vc_conn;
2316 var ConnHdlrPars pars;
2317 f_init();
2318 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2319 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2320 pcu_comp := false, trxc_comp := true);
2321 vc_conn.done;
2322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2323}
2324
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002325/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002326private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002327 f_connhdlr_init_vty_bsc();
2328
2329 f_l1_tune(L1CTL);
2330 RSL.clear;
2331
2332 /* Wait until BTS is started and at full power */
2333 var integer max_rx_lvl := f_wait_ramp_up();
2334 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2335
2336 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2337 f_verify_ramp_down(max_rx_lvl);
2338
2339 setverdict(pass);
2340}
2341testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2342 var ConnHdlr vc_conn;
2343 var ConnHdlrPars pars;
2344 f_init();
2345 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2346 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2347 pcu_comp := false, trxc_comp := true);
2348 vc_conn.done;
2349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2350}
2351
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002352/* Verify Tx power:
2353 * + ramping down during ADM state UNLOCKED->LOCKED
2354 * + ramping up during ADM state LOCKED->UNLOCKED
2355 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002356private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002357 var L1ctlDlMessage l1_dl;
2358 var integer last_rx_lvl;
2359
2360 f_connhdlr_init_vty_bsc();
2361
2362 f_l1_tune(L1CTL);
2363 RSL.clear;
2364
2365 /* Wait until BTS is started and at full power */
2366 var integer max_rx_lvl := f_wait_ramp_up();
2367 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2368
2369 log("ADM STATE UNLOCKED->LOCKED");
2370 f_vty_enter_cfg_trx(BSCVTY);
2371 f_vty_transceive(BSCVTY, "rf_locked 1");
2372 last_rx_lvl := max_rx_lvl;
2373 f_verify_ramp_down(max_rx_lvl);
2374
2375 /* Let some time after we received 0dBm, then check we don't receive BCCH
2376 * anymore because scheduler has stopped after ramping down */
2377 f_sleep(2.0);
2378 L1CTL.clear;
2379 timer Tlocked := 2.0;
2380 Tlocked.start;
2381 alt {
2382 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2383 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2384 log2str("Received data_ind during rf_locked: ", l1_dl));
2385 }
2386 [] L1CTL.receive { repeat; }
2387 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2388 }
2389
2390 log("ADM STATE LOCKED->UNLOCKED");
2391 f_vty_transceive(BSCVTY, "rf_locked 0");
2392 f_verify_ramp_up();
2393 setverdict(pass);
2394}
2395testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2396 var ConnHdlr vc_conn;
2397 var ConnHdlrPars pars;
2398 f_init();
2399 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2400 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2401 pcu_comp := false, trxc_comp := true);
2402 vc_conn.done;
2403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2404}
2405
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002406private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002407 timer T := 8.0;
2408 T.start;
2409 var RSL_Message rsl;
2410 alt {
2411 [] as_l1_sacch();
2412 [] L1CTL.receive { repeat; }
2413 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2414 if (rsl.ies[3].body.bs_power.power_level == level) {
2415 setverdict(pass)
2416 } else {
2417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2418 }
2419 }
2420 [] T.timeout {
2421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2422 }
2423 }
2424}
2425
2426/* see if the rsl meas res contains our expeced bs power level
2427bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002428private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002429 f_l1_tune(L1CTL);
2430 RSL.clear;
2431
2432 if (mp_bts_trxc_port != -1) {
2433 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2434 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2435 }
2436
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002437 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002438 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2439 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2440
2441 f_est_dchan(more_ies :={valueof(pwr)});
2442
2443 f_check_meas_bs_power_level(pwr_var);
2444
2445 f_rsl_chan_deact();
2446 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2447}
2448
2449/* see if the rsl meas res contains our expeced bs power level
2450bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002451private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002452 f_l1_tune(L1CTL);
2453 RSL.clear;
2454
2455 if (mp_bts_trxc_port != -1) {
2456 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2457 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2458 }
2459
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002460 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002461 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2462
2463 f_est_dchan();
2464
2465 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2466
2467 f_check_meas_bs_power_level(pwr_var);
2468
2469 f_rsl_chan_deact();
2470 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2471}
2472
2473testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2474 var ConnHdlr vc_conn;
2475 var ConnHdlrPars pars;
2476 f_init();
2477 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2478 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2479 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2480 pcu_comp := false, trxc_comp := true);
2481 vc_conn.done;
2482 }
2483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2484}
2485
2486testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2487 var ConnHdlr vc_conn;
2488 var ConnHdlrPars pars;
2489 f_init();
2490 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2491 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2492 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2493 pcu_comp := false, trxc_comp := true);
2494 vc_conn.done;
2495 }
2496 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2497}
2498
Eric Wild61edb7e2019-06-03 12:38:31 +02002499/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2500second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2501These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002502private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002503 var uint5_t pwr_var := 7;
2504 var L1ctlDlMessage l1_dl;
2505
2506 f_trxc_fake_rssi(rxlev2dbm(10));
2507 f_l1_tune(L1CTL);
2508 RSL.clear;
2509
2510 var RSL_IE_List addl_ies;
2511 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2512
2513 addl_ies := {
2514 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2515 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2516 };
2517
2518 /* establish with power parameters */
2519 f_est_dchan(more_ies := addl_ies);
2520
2521 /* set a high value to ensure L1 power control level increases */
2522 f_trxc_fake_rssi(rxlev2dbm(20));
2523
2524 timer T2 := 6.0;
2525 T2.start;
2526 alt {
2527 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002528 /* Update sent MS power to follow what BTS requests */
2529 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2530 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002531 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002532 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002533 T2.stop;
2534 }
2535 [] L1CTL.receive { repeat; }
2536 [] T2.timeout {
2537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2538 "Power Level in L1 header has not increased sufficiently");
2539 }
2540 }
2541
2542 /* set a low value to ensure L1 power control level decreases */
2543 f_trxc_fake_rssi(rxlev2dbm(0));
2544
2545 timer T4 := 6.0;
2546 T4.start;
2547 alt {
2548 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002549 /* Update sent MS power to follow what BTS requests */
2550 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2551 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002552 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002553 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002554 T4.stop;
2555 setverdict(pass, "Power level in L1 decreased/increased as expected");
2556 }
2557 [] L1CTL.receive { repeat; }
2558 [] T4.timeout {
2559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2560 "Power Level in L1 header has not decreased sufficiently");
2561 }
2562 }
2563
2564 f_rsl_chan_deact();
2565 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2566
2567}
2568
2569/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002570private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002571 var uint5_t pwr_var := 7;
2572 var L1ctlDlMessage l1_dl;
2573
2574 /* set a low value to ensure power increases */
2575 f_trxc_fake_rssi(rxlev2dbm(10));
2576 f_l1_tune(L1CTL);
2577 RSL.clear;
2578
2579 var RSL_IE_List addl_ies;
2580 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2581
2582 addl_ies := {
2583 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2584 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2585 };
2586
2587 /* establish with power parameters */
2588 f_est_dchan(more_ies := addl_ies);
2589
2590 timer T1 := 10.0;
2591 T1.start;
2592 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002593 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2594 /* Update sent MS power to follow what BTS requests */
2595 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2596 repeat;
2597 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002598 [] L1CTL.receive { repeat; }
2599 [] T1.timeout {
2600 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2601 setverdict(fail, "Power level in L1 header should not have changed");
2602 }
2603 }
2604 }
2605
2606 f_rsl_chan_deact();
2607 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2608
2609}
2610
2611/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002612private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002613 var L1ctlDlMessage l1_dl;
2614 var uint5_t pwr_var := 15;
2615 var uint5_t pwr_max_var := f_get_max_power_from_band();
2616
2617 /* set a low value to ensure power increases */
2618 f_trxc_fake_rssi(rxlev2dbm(10));
2619 f_l1_tune(L1CTL);
2620 RSL.clear;
2621
2622 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2623 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2624
2625 /* establish with fixed power level */
2626 f_est_dchan(more_ies :={valueof(pwr)});
2627
2628 /* check our initial power level */
2629 f_wait_for_l1_power_level(pwr_var);
2630
2631 /* update power param to enable power loop
2632 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2633 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2634
2635 /* wait, then check that our power level was reduced */
2636 timer T1 := 10.0;
2637 T1.start;
2638 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002639 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2640 /* Update sent MS power to follow what BTS requests */
2641 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2642 repeat;
2643 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002644 [] L1CTL.receive { repeat; }
2645 [] T1.timeout {
2646 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2647 if( f_power_level_is_highest_dbm(rcv) ){
2648 setverdict(pass, "Power level in L1 header reduced as expected");
2649 } else {
2650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2651 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2652 }
2653 }
2654 }
2655
2656 f_rsl_chan_deact();
2657 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2658
2659}
2660
2661/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002662private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002663 var L1ctlDlMessage l1_dl;
2664
2665 /* set a high value to ensure power decreases */
2666 f_trxc_fake_rssi(rxlev2dbm(50));
2667 f_l1_tune(L1CTL);
2668 RSL.clear;
2669
2670 var uint5_t pwr_var := 5;
2671 var uint5_t pwr_target_val := 15;
2672
2673 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2674 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2675
2676 /* establish with fixed power level */
2677 f_est_dchan(more_ies :={valueof(pwr)});
2678
2679 /* check our initial power level */
2680 f_wait_for_l1_power_level(pwr_var);
2681
2682 /* update power param to enable power loop
2683 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002684 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002685
2686 /* wait, then check that our power level was increased */
2687 timer T1 := 10.0;
2688 T1.start;
2689 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002690 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2691 /* Update sent MS power to follow what BTS requests */
2692 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2693 repeat;
2694 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002695 [] L1CTL.receive { repeat; }
2696 [] T1.timeout {
2697 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2698 setverdict(pass, "Power level in L1 header increased to lowest power value");
2699 } else {
2700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2701 "Power level in L1 header NOT increased to lowest power value");
2702 }
2703 }
2704 }
2705
2706 f_rsl_chan_deact();
2707 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2708
2709}
2710
Eric Wild095024b2019-06-17 15:08:57 +02002711/* see if we change the power level without receiving power parameters, which should not happen
2712rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002713private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002714 var L1ctlDlMessage l1_dl;
2715
2716 /* set a high value to ensure power decreases */
2717 f_trxc_fake_rssi(rxlev2dbm(50));
2718 f_l1_tune(L1CTL);
2719 RSL.clear;
2720
2721 var uint5_t pwr_var := 5;
2722
2723 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2724 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2725
2726 /* establish with fixed power level */
2727 f_est_dchan(more_ies :={valueof(pwr)});
2728
2729 /* check our initial power level */
2730 f_wait_for_l1_power_level(pwr_var);
2731
2732 /* wait, then check that our power level did not change */
2733 timer T1 := 10.0;
2734 T1.start;
2735 alt {
2736 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2737 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2738 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2739 "BS power control should not be active unless we receive a power parameters IE!");
2740 }
2741 repeat;
2742 }
2743 [] L1CTL.receive { repeat; }
2744 [] T1.timeout { setverdict(pass); }
2745 }
2746
2747 f_rsl_chan_deact();
2748 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2749
2750}
2751
Eric Wild095024b2019-06-17 15:08:57 +02002752/* see if we change the power level without receiving power parameters, which should not happen
2753ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002754private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002755 var L1ctlDlMessage l1_dl;
2756
2757 /* set a high value to ensure power decreases */
2758 f_trxc_fake_rssi(rxlev2dbm(50));
2759 f_l1_tune(L1CTL);
2760 RSL.clear;
2761
2762 var uint5_t pwr_var := 5;
2763
2764 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2765 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2766
2767 /* establish with fixed power level */
2768 f_est_dchan(more_ies :={valueof(pwr)});
2769
2770 /* check our initial power level */
2771 f_wait_for_l1_power_level(pwr_var);
2772
2773 /* pwr control without power params IE, should NOT activate MS power control*/
2774 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2775
2776 /* wait, then check that our power level did not change */
2777 timer T1 := 10.0;
2778 T1.start;
2779 alt {
2780 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2781 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2783 "BS power control should not be active unless we receive a power parameters IE!");
2784 }
2785 repeat;
2786 }
2787 [] L1CTL.receive { repeat; }
2788 [] T1.timeout { setverdict(pass); }
2789 }
2790
2791 f_rsl_chan_deact();
2792 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2793
2794}
2795
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002796private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002797 var L1ctlDlMessage l1_dl;
2798 timer T0 := 10.0;
2799 T0.start;
2800 alt {
2801 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2802 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2803 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2804 "Power level in L1 header != signaled (RSL) power level.");
2805 }
2806 }
2807 [] L1CTL.receive { repeat; }
2808 [] T0.timeout {
2809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2810 "Timeout waiting for initial power level");
2811 }
2812 }
2813 T0.stop;
2814}
2815
2816private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2817 var IntegerRecord min_dbm_level;
2818 var IntegerRecord max_dbm_level;
2819 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2820
2821 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2822 if (min_dbm_level[i] == level) {
2823 return true;
2824 }
2825 }
2826 return false;
2827}
2828
2829private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2830 var IntegerRecord min_dbm_level;
2831 var IntegerRecord max_dbm_level;
2832 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2833
2834 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2835 if (max_dbm_level[i] == level) {
2836 return true;
2837 }
2838 }
2839 return false;
2840}
2841
2842private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2843 var IntegerRecord min_dbm_level;
2844 var IntegerRecord max_dbm_level;
2845 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2846 return max_dbm_level[0];
2847}
2848
2849type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002850private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002851private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2852 // 45.005 4.1.1
2853 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2854 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2855 2, 1, 0};
2856 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2857 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2858 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2859 var IntegerRecord rv;
2860
2861 select(band){
2862 case (BtsBand_allGSM){
2863 rv := gsm_power;
2864 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2865 max_dbm_level := {2, 1, 0};
2866 }
2867 case("DCS1800"){
2868 rv := dcs_power;
2869 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2870 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2871 }
2872 case("PCS1900"){
2873 rv := pcs_power;
2874 min_dbm_level := {15};
2875 max_dbm_level := {30};
2876 }
Harald Welte194b6912020-10-11 21:01:55 +02002877 case else {
2878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2879 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002880 }
2881
2882 return rv;
2883}
2884
2885private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002886 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of*type* in band (\w+),*", 0);
Eric Wild61edb7e2019-06-03 12:38:31 +02002887}
2888
2889testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2890 var ConnHdlr vc_conn;
2891 var ConnHdlrPars pars;
2892 f_init();
2893 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2894 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2895 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2896 pars.bts0_band := f_vty_get_bts0_band();
2897 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2898 vc_conn.done;
2899 }
2900 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2902}
2903
2904testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2905 var ConnHdlr vc_conn;
2906 var ConnHdlrPars pars;
2907 f_init();
2908 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2909 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2910 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2911 pars.bts0_band := f_vty_get_bts0_band();
2912 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2913 vc_conn.done;
2914 }
2915 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2916 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2917}
2918
2919testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2920 var ConnHdlr vc_conn;
2921 var ConnHdlrPars pars;
2922 f_init();
2923 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2924 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2925 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2926 pars.bts0_band := f_vty_get_bts0_band();
2927 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2928 vc_conn.done;
2929 }
2930 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2931 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2932}
2933
2934testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2935 var ConnHdlr vc_conn;
2936 var ConnHdlrPars pars;
2937 f_init();
2938 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2939 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2940 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2941 pars.bts0_band := f_vty_get_bts0_band();
2942 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2943 vc_conn.done;
2944 }
2945 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2946 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2947}
2948
Eric Wild280ccb82019-06-17 11:11:52 +02002949testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2950 var ConnHdlr vc_conn;
2951 var ConnHdlrPars pars;
2952 f_init();
2953 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2954 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2955 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2956 pars.bts0_band := f_vty_get_bts0_band();
2957 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2958 vc_conn.done;
2959 }
2960 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2962}
2963
Eric Wild095024b2019-06-17 15:08:57 +02002964testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2965 var ConnHdlr vc_conn;
2966 var ConnHdlrPars pars;
2967 f_init();
2968 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2969 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2970 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2971 pars.bts0_band := f_vty_get_bts0_band();
2972 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2973 vc_conn.done;
2974 }
2975 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2977}
2978
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07002979testcase TC_meas_res_speech_tchf() runs on test_CT {
2980 var template RSL_IE_ChannelMode ch_mode;
2981 var ConnHdlr vc_conn;
2982 var ConnHdlrPars pars;
2983 f_init();
2984 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
2985 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
2986 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
2987 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2988 pcu_comp := false, trxc_comp := true);
2989 vc_conn.done;
2990 }
2991 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2992}
2993testcase TC_meas_res_speech_tchh() runs on test_CT {
2994 var template RSL_IE_ChannelMode ch_mode;
2995 var ConnHdlr vc_conn;
2996 var ConnHdlrPars pars;
2997 f_init();
2998 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
2999 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3000 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3001 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3002 pcu_comp := false, trxc_comp := true);
3003 vc_conn.done;
3004 }
3005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3006}
3007
Harald Welte70767382018-02-21 12:16:40 +01003008testcase TC_meas_res_sign_tchf() runs on test_CT {
3009 var ConnHdlr vc_conn;
3010 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003011 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003012 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003013 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003014 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3015 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003016 vc_conn.done;
3017 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003018 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003019}
3020testcase TC_meas_res_sign_tchh() runs on test_CT {
3021 var ConnHdlr vc_conn;
3022 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003023 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003024 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003025 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003026 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3027 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003028 vc_conn.done;
3029 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003031}
3032testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3033 var ConnHdlr vc_conn;
3034 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003035 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003036 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3037 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003038 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3039 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003040 vc_conn.done;
3041 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003043}
3044testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3045 var ConnHdlr vc_conn;
3046 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003047 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003048 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3049 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003050 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3051 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003052 vc_conn.done;
3053 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003055}
Harald Welte685d5982018-02-27 20:42:05 +01003056testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3057 var ConnHdlr vc_conn;
3058 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003059 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003060 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3061 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003062 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003063 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003064 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3065 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003066 vc_conn.done;
3067 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003069}
3070
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003071/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3072 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003073private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003074 var L1ctlDlMessage l1_dl;
3075 var RSL_IE_MS_Power ms_power;
3076 var RSL_Message rsl;
3077 var uint5_t power_level := 0;
3078
3079 f_l1_tune(L1CTL);
3080 RSL.clear;
3081
3082 f_est_dchan();
3083
3084 ms_power.reserved := 0;
3085 ms_power.fpc_epc := false;
3086
3087 /* Send the first power control command. This will disable any BTS/TRX
3088 * internal power control and switch the MS (which is not in scope of
3089 * this test) to a constant power level. We start with a power level
3090 * of 0 */
3091 ms_power.power_level := power_level;
3092 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3093 RSL.send(rsl);
3094
3095 alt {
3096
3097 /* Pick all SACCH blocks for checking */
3098 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3099
3100 /* The first byte of the L1 header contains the power level.
3101 * The reserved bits and the fpc bit is set to 0, so we may
3102 * compare directly. */
3103 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3104 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3105 }
3106
3107 /* Signal a new power level via RSL for the next turn. */
3108 if (power_level < 31) {
3109 power_level := power_level + 1;
3110 ms_power.power_level := power_level;
3111 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3112 RSL.send(rsl);
3113 repeat;
3114 }
3115
3116 }
3117
3118 /* Ignore all other blocks */
3119 [] L1CTL.receive { repeat; }
3120
3121 }
3122
3123 f_rsl_chan_deact();
3124 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3125
3126 setverdict(pass);
3127}
3128
3129testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3130 var ConnHdlr vc_conn;
3131 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003132 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003133
3134 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3135 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3136 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3137 vc_conn.done;
3138 }
3139 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3140}
Harald Welte70767382018-02-21 12:16:40 +01003141
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003142/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003143TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003144private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003145 var L1ctlDlMessage l1_dl;
3146 var uint5_t ta_to_test := 16;
3147
3148
3149 f_l1_tune(L1CTL);
3150 RSL.clear;
3151
3152 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003153 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003154
3155 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3156
3157
3158 alt {
3159
3160 /* Pick all SACCH blocks for checking */
3161 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3162
3163 /* The second byte of the L1 header contains the TA. */
3164 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3165 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3166 }
3167
3168 }
3169
3170 /* Ignore all other blocks */
3171 [] L1CTL.receive { repeat; }
3172
3173 }
3174
3175 f_rsl_chan_deact();
3176 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3177
3178 setverdict(pass);
3179}
3180
3181testcase TC_rsl_chan_initial_ta() runs on test_CT {
3182 var ConnHdlr vc_conn;
3183 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003184 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003185 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003186 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3187 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003188 vc_conn.done;
3189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3190}
3191
Eric Wilde57e1a62019-05-28 13:30:55 +02003192/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003193private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003194 var L1ctlDlMessage l1_dl;
3195 var uint5_t ms_power_level := 7;
3196
3197 var RSL_IE_MS_Power ms_power;
3198 ms_power.reserved := 0;
3199 ms_power.fpc_epc := false;
3200 ms_power.power_level := ms_power_level;
3201
3202 f_l1_tune(L1CTL);
3203 RSL.clear;
3204
3205 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3206
3207 timer T := 1.0;
3208 T.start;
3209 alt {
3210 /* Pick all SACCH blocks for checking */
3211 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3212 /* The first byte of the L1 header contains the power level.. */
3213 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3214 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3215 }
3216 }
3217 /* Ignore all other blocks */
3218 [] L1CTL.receive { repeat; }
3219 [] T.timeout {
3220 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3221 }
3222 }
3223
3224 f_rsl_chan_deact();
3225 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3226 setverdict(pass);
3227}
3228
3229testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3230 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3231 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3232}
3233
Harald Welte0472ab42018-03-12 15:02:26 +01003234/* 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 +01003235private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003236 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003237 RSL.clear;
3238
3239 f_est_dchan();
3240 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003241 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003242
3243 timer T := 40.0;
3244 T.start;
3245 alt {
3246 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3247 setverdict(pass)
3248 }
3249 [] RSL.receive { repeat };
3250 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003252 }
3253 }
3254 f_rsl_chan_deact();
3255}
3256testcase TC_conn_fail_crit() runs on test_CT {
3257 var ConnHdlr vc_conn;
3258 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003259 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003260 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3261 pars.t_guard := 60.0;
3262 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3263 vc_conn.done;
3264}
3265
Harald Welte93640c62018-02-25 16:59:33 +01003266/***********************************************************************
3267 * Paging
3268 ***********************************************************************/
3269
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003270private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003271 if (tmsi == 'FFFFFFFF'O) {
3272 return true;
3273 } else {
3274 return false;
3275 }
3276}
Harald Welte70767382018-02-21 12:16:40 +01003277
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003278private type record allowedFn { integer frame_nr }
3279private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3280private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3281private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3282private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3283private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3284private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3285private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3286private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3287private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003288{
3289 var integer frame_nr_51;
3290 frame_nr_51 := frame_nr mod 51
3291
3292 var allowedFn fn_check;
3293 fn_check.frame_nr := frame_nr_51;
3294
3295 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003297 return;
3298 }
3299
3300 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3301 return;
3302 }
3303 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3304 return;
3305 }
3306 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3307 return;
3308 }
3309 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3310 return;
3311 }
3312 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3313 return;
3314 }
3315 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3316 return;
3317 }
3318 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3319 return;
3320 }
3321 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3322 return;
3323 }
3324
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003325 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003326 return;
3327}
3328
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003329private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3330 inout integer num_paging_rcv_ids,
3331 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003332runs on test_CT {
3333 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003334 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003335 repeat;
3336 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003337 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003338 var octetstring without_plen :=
3339 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3340 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003341
3342 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3343
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003344 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3345 /* Ignore empty RR Paging Request (PCH filling) messages.
3346 * TODO: does it make sense to count them? */
3347 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003348 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3349 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003350 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003351 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3352 }
3353 } else if (match(rr, tr_PAGING_REQ2)) {
3354 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3355 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3356 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3357 }
3358 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3359 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3360 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003361 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003362 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3363 }
3364 } else if (match(rr, tr_PAGING_REQ3)) {
3365 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3366 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3367 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3368 }
3369 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3370 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3371 }
3372 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3373 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3374 }
3375 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3376 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3377 }
3378 }
3379 repeat;
3380 }
3381}
3382
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003383private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003384 boolean combined_ccch,
3385 integer bs_ag_blks_res,
3386 float load_factor,
3387 boolean exp_load_ind,
3388 boolean exp_overload,
3389 boolean use_tmsi
3390}
3391
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003392private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003393 integer num_paging_sent,
3394 integer num_paging_rcv_msgs,
3395 integer num_paging_rcv_ids,
3396 integer num_overload
3397}
3398
Harald Welte68e495b2018-02-25 00:05:57 +01003399/* Helper function for paging related testing */
3400private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003401 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003402 f_init_l1ctl();
3403 f_l1_tune(L1CTL);
3404
3405 var PagingTestState st := {
3406 num_paging_sent := 0,
3407 num_paging_rcv_msgs := 0,
3408 num_paging_rcv_ids := 0,
3409 num_overload := 0
3410 };
3411
3412 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3413 var float max_pch_imsi_per_sec;
3414 if (cfg.use_tmsi) {
3415 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3416 } else {
3417 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3418 }
3419 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3420 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003421 var float time_total := 20.0;
3422 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3423 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003424
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003425 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3426 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003427
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003428 timer T_itv := 0.0;
3429 T_itv.start;
3430 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003431 alt {
3432 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003433 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003434 st.num_overload := st.num_overload + 1;
3435 repeat;
3436 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003437 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003439 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003440 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003441 log("Rx LOAD_IND");
3442 /* FIXME: analyze/verify interval + contents */
3443 repeat;
3444 }
3445 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003446 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003447 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003448 [] T_itv.timeout {
3449 /* Send paging cmds based on elapsed time */
3450 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3451 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003452 var MobileIdentityV mi;
3453
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003454 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003455 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003456 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003457 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003458 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003459 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003460
3461 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003462 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 +02003463
3464 st.num_paging_sent := st.num_paging_sent + 1;
3465 }
3466 if (st.num_paging_sent < pkt_total) {
3467 /* Wait for interval to next PAGING COMMAND */
3468 var float time_now := T_total.read;
3469 var float next_sched := int2float(st.num_paging_sent)*interval;
3470 if (next_sched > time_now) {
3471 T_itv.start(next_sched - time_now);
3472 } else {
3473 T_itv.start(0.0);
3474 }
3475 } else {
3476 /* We are done, no need to keep counting */
3477 T_total.stop;
3478 }
3479 }
3480 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003481 }
3482 }
3483
3484 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3485 timer T_wait := 18.0;
3486 T_wait.start;
3487 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003488 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003489 [] L1CTL.receive { repeat; }
3490 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003491 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3492 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003493 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003494 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003495 }
Harald Welte68e495b2018-02-25 00:05:57 +01003496 }
3497
3498 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3499 " rcvd_ids=", st.num_paging_rcv_ids);
3500 return st;
3501}
3502
3503/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3504 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3505 * - that CCCH LOAD IND (PCH) are being generated
3506 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3507testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003508 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003509 var PagingTestCfg cfg := {
3510 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003511 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003512 load_factor := 0.8,
3513 exp_load_ind := true,
3514 exp_overload := false,
3515 use_tmsi := false
3516 };
3517 var PagingTestState st := f_TC_paging(cfg);
3518 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003519 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3520 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003521 } else {
3522 setverdict(pass);
3523 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003524 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003525}
3526
3527/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3528 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3529 * - that CCCH LOAD IND (PCH) are being generated
3530 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3531testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003532 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003533 var PagingTestCfg cfg := {
3534 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003535 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003536 load_factor := 0.8,
3537 exp_load_ind := true,
3538 exp_overload := false,
3539 use_tmsi := true
3540 };
3541 var PagingTestState st := f_TC_paging(cfg);
3542 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3544 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003545 } else {
3546 setverdict(pass);
3547 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003548 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003549}
3550
3551/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3552 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3553 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3554 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3555testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003556 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003557 var PagingTestCfg cfg := {
3558 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003559 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003560 load_factor := 2.0,
3561 exp_load_ind := true,
3562 exp_overload := true,
3563 use_tmsi := false
3564 };
3565 var PagingTestState st := f_TC_paging(cfg);
3566 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3567 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003568 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003569 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003570 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 +01003571 } else {
3572 setverdict(pass);
3573 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003574 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003575}
3576
3577/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3578 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3579 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3580 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3581testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003582 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003583 var PagingTestCfg cfg := {
3584 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003585 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003586 load_factor := 2.0,
3587 exp_load_ind := true,
3588 exp_overload := true,
3589 use_tmsi := true
3590 };
3591 var PagingTestState st := f_TC_paging(cfg);
3592 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3593 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003594 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003595 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003596 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 +01003597 } else {
3598 setverdict(pass);
3599 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003600 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003601}
3602
3603
Harald Welte93640c62018-02-25 16:59:33 +01003604/***********************************************************************
3605 * Immediate Assignment / AGCH
3606 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003607private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003608 len := 0,
3609 ma := ''B
3610}
Harald Welte93640c62018-02-25 16:59:33 +01003611
Harald Weltee8d750e2018-06-10 21:41:35 +02003612private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3613 return int2str(num_tx) & " sent, "
3614 & int2str(num_rx) & " received, "
3615 & int2str(num_del) & " deleted";
3616}
3617
3618private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3619 var L1ctlDlMessage l1_dl;
3620 timer T := 10.0;
3621 var integer num_tx := 0;
3622 var integer num_rx := 0;
3623 var integer num_del := 0;
3624 var charstring res_str;
3625 var float rx_ratio;
3626
Harald Welte10474062019-05-30 16:48:17 +02003627 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003628 f_init_l1ctl();
3629 f_l1_tune(L1CTL);
3630
3631 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003632 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003633 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3634 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003635 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003636 num_tx := num_tx+1;
3637 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003638 }
3639 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003640 T.start;
3641 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003642 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003643 num_del := num_del+1;
3644 repeat;
3645 }
3646 [] RSL_CCHAN.receive {
3647 repeat;
3648 }
3649 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003650 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3651 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3652 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003653 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003654 } else {
3655 num_rx := num_rx+1;
3656 }
3657 repeat;
3658 }
3659 [] L1CTL.receive { repeat; }
3660 [] T.timeout { }
3661 }
3662 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3663 log("AGCH test: " & res_str);
3664 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003666 }
3667 rx_ratio := int2float(num_rx) / int2float(num_tx);
3668 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003669 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 +02003670 } else {
3671 setverdict(pass);
3672 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003674}
3675
Harald Weltee8d750e2018-06-10 21:41:35 +02003676/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3677testcase TC_imm_ass_1000_20ms() runs on test_CT {
3678 f_TC_imm_ass(1000, 0.02, 0.25);
3679}
3680
3681/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3682testcase TC_imm_ass_200_0ms() runs on test_CT {
3683 f_TC_imm_ass(200, 0.0, 0.05);
3684}
3685
3686/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3687testcase TC_imm_ass_200_76ms() runs on test_CT {
3688 f_TC_imm_ass(150, 0.076, 1.00);
3689}
3690
3691
3692
Harald Welte48494ca2018-02-25 16:59:50 +01003693/***********************************************************************
3694 * BCCH
3695 ***********************************************************************/
3696
3697/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003698private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003699 GsmFrameNumber frame_number,
3700 SystemInformation si
3701}
3702
3703/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003704private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003705
3706/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003707private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003708
3709/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003710private function f_si_vecslot_contains(SystemInformationVector arr,
3711 RrMessageType key,
3712 boolean bcch_ext := false)
3713return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003714 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3715 var integer fn_mod51 := arr[i].frame_number mod 51;
3716 if (not bcch_ext and fn_mod51 == 2 or
3717 bcch_ext and fn_mod51 == 6) {
3718 if (arr[i].si.header.message_type == key) {
3719 return true;
3720 }
3721 }
3722 }
3723 return false;
3724}
3725
3726/* 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 +07003727private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3728 integer tc, RrMessageType key,
3729 boolean ext_bcch := false)
3730{
Harald Welte48494ca2018-02-25 16:59:50 +01003731 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003733 }
3734}
3735
3736/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003737private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3738 RrMessageType key)
3739return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003740 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3741 if (f_si_vecslot_contains(arr[tc], key) or
3742 f_si_vecslot_contains(arr[tc], key, true)) {
3743 return true;
3744 }
3745 }
3746 return false;
3747}
3748
3749/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003750private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3751 RrMessageType key,
3752 boolean bcch_ext := false,
3753 integer n := 1, integer m := 4)
3754return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003755 var integer count := 0;
3756 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3758 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003759 }
3760 for (var integer i:= 0; i < m; i := i + 1) {
3761 var integer fn_mod51 := arr[i].frame_number mod 51;
3762 if (not bcch_ext and fn_mod51 == 2 or
3763 bcch_ext and fn_mod51 == 6) {
3764 if (arr[i].si.header.message_type == key) {
3765 count := count + 1;
3766 }
3767 }
3768 }
3769 if (count >= n) {
3770 return true;
3771 } else {
3772 return false;
3773 }
3774}
3775
3776/* 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 +07003777private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3778 integer tc, RrMessageType key,
3779 boolean ext_bcch := false,
3780 integer n, integer m)
3781{
Harald Welte48494ca2018-02-25 16:59:50 +01003782 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003783 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003784 }
3785}
3786
3787/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003788private function f_si_vecslot_contains_only(SystemInformationVector arr,
3789 RrMessageType key,
3790 boolean bcch_ext := false)
3791return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003792 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3793 var integer fn_mod51 := arr[i].frame_number mod 51;
3794 if (not bcch_ext and fn_mod51 == 2 or
3795 bcch_ext and fn_mod51 == 6) {
3796 if (arr[i].si.header.message_type != key) {
3797 return false;
3798 }
3799 }
3800 }
3801 return true;
3802}
3803
3804/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003805private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3806 integer tc, RrMessageType key,
3807 boolean ext_bcch := false)
3808{
Harald Welte48494ca2018-02-25 16:59:50 +01003809 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003810 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003811 }
3812}
3813
3814/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003815private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003816 boolean bcch_extended,
3817 boolean si1_present,
3818 boolean si2bis_present,
3819 boolean si2ter_present,
3820 boolean si2quater_present,
3821 boolean si7_present,
3822 boolean si8_present,
3823 boolean si9_present,
3824 boolean si13_present,
3825 boolean si13alt_present,
3826 boolean si15_present,
3827 boolean si16_present,
3828 boolean si17_present,
3829 boolean si2n_present,
3830 boolean si21_present,
3831 boolean si22_present
3832}
3833
3834/* 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 +07003835private function f_validate_si_scheduling(SystemInformationConfig cfg,
3836 SystemInformationVectorPerTc si_per_tc)
3837{
Harald Welte48494ca2018-02-25 16:59:50 +01003838 var integer i;
3839 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3840 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003841 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003842 }
3843 }
3844 if (cfg.si1_present) {
3845 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3846 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3847 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3848 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3849 /* make sure *ALL* contain SI1 */
3850 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3851 }
3852 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3853 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3854 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3855 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3856 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3857 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3858
3859 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3860 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3861 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3862 * consecutive occurrences of TC = 4. */
3863 if (cfg.si2bis_present and not cfg.si2ter_present) {
3864 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3865 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3866 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3867 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3868 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3869 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3870 }
3871
3872 if (cfg.si7_present or cfg.si8_present) {
3873 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3874 * if System Information type 4 does not contain all information needed for cell
3875 * selection and reselection. */
3876 if (not cfg.bcch_extended) {
3877 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3878 }
3879 if (cfg.si7_present) {
3880 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3881 }
3882 if (cfg.si8_present) {
3883 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3884 }
3885 }
3886
3887 if (cfg.si2quater_present) {
3888 /* iii) System information type 2 quater is sent if needed, as determined by the system
3889 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3890 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3891 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3892 * within any of 4 consecutive occurrences of TC = 5. */
3893 if (not (cfg.bcch_extended)) {
3894 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3895 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3896 } else {
3897 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3898 }
3899 } else {
3900 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3901 }
3902 }
3903 if (cfg.si9_present) {
3904 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3905 * in system information type 3 as defined in 3GPP TS 44.018. */
3906 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3907 }
3908 if (cfg.si13_present) {
3909 /* vii) System Information type 13 is only related to the GPRS service. System Information
3910 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3911 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3912 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3913 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3914 * within any of 4 consecutive occurrences of TC=4. */
3915 if (not cfg.bcch_extended) {
3916 log("not-bccch-extended");
3917 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3918 } else {
3919 log("bccch-extended");
3920 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3921 }
3922 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003923 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003924 }
3925 }
3926 if (cfg.si16_present or cfg.si17_present) {
3927 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3928 * should not be sent in a cell where network sharing is used (see rule xv). */
3929 if (cfg.si22_present) {
3930 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3931 }
3932 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003933 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003934 }
3935 if (not cfg.bcch_extended) {
3936 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3937 }
3938 if (cfg.si16_present) {
3939 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3940 }
3941 if (cfg.si17_present) {
3942 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3943 }
3944 }
3945
3946 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3947 * broadcast information. The frequency with which they are sent is determined by the
3948 * system operator. System Information type 9 identifies the scheduling of System
3949 * Information type 18 and 20 messages. */
3950
3951 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3952 * Information Type 19 is present, then its scheduling shall be indicated in System
3953 * Information Type 9. */
3954
3955 if (cfg.si15_present) {
3956 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3957 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3958 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3959 * 4 consecutive occurrences of TC = 1. */
3960 if (not cfg.bcch_extended) {
3961 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3962 } else {
3963 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3964 }
3965 }
3966 if (cfg.si13alt_present) {
3967 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3968 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3969 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3970 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3971 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3972 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3973 * of TC = 4. */
3974 if (cfg.si13_present) {
3975 testcase.stop("Error: Cannot have SI13alt and SI13");
3976 }
3977 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003979 }
3980 if (not cfg.bcch_extended) {
3981 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3982 } else {
3983 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3984 }
3985 }
3986 if (cfg.si2n_present) {
3987 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3988 * as determined by the system operator. In the case that the message is sent on the
3989 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3990 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3991 * consecutive occurrences of TC = 4. */
3992 if (not cfg.bcch_extended) {
3993 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3994 } else {
3995 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3996 }
3997 }
3998 if (cfg.si21_present) {
3999 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4000 * determined by the system operator. If Extended Access Barring is in use in the cell
4001 * then this message is sent at least once within any of 4 consecutive occurrences of
4002 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4003 * cell then this message shall only be sent on BCCH Ext. */
4004 if (not cfg.bcch_extended) {
4005 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4006 } else {
4007 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4008 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004010 }
4011 }
4012 }
4013 if (cfg.si22_present) {
4014 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4015 * should not be sent in a cell where SoLSA is used (see rule viii). System
4016 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4017 * =2 and TC=6. */
4018 if (cfg.si16_present or cfg.si17_present) {
4019 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4020 }
4021 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4022 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004023 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004024 }
4025 if (not cfg.bcch_extended) {
4026 testcase.stop("Error: SI22 requires BCCH Extd!");
4027 } else {
4028 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4029 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4030 }
4031 }
4032}
4033
4034/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004035private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4036return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004037 timer T := duration;
4038 var SystemInformationVectorPerTc si_per_tc;
4039 var L1ctlDlMessage l1_dl;
4040
4041 /* initialize all per-TC vectors empty */
4042 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4043 si_per_tc[i] := {};
4044 }
4045
4046 /* flush all previous L1 queued msgs */
4047 pt.clear;
4048
4049 T.start;
4050 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004051 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004052 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4053 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4054 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004055 repeat;
4056 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004057
Harald Welte48494ca2018-02-25 16:59:50 +01004058 var integer tc := f_gsm_compute_tc(sig.frame_number);
4059 log("SI received at TC=", tc, ": ", sig.si);
4060 /* append to the per-TC bucket */
4061 si_per_tc[tc] := si_per_tc[tc] & { sig };
4062 repeat;
4063 }
4064 [] pt.receive { repeat; }
4065 [] T.timeout { }
4066 }
4067
4068 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4069 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4070 }
4071 log("si_per_tc=", si_per_tc);
4072 return si_per_tc;
4073}
4074
4075/* helper function: Set given SI via RSL + validate scheduling.
4076 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004077private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004078 var SystemInformationVectorPerTc si_per_tc;
4079 f_init_l1ctl();
4080 f_l1_tune(L1CTL);
4081
4082 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004083 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004084 f_validate_si_scheduling(si_cfg, si_per_tc);
4085
4086 setverdict(pass);
4087}
4088
4089testcase TC_si_sched_default() runs on test_CT {
4090 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004091 /* 2+3+4 are mandatory and set in f_init() */
4092 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004094}
4095
4096testcase TC_si_sched_1() runs on test_CT {
4097 f_init();
4098 si_cfg.si1_present := true;
4099 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004100 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004101 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004102}
4103
4104testcase TC_si_sched_2bis() runs on test_CT {
4105 f_init();
4106 si_cfg.si2bis_present := true;
4107 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4108 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004109 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004110}
4111
4112testcase TC_si_sched_2ter() runs on test_CT {
4113 f_init();
4114 si_cfg.si2ter_present := true;
4115 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4116 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_2ter_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 si_cfg.si2ter_present := true;
4125 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4126 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004127 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004128}
4129
4130testcase TC_si_sched_2quater() runs on test_CT {
4131 f_init();
4132 si_cfg.si2quater_present := true;
4133 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004134 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004136}
4137
4138testcase TC_si_sched_13() runs on test_CT {
4139 f_init();
4140 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004141 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004142 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_13_2bis_2ter_2quater() runs on test_CT {
4147 f_init();
4148 si_cfg.si2bis_present := true;
4149 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4150 si_cfg.si2ter_present := true;
4151 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4152 si_cfg.si2quater_present := true;
4153 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4154 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004155 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004156 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004157 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004158}
4159
4160
Harald Welte68e495b2018-02-25 00:05:57 +01004161testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004162 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004163 /* FIXME: enable / disable individual BCCH info */
4164 //ts_RSL_BCCH_INFO(si_type, info);
4165 /* expect no ERROR REPORT after either of them *
4166 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004167 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004168}
4169
Harald Welte93640c62018-02-25 16:59:33 +01004170/***********************************************************************
4171 * Low-Level Protocol Errors / ERROR REPORT
4172 ***********************************************************************/
4173
Harald Welte01d982c2018-02-25 01:31:40 +01004174private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4175 timer T := 5.0;
4176 T.start;
4177 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004178 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004179 setverdict(pass);
4180 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004181 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004183 }
4184 [] RSL_CCHAN.receive {
4185 repeat;
4186 }
4187 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004189 }
4190 }
4191}
4192
4193/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4194testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004195 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004196 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4197 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004198 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004199
4200 f_exp_err_rep(RSL_ERR_PROTO);
4201}
4202
4203/* Provoke a mandatory IE error and match on ERROR REPORT */
4204testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004205 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004206
4207 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4208 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004209 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004210
4211 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4212}
4213
4214/* Provoke an IE content error and match on ERROR REPORT */
4215testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004216 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004217 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4218 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004219 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004220
4221 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4222}
4223
Harald Welteee25aae2019-05-19 14:32:37 +02004224/* attempt to activate channel with wrong RSL Message Discriminator IE */
4225function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4226 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4227 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4228 RSL.send(rsl);
4229 f_rslem_unregister(0, g_chan_nr);
4230}
4231testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4232 var ConnHdlr vc_conn;
4233 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4234
Harald Welte10474062019-05-30 16:48:17 +02004235 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004236
4237 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4238 vc_conn.done;
4239 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4240
4241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4242}
4243
4244/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004245private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004246 var template (value) RSL_Message rsl_tx;
4247 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4248 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4249 RSL.send(rsl_tx);
4250 f_rslem_unregister(0, g_chan_nr);
4251}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004252private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004253 var template (value) RSL_Message rsl_tx;
4254 /* we first have to activate the dedicated channel */
4255 f_rsl_chan_act(g_pars.chan_mode);
4256 /* ... to then send an invalid RLL message */
4257 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4258 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4259 RSL.send(rsl_tx);
4260 f_rslem_unregister(0, g_chan_nr);
4261}
4262testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4263 var ConnHdlr vc_conn;
4264 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4265 var template (value) RSL_Message rsl_tx;
4266
Harald Welte10474062019-05-30 16:48:17 +02004267 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004268
4269 /* Common Channel with wrong message type */
4270 RSL_CCHAN.clear;
4271 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4272 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004273 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004274 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4275
4276 /* TRX Management */
4277 RSL_CCHAN.clear;
4278 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4279 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004280 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004281 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4282
4283 /* Dedicated Channel */
4284 RSL_CCHAN.clear;
4285 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4286 vc_conn.done;
4287 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4288
4289 /* RLL */
4290 RSL_CCHAN.clear;
4291 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4292 vc_conn.done;
4293 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4294}
4295
4296/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004297private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004298 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4299 f_rslem_unregister(0, g_chan_nr);
4300}
4301testcase TC_err_rep_wrong_sequence() runs on test_CT {
4302 var ConnHdlr vc_conn;
4303 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4304
Harald Welte10474062019-05-30 16:48:17 +02004305 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004306
4307 RSL_CCHAN.clear;
4308 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4309 vc_conn.done;
4310 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4311}
4312
Harald Welte93640c62018-02-25 16:59:33 +01004313/***********************************************************************
4314 * IPA CRCX/MDCX/DLCS media stream handling
4315 ***********************************************************************/
4316
Harald Weltea871a382018-02-25 02:03:14 +01004317/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004318private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004319 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4320 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004321}
4322testcase TC_ipa_dlcx_not_active() runs on test_CT {
4323 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004324 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004325 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4326 vc_conn.done;
4327}
Harald Welte68e495b2018-02-25 00:05:57 +01004328
Harald Weltea3f1df92018-02-25 12:49:55 +01004329/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004330private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004331 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4332 "IPA CRCX ACK");
4333 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4334 "IPA CRCX NACK");
4335}
4336testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4337 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004338 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004339 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4340 vc_conn.done;
4341}
4342
4343/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004344private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004345 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4346 "IPA CRCX ACK");
4347 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4348 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4349 var uint7_t rtp_pt2 := f_rnd_int(127);
4350 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4351 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4352 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4353 "IPA MDCX ACK");
4354 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4355 "IPA DLCX ACK");
4356}
4357testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4358 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004359 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004360 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4361 vc_conn.done;
4362}
4363
Harald Welte3ae11da2018-02-25 13:36:06 +01004364/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004365private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004366 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4367 "IPA CRCX ACK");
4368 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4369 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4370 var uint7_t rtp_pt2 := f_rnd_int(127);
4371 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4372 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4373 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4374 "IPA MDCX ACK");
4375 /* Second MDCX */
4376 remote_ip := f_rnd_int(c_UINT32_MAX);
4377 remote_port := f_rnd_int(c_UINT16_MAX);
4378 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4379 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4380 "IPA MDCX ACK");
4381 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4382 "IPA DLCX ACK");
4383}
4384testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4385 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004386 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004387 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4388 vc_conn.done;
4389}
4390
Harald Welte9912eb52018-02-25 13:30:15 +01004391/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004392private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004393 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4394 "IPA CRCX NACK");
4395}
4396testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4397 var ConnHdlrPars pars;
4398 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004399 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004400
4401 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4402 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4403 vc_conn.done;
4404
4405 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4406 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4407 vc_conn.done;
4408}
4409
Harald Weltea3f1df92018-02-25 12:49:55 +01004410
Harald Welte883340c2018-02-28 18:59:29 +01004411/***********************************************************************
4412 * PCU Socket related tests
4413 ***********************************************************************/
4414
Harald Welte07bd2d22019-05-25 11:03:30 +02004415/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004416friend 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 +01004417runs on test_CT {
4418 timer T := 3.0;
4419
4420 /* we don't expect any RTS.req before PDCH are active */
4421 T.start;
4422 alt {
4423 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004425 }
4426 [] PCU.receive { repeat; }
4427 [] T.timeout { }
4428 }
4429
4430 /* Send PDCH activate request for known PDCH timeslot */
4431 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4432
4433 /* we now expect RTS.req for this timeslot (only) */
4434 T.start;
4435 alt {
4436 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4437 setverdict(pass);
4438 }
4439 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4440 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004441 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004442 }
4443 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004444 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004445 }
4446 [] PCU.receive { repeat; }
4447 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004449 }
4450 [not exp_success] T.timeout {
4451 setverdict(pass);
4452 }
4453 }
4454}
4455
Harald Welte07bd2d22019-05-25 11:03:30 +02004456/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004457friend 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 +01004458runs on test_CT {
4459 timer T := 3.0;
4460
4461 /* Send PDCH activate request for known PDCH timeslot */
4462 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 +02004463 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4464 * when it will actually have been executed in the BTS */
4465 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004466 PCU.clear;
4467 /* we now expect no RTS.req for this timeslot */
4468 T.start;
4469 alt {
4470 [] 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 +02004471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004472 }
4473 [] PCU.receive { repeat; }
4474 [] T.timeout {
4475 setverdict(pass);
4476 }
4477 }
4478}
4479
Harald Weltead033dc2019-05-25 17:28:16 +02004480friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004481 f_init();
4482 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4483}
4484
Harald Welte883340c2018-02-28 18:59:29 +01004485/* PDCH activation via PCU socket; check for presence of RTS.req */
4486testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004487 f_init_pcu_test();
4488
Harald Welte883340c2018-02-28 18:59:29 +01004489 f_TC_pcu_act_req(0, 0, 7, true);
4490}
4491
4492/* PDCH activation via PCU socket on non-PDCU timeslot */
4493testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004494 f_init_pcu_test();
4495
Harald Welte883340c2018-02-28 18:59:29 +01004496 f_TC_pcu_act_req(0, 0, 1, false);
4497}
4498
4499/* PDCH activation via PCU socket on wrong BTS */
4500testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004501 f_init_pcu_test();
4502
Harald Welte883340c2018-02-28 18:59:29 +01004503 f_TC_pcu_act_req(23, 0, 7, false);
4504}
4505
4506/* PDCH activation via PCU socket on wrong TRX */
4507testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004508 f_init_pcu_test();
4509
Harald Welte883340c2018-02-28 18:59:29 +01004510 f_TC_pcu_act_req(0, 23, 7, false);
4511}
4512
4513/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4514testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004515 f_init_pcu_test();
4516
Harald Welte883340c2018-02-28 18:59:29 +01004517 /* Activate PDCH */
4518 f_TC_pcu_act_req(0, 0, 7, true);
4519 f_sleep(1.0);
4520 /* and De-Activate again */
4521 f_TC_pcu_deact_req(0, 0, 7);
4522}
4523
4524/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4525testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004526 f_init_pcu_test();
4527
Harald Welte883340c2018-02-28 18:59:29 +01004528 f_TC_pcu_deact_req(0, 0, 1);
4529}
4530
4531/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4532testcase TC_pcu_ver_si13() runs on test_CT {
4533 const octetstring si13 := '00010203040506070909'O;
4534 var PCUIF_send_data sd;
4535 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004536 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004537
4538 /* Set SI13 via RSL */
4539 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004540
Harald Welte883340c2018-02-28 18:59:29 +01004541 T.start;
4542 alt {
4543 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4544 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4545 setverdict(pass);
4546 } else {
4547 repeat;
4548 }
4549 }
4550 [] PCU.receive { repeat; }
4551 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004552 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004553 }
4554 }
4555}
4556
4557private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4558
4559/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004560friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004561 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4562runs on test_CT
4563{
4564 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4565 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4566}
4567
4568/* 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 +02004569friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4570 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004571runs on test_CT
4572{
4573 var PCUIF_send_data sd;
4574
4575 timer T := 3.0;
4576 T.start;
4577 alt {
4578 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4579 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4580 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4581 sd.data.u.rts_req.fn, sapi, data);
4582 }
4583 [] PCU.receive { repeat; }
4584 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004585 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004586 }
4587 }
4588}
4589
4590/* Send DATA.req on invalid BTS */
4591testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004592 var TfiUsfArr tua := f_TfiUsfArrInit();
4593 var octetstring data := '0000'O & f_rnd_octstring(21);
4594
4595 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004596
Harald Welte883340c2018-02-28 18:59:29 +01004597 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004598 f_TfiUsfArrSet(tua, 7, 0);
4599 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4600 f_sleep(1.0);
4601
4602 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004603}
4604
4605/* Send DATA.req on invalid TRX */
4606testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004607 var TfiUsfArr tua := f_TfiUsfArrInit();
4608 var octetstring data := '0000'O & f_rnd_octstring(21);
4609
4610 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004611
Harald Welte883340c2018-02-28 18:59:29 +01004612 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004613 f_TfiUsfArrSet(tua, 7, 0);
4614 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4615 f_sleep(1.0);
4616
4617 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004618}
4619
4620/* Send DATA.req on invalid timeslot */
4621testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004622 var TfiUsfArr tua := f_TfiUsfArrInit();
4623 var octetstring data := '0000'O & f_rnd_octstring(21);
4624
4625 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004626
Harald Welte883340c2018-02-28 18:59:29 +01004627 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004628 f_TfiUsfArrSet(tua, 7, 0);
4629 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4630 f_sleep(1.0);
4631
4632 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004633}
4634
4635/* Send DATA.req on timeslot that hasn't been activated */
4636testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004637 var TfiUsfArr tua := f_TfiUsfArrInit();
4638 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004639
Harald Welte7162a612019-05-26 12:56:09 +02004640 f_virtphy_common();
4641
4642 f_TfiUsfArrSet(tua, 7, 0);
4643 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4644 f_sleep(1.0);
4645
4646 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004647}
4648
Harald Weltead033dc2019-05-25 17:28:16 +02004649private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004650 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4651 boolean wait_rts := true)
4652runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004653 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004654 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004655
4656 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004657 if (wait_rts) {
4658 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4659 } else {
4660 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4661 }
Harald Weltead033dc2019-05-25 17:28:16 +02004662
4663 T.start;
4664 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004665 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004666 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4667 setverdict(pass);
4668 }
Harald Welte7162a612019-05-26 12:56:09 +02004669 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4670 setverdict(fail, "Received unexpected ", rx_dl);
4671 }
Harald Weltead033dc2019-05-25 17:28:16 +02004672 [] L1CTL.receive {
4673 repeat;
4674 }
Harald Welte7162a612019-05-26 12:56:09 +02004675 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004676 setverdict(fail, "Timeout waiting for ", data);
4677 }
Harald Welte7162a612019-05-26 12:56:09 +02004678 [not expect_data] T.timeout {
4679 setverdict(pass);
4680 }
Harald Weltead033dc2019-05-25 17:28:16 +02004681 }
4682}
4683
4684private function f_disable_dynamic_ts() runs on test_CT
4685{
4686 f_init_vty_bsc();
4687 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4688 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4689 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4690 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004691 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004692}
4693
4694private function f_virtphy_common() runs on test_CT {
4695 f_disable_dynamic_ts();
4696 f_init_l1ctl();
4697 f_l1_tune(L1CTL);
4698}
4699
4700testcase TC_pcu_data_req_pdtch() runs on test_CT {
4701 var TfiUsfArr tua := f_TfiUsfArrInit();
4702 var octetstring data := '0000'O & f_rnd_octstring(21);
4703
4704 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004705
Harald Welte883340c2018-02-28 18:59:29 +01004706 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004707 f_TfiUsfArrSet(tua, 7, 0);
4708 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4709 f_sleep(1.0);
4710
4711 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004712}
4713
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004714/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004715testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004716 var TfiUsfArr tua := f_TfiUsfArrInit();
4717 var octetstring data := '0000'O & f_rnd_octstring(21);
4718
4719 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004720
Harald Welte883340c2018-02-28 18:59:29 +01004721 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004722 f_TfiUsfArrSet(tua, 7, 0);
4723 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4724 f_sleep(1.0);
4725
4726 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004727}
4728
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004729private function f_TC_pcu_ptcch_ul(uint16_t ra)
4730runs on test_CT {
4731 var template PCUIF_Message pcu_rach_ind;
4732 var PCUIF_send_data sd;
4733 var GsmFrameNumber fn;
4734 timer T;
4735
4736 /* Send an Access Burst on PTCCH/U over the Um-interface */
4737 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4738 chan_nr := ts_RslChanNr_PDCH(7),
4739 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4740
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004741 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4742 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004743
4744 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4745 T.start(52.0 * 4.615 / 1000.0);
4746 alt {
4747 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4748 log("Rx an Access Burst on the PCU interface: ", sd.data);
4749 setverdict(pass);
4750 T.stop;
4751 }
4752 [] PCU.receive { repeat; }
4753 [] T.timeout {
4754 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4755 /* Keep going, that's not the end of the world */
4756 }
4757 }
4758}
4759
4760testcase TC_pcu_ptcch() runs on test_CT {
4761 var L1ctlDlMessage dl;
4762 var octetstring data;
4763 timer T;
4764
4765 f_init_pcu_test();
4766 f_init_l1ctl();
4767 f_l1_tune(L1CTL);
4768
4769 /* Activate PDCH channel on TS7 */
4770 f_TC_pcu_act_req(0, 0, 7, true);
4771
4772 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004773 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004774 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004775 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004776 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004777
4778 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4779 for (var integer i := 0; i < 16; i := i + 1) {
4780 log("Sending an Access Burst towards the L1CTL interface");
4781 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4782 }
4783
4784 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4785 data := f_rnd_octstring(23);
4786
4787 /* Verify PTCCH/D: send a random data block, make sure it's received */
4788 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4789 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4790
4791 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4792 * let's give it more time in case if we miss the beginning. */
4793 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4794 alt {
4795 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4796 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4797 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4798 frame := data)) -> value dl {
4799 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4800 setverdict(pass);
4801 T.stop;
4802 }
4803 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4804 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4805 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4806 l2_data := data)) -> value dl {
4807 log("Rx PTCCH/D data block on L1CTL: ", dl);
4808 setverdict(pass);
4809 T.stop;
4810 }
4811 [] L1CTL.receive { repeat; }
4812 [] T.timeout {
4813 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4814 }
4815 }
4816}
4817
Harald Welte883340c2018-02-28 18:59:29 +01004818/* Send AGCH from PCU; check it appears on Um side */
4819testcase TC_pcu_data_req_agch() runs on test_CT {
4820 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004821 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004822 f_init_l1ctl();
4823 f_l1_tune(L1CTL);
4824
4825 f_TC_pcu_act_req(0, 0, 7, true);
4826 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4827
4828 T.start;
4829 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004830 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004831 setverdict(pass);
4832 }
4833 [] L1CTL.receive { repeat; }
4834 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004836 }
4837 }
4838}
4839
Harald Welte928622b2019-05-26 13:22:59 +02004840/* Send AGCH from PCU; check it appears on Um side */
4841testcase TC_pcu_data_req_pch() runs on test_CT {
4842 timer T := 3.0;
4843 f_init_pcu_test();
4844 f_init_l1ctl();
4845 f_l1_tune(L1CTL);
4846
4847 f_TC_pcu_act_req(0, 0, 7, true);
4848 /* three characters prefix: last 3 digits of IMSI as ASCII */
4849 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4850
4851 T.start;
4852 alt {
4853 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4854 setverdict(pass);
4855 }
4856 [] L1CTL.receive { repeat; }
4857 [] T.timeout {
4858 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4859 }
4860 }
4861}
4862
Harald Welte883340c2018-02-28 18:59:29 +01004863/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4864testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4865 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004866 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004867 f_init_l1ctl();
4868 f_l1_tune(L1CTL);
4869
4870 /* append 3 last imsi digits so BTS can compute pagng group */
4871 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4872
4873 timer T := 0.5;
4874 T.start;
4875 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004876 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004877 /* TODO: verify paging group */
4878 setverdict(pass);
4879 }
4880 [] L1CTL.receive { repeat; }
4881 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004883 }
4884 }
4885}
4886
4887/* Send RACH from Um side, expect it to show up on PCU socket */
4888testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004889 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004890 f_init_l1ctl();
4891 f_l1_tune(L1CTL);
4892
4893 var GsmFrameNumber fn_last := 0;
4894 for (var integer i := 0; i < 1000; i := i+1) {
4895 var OCT1 ra := f_rnd_ra_ps();
4896 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4897 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004899 }
4900 fn_last := fn;
4901
4902 timer T := 2.0;
4903 T.start;
4904 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004905 [] 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 +01004906 T.stop;
4907 }
4908 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004910 }
4911 [] PCU.receive { repeat; }
4912 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004914 }
4915 }
4916 }
4917 setverdict(pass);
4918}
4919
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004920/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4921 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4922testcase TC_pcu_ext_rach_content() runs on test_CT {
4923 var template PCUIF_Message pcu_rach_ind;
4924 var GsmFrameNumber fn_last := 0;
4925 var L1ctlRachSynchSeq synch_seq;
4926 var PCUIF_BurstType pcu_bt;
4927 var GsmFrameNumber fn;
4928 var BIT11 ra11;
4929
4930 f_init_pcu_test();
4931 f_init_l1ctl();
4932 f_l1_tune(L1CTL);
4933
4934 for (var integer i := 0; i < 1000; i := i+1) {
4935 /* We need to test both TS1 & TS2 */
4936 if (i rem 2 == 0) {
4937 synch_seq := RACH_SYNCH_SEQ_TS1;
4938 pcu_bt := BURST_TYPE_1;
4939 } else {
4940 synch_seq := RACH_SYNCH_SEQ_TS2;
4941 pcu_bt := BURST_TYPE_2;
4942 }
4943
4944 ra11 := f_rnd_ra11_ps();
4945 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4946 if (fn == fn_last) {
4947 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4948 "Two RACH in same FN?!?");
4949 }
4950 fn_last := fn;
4951
4952 /* Compose the expected message */
4953 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004954 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004955 ra := bit2int(ra11),
4956 is_11bit := 1,
4957 burst_type := pcu_bt,
4958 fn := fn);
4959
4960 timer T := 2.0;
4961 T.start;
4962 alt {
4963 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4964 T.stop;
4965 }
4966 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4967 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4968 }
4969 [] PCU.receive { repeat; }
4970 [] T.timeout {
4971 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4972 }
4973 }
4974 }
4975 setverdict(pass);
4976}
4977
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004978private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4979runs on test_CT {
4980 var template PCUIF_send_data sdt;
4981 var PCUIF_send_data sd;
4982 var int16_t lqual_cb;
4983 timer T := 1.0;
4984
4985 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4986 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4987
4988 /* Send a random PDTCH frame over Um */
4989 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4990 '0000'O & f_rnd_octstring(21)));
4991
4992 T.start;
4993 alt {
4994 /* If expected link quality is above the threshold */
4995 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4996 lqual_cb := sd.data.u.data_ind.lqual_cb;
4997 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4998
4999 /* Make sure the actual link quality matches the expected value */
5000 if (not match(lqual_cb, lqual_cb_exp)) {
5001 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5002 "expected value ", lqual_cb_exp));
5003 } else {
5004 setverdict(pass);
5005 }
5006 }
5007 /* If expected link quality is below the threshold */
5008 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5010 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5011 }
5012 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5013 [] PCU.receive { repeat; }
5014 [lqual_cb_exp < thresh] T.timeout {
5015 log("Rx nothing, as expected");
5016 setverdict(pass);
5017 }
5018 [lqual_cb_exp >= thresh] T.timeout {
5019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5020 "Timeout waiting for PCUIF_DATA.ind");
5021 }
5022 }
5023}
5024
5025/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5026testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
5027 f_init_pcu_test();
5028 PCU.clear;
5029
5030 f_init_l1ctl();
5031 f_l1_tune(L1CTL);
5032
5033 /* Activate a PDCH channel on TS7 */
5034 f_TC_pcu_act_req(0, 0, 7, true);
5035
5036 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005037 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005038 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005039 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005040 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005041
5042 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5043 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5044 var TrxcMessage ret;
5045
5046 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5047 valueof(ts_TRXC_FAKE_CI(i)));
5048
5049 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5050 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5051 }
5052}
5053
Harald Welte883340c2018-02-28 18:59:29 +01005054/* Send PAGING via RSL, expect it to shw up on PCU socket */
5055testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005056 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01005057
5058 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005059 var MobileIdentityLV mi_lv;
5060 var octetstring mi_lv_enc;
5061 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005062 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005063
Harald Welte883340c2018-02-28 18:59:29 +01005064 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005065 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005066 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005067 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005068 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005069
5070 /* Fancy encoding for PCUIF */
5071 mi_lv := valueof(ts_MI_LV(mi));
5072 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5073 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005074
5075 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005076 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005077 T.start;
5078 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005079 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005080 }
5081 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005082 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005083 }
5084 [] PCU.receive { repeat; }
5085 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005086 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005087 }
5088 }
5089 }
5090 setverdict(pass);
5091}
5092
Harald Welted66c9b82019-05-25 09:03:15 +02005093/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5094testcase TC_pcu_time_ind() runs on test_CT {
5095 var PCUIF_send_data pcu_sd;
5096 var integer num_time_ind := 0;
5097 var integer first_fn, last_fn;
5098 var float test_duration := 5.0;
5099 timer T;
5100
5101 f_init_pcu_test();
5102 f_TC_pcu_act_req(0, 0, 7, true);
5103
5104 PCU.clear;
5105 T.start(test_duration);
5106 alt {
5107 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5108 num_time_ind := num_time_ind + 1;
5109 if (not isbound(first_fn)) {
5110 first_fn := pcu_sd.data.u.time_ind.fn;
5111 }
5112 last_fn := pcu_sd.data.u.time_ind.fn;
5113 repeat;
5114 }
5115 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5116 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5117 repeat;
5118 }
5119 [] PCU.receive {
5120 repeat;
5121 }
5122 [] T.timeout {}
5123 }
5124 var integer fn_expired := last_fn - first_fn;
5125 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5126
5127 /* verify the number of frames expired matches our expectation */
5128 const float c_GSM_FN_DURATION_MS := 4.61538;
5129 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005130 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005131 if (not match(fn_expired, t_fn_expected)) {
5132 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5133 }
5134
5135 /* There are three TIME.ind in every fn MOD 13 */
5136 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5137 /* Add some tolerance */
5138 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5139 if (not match(num_time_ind, t_time_ind_exp)) {
5140 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5141 }
5142
5143 setverdict(pass);
5144}
5145
Harald Welte4832c862019-05-25 14:57:18 +02005146/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5147testcase TC_pcu_rts_req() runs on test_CT {
5148 var PCUIF_send_data pcu_sd;
5149 var integer first_fn, last_fn;
5150 var integer num_rts_pdtch := 0;
5151 var integer num_rts_ptcch := 0;
5152 var float test_duration := 5.0;
5153 timer T;
5154
5155 f_init_pcu_test();
5156 f_TC_pcu_act_req(0, 0, 7, true);
5157
5158 PCU.clear;
5159 T.start(test_duration);
5160 alt {
5161 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5162 -> value pcu_sd {
5163 num_rts_pdtch := num_rts_pdtch + 1;
5164 if (not isbound(first_fn)) {
5165 first_fn := pcu_sd.data.u.rts_req.fn;
5166 }
5167 last_fn := pcu_sd.data.u.rts_req.fn;
5168 repeat;
5169 }
5170 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5171 -> value pcu_sd {
5172 num_rts_ptcch := num_rts_ptcch + 1;
5173 if (not isbound(first_fn)) {
5174 first_fn := pcu_sd.data.u.rts_req.fn;
5175 }
5176 last_fn := pcu_sd.data.u.rts_req.fn;
5177 repeat;
5178 }
5179 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5180 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5181 repeat;
5182 }
5183 [] PCU.receive {
5184 repeat;
5185 }
5186 [] T.timeout {}
5187 }
5188 var integer fn_expired := last_fn - first_fn;
5189 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5190 ", num_rts_ptcch=", num_rts_ptcch);
5191
5192 /* verify the number of frames expired matches our expectation */
5193 const float c_GSM_FN_DURATION_MS := 4.61538;
5194 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005195 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005196 if (not match(fn_expired, t_fn_expected)) {
5197 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5198 }
5199
5200 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5201 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5202 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5203 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5204 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5205 t_ptcch_exp);
5206 }
5207
5208 /* We have 12 PDTCH blocks every 52-multiframe */
5209 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5210 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5211 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5212 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5213 t_pdtch_exp);
5214 }
5215
5216 setverdict(pass);
5217}
5218
Harald Welte07bd2d22019-05-25 11:03:30 +02005219/* test for generating Abis side OML ALERT from the PCU */
5220testcase TC_pcu_oml_alert() runs on test_CT {
5221 var PCUIF_send_data pcu_sd;
5222 var integer num_time_ind := 0;
5223 var integer first_fn, last_fn;
5224 var float test_duration := 5.0;
5225 timer T;
5226
5227 f_init_pcu_test();
5228 f_TC_pcu_act_req(0, 0, 7, true);
5229
5230 /* re-connect CTRL port from BTS to BSC */
5231 f_ipa_ctrl_stop();
5232 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5233
5234 /* Send that OML Alert */
5235 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5236
5237 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5238 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5239 setverdict(pass);
5240}
5241
Harald Welteeaa9a862019-05-26 23:01:08 +02005242/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5243private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5244 var PCUIF_Message first_info;
5245 var integer pcu_conn_id := -1;
5246 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5247 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5248 var OCT4 tlli := '01020304'O;
5249 var OCT1 cause := '23'O;
5250 timer T := 5.0;
5251
5252 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5253
5254 f_l1_tune(L1CTL);
5255 RSL.clear;
5256
5257 f_est_dchan();
5258 L1CTL.clear;
5259
5260 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5261
5262 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5263 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5264 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5265
5266 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5267 T.start;
5268 alt {
5269 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5270 setverdict(pass);
5271 }
5272 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5273 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5274 }
5275 [] PCU.receive {
5276 repeat;
5277 }
5278 [] T.timeout {
5279 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5280 }
5281 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005282
5283 /* release the channel */
5284 f_rsl_chan_deact();
5285 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5286 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005287}
5288testcase TC_pcu_rr_suspend() runs on test_CT {
5289 var ConnHdlrPars pars;
5290 var ConnHdlr vc_conn;
5291
5292 f_init();
5293
5294 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5295 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5296 vc_conn.done;
5297}
Harald Welte07bd2d22019-05-25 11:03:30 +02005298
Harald Weltea2e0e942019-05-27 18:12:53 +02005299/* Ensure that PCUIF socket can accept only a single connection */
5300testcase TC_pcu_socket_connect_multi() runs on test_CT {
5301 timer T := 5.0;
5302
5303 /* this (among other things) establishes the first connection to the PCUIF socket */
5304 f_init();
5305
5306 /* try to establish a second connection, expect it to fail */
5307 PCU.send(UD_connect:{mp_pcu_socket, -1});
5308 T.start;
5309 alt {
5310 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5311 setverdict(pass);
5312 }
5313 [] PCU.receive(UD_connect_result:?) {
5314 setverdict(fail, "Unexpected unix domain connect result");
5315 }
5316 [] T.timeout {
5317 setverdict(pass);
5318 }
5319 }
5320 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5321}
5322
Harald Weltec8effb72019-05-27 18:23:04 +02005323/* Ensure that PCUIF socket can disconnect + reconnect */
5324testcase TC_pcu_socket_reconnect() runs on test_CT {
5325 /* this (among other things) establishes the first connection to the PCUIF socket */
5326 f_init();
5327
5328 f_sleep(1.0);
5329
5330 f_pcuif_close(PCU, g_pcu_conn_id);
5331 g_pcu_conn_id := -1;
5332
5333 f_sleep(1.0);
5334
5335 /* re-connect */
5336 PCU.clear;
5337 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5338 setverdict(pass);
5339
5340 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5341}
5342
Harald Weltebe030482019-05-27 22:29:35 +02005343/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005344private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5345runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005346 var L1ctlDlMessage l1_dl;
5347 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005348 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005349 timer T := 5.0;
5350 T.start;
5351 alt {
5352 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005353 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5354 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005355 repeat;
5356 }
5357 }
5358 [] pt.receive {
5359 repeat;
5360 }
5361 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005362 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5363 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005364 }
5365 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005366 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005367}
5368
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005369/* Check if GPRS Indicator is present in RR System Information of a given type */
5370private function f_si_has_gprs_indicator(RrMessageType si_type)
5371runs on test_CT return boolean {
5372 var SystemInformation si := f_get_si(L1CTL, si_type);
5373
5374 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005375 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005376 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005377 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005378 }
5379
5380 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5381 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005382}
5383
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005384/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5385private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5386runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005387 /* don't call f_init() as this would connect PCU socket */
5388 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005389
5390 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005391 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005392 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005393
5394 f_init_l1ctl();
5395 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005396 f_sleep(2.0);
5397 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005398
5399 if (f_si_has_gprs_indicator(si_type)) {
5400 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005401 } else {
5402 setverdict(pass);
5403 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005404
Harald Weltebe030482019-05-27 22:29:35 +02005405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5406}
5407
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005408testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5409 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5410}
Harald Weltebe030482019-05-27 22:29:35 +02005411
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005412testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5413 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5414}
5415
5416/* Ensure that GPRS capability is advertised after PCU socket connect */
5417private function f_TC_pcu_socket_connect(RrMessageType si_type)
5418runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005419 /* this (among other things) establishes the first connection to the PCUIF socket */
5420 f_init();
5421 f_init_l1ctl();
5422 f_l1_tune(L1CTL);
5423
5424 f_sleep(2.0);
5425 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005426
5427 if (not f_si_has_gprs_indicator(si_type)) {
5428 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005429 } else {
5430 setverdict(pass);
5431 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005432
Harald Weltebe030482019-05-27 22:29:35 +02005433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5434}
5435
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005436testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5437 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5438}
Harald Weltebe030482019-05-27 22:29:35 +02005439
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005440testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5441 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5442}
5443
5444/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5445private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5446runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005447 /* this (among other things) establishes the first connection to the PCUIF socket */
5448 f_init();
5449 f_init_l1ctl();
5450 f_l1_tune(L1CTL);
5451
5452 f_pcuif_close(PCU, g_pcu_conn_id);
5453 g_pcu_conn_id := -1;
5454
5455 f_sleep(1.0);
5456
5457 /* re-connect */
5458 PCU.clear;
5459 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5460
5461 f_sleep(2.0);
5462 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005463
5464 if (f_si_has_gprs_indicator(si_type)) {
5465 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005466 } else {
5467 setverdict(pass);
5468 }
5469
5470 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5471}
5472
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005473testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5474 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5475}
5476
5477testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5478 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5479}
5480
Oliver Smithf5239c72019-08-28 10:01:25 +02005481/* 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) */
5482testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5483 var SystemInformation si3 := valueof(ts_SI3_default);
5484
5485 f_init();
5486
Harald Welte76220222020-10-11 20:32:44 +02005487 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5488 * information */
5489 timer T := 2.0;
5490 T.start;
5491 alt {
5492 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5493 [] T.timeout {}
5494 }
5495
Oliver Smithf5239c72019-08-28 10:01:25 +02005496 /* Verify cell_id */
5497 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5498 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5499 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005500 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5501 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5502 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005503 }
5504
5505 /* Verify LAC */
5506 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5507 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5508 if (lac_si3 != lac_pcu) {
5509 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5510 }
5511
5512 setverdict(pass);
5513}
Harald Welted66c9b82019-05-25 09:03:15 +02005514
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005515/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5516testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5517 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005518 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005519
5520 f_init();
5521
5522 info_ind := g_pcu_last_info.u.info_ind;
5523
5524 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5525 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5526 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5527 /* Skip inactive timeslots */
5528 continue;
5529 }
5530
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005531 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005532 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005533 else
5534 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005535
5536 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005537 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005538 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005539 hsn := fhp.maio_hsn.hsn,
5540 maio := fhp.maio_hsn.maio,
5541 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005542 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005543 } else {
5544 tr_ts := tr_PCUIF_InfoTrxTsH0;
5545 }
5546
5547 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5548 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5549 if (not match(ts, tr_ts)) {
5550 setverdict(fail, "Hopping parameters do not match: ",
5551 "received ", ts, " vs expected ", tr_ts);
5552 } else {
5553 setverdict(pass);
5554 }
5555 }
5556 }
5557}
5558
Alexander Couzens5283f552020-07-28 15:39:04 +02005559/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5560testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5561 f_init_vty_bsc();
5562 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5563 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5564
5565 f_init();
5566
5567 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5568 if (not ischosen(remote_addr.v10)) {
5569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5570 log2str("Unexpected remote_addr: ", remote_addr));
5571 }
5572
5573 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5574 setverdict(fail, "Received address family is not IPv4");
5575 }
5576
5577 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5578 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5579 }
5580
5581 setverdict(pass);
5582}
5583
5584/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5585testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5586 f_init_vty_bsc();
5587 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5588
5589 f_init();
5590
5591 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5592 if (not ischosen(remote_addr.v10)) {
5593 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5594 log2str("Unexpected remote_addr: ", remote_addr));
5595 }
5596
5597 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5598 setverdict(fail, "Received address family is not IPv6");
5599 }
5600
5601 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5602 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5603 }
5604
5605 setverdict(pass);
5606}
5607
Harald Welte3d04ae62018-04-04 20:29:05 +02005608/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005609 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005610 ***********************************************************************/
5611
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005612private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5613 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005614runs on ConnHdlr {
5615 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005616
5617 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005618 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005619 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5620 repeat;
5621 }
5622 }
5623}
5624
5625private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5626runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005627 /* Expect BTS to immediately acknowledge activation as PDCH */
5628 PCU.clear;
5629 f_rsl_chan_act(g_pars.chan_mode);
5630 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005631 timer T_wait := 2.0;
5632 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005633 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005634 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005635 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005636 [] T_wait.timeout {
5637 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5638 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5639 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005640 }
5641 /* try to activate this PDCH from the PCU point of view */
5642 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5643 /* FIXME: is there a response? */
5644}
5645
5646private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5647runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005648 /* Send RSL CHAN REL (deactivate) */
5649 PCU.clear;
5650 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5651 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005652 timer T_wait := 2.0;
5653 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005654 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005655 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005656 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005657 [] T_wait.timeout {
5658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5659 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5660 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005661 }
5662 /* Emulate PCU asking BTS to deactivate PDCH */
5663 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5664 alt {
5665 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5666 setverdict(pass);
5667 }
5668 [] RSL.receive { repeat; }
5669 }
5670}
5671
5672/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005673private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005674 var PCUIF_Message first_info;
5675 var integer ts_nr := g_chan_nr.tn;
5676 var integer trx_nr := 0;
5677 var integer bts_nr := 0;
5678 var integer pcu_conn_id := -1;
5679
5680 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5681
5682 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5683 f_sleep(3.0);
5684 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5685 setverdict(pass);
5686}
5687testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5688 var ConnHdlrPars pars;
5689 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005690 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005691
5692 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5693 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5694 vc_conn.done;
5695}
5696
5697/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005698private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005699 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005700 var integer pcu_conn_id := -1;
5701
5702 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5703
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005704 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5705 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5706 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005707 setverdict(pass);
5708}
5709testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5710 var ConnHdlrPars pars;
5711 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005712 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005713
5714 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5715 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5716 vc_conn.done;
5717}
5718
5719/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005720private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005721 var PCUIF_Message first_info;
5722 var integer ts_nr := g_chan_nr.tn;
5723 var integer trx_nr := 0;
5724 var integer bts_nr := 0;
5725 var integer pcu_conn_id := -1;
5726
5727 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5728
5729 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005730 /* Send a second Chan Activ and expect it to be NACKed */
5731 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5732 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005733 setverdict(pass);
5734}
5735testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5736 var ConnHdlrPars pars;
5737 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005738 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005739
5740 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5741 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5742 vc_conn.done;
5743}
5744
5745/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005746private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005747 var PCUIF_Message first_info;
5748 var integer ts_nr := g_chan_nr.tn;
5749 var integer trx_nr := 0;
5750 var integer bts_nr := 0;
5751 var integer pcu_conn_id := -1;
5752 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5753
5754 /* register for the TCH/F channel number */
5755 f_rslem_register(0, chan_nr);
5756
5757 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5758
5759 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5760 "RSL CHAN ACT");
5761 setverdict(pass);
5762}
5763testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5764 var ConnHdlrPars pars;
5765 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005766 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005767
5768 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5769 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5770 vc_conn.done;
5771}
5772
5773/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005774private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005775 var PCUIF_Message first_info;
5776 var integer ts_nr := g_chan_nr.tn;
5777 var integer trx_nr := 0;
5778 var integer bts_nr := 0;
5779 var integer pcu_conn_id := -1;
5780 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5781 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5782
5783 /* register for the TCH/H channel numbers */
5784 f_rslem_register(0, chan_nr[0]);
5785 f_rslem_register(0, chan_nr[1]);
5786
5787 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5788
5789 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5790 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5791 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5792 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5793 setverdict(pass);
5794}
5795testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5796 var ConnHdlrPars pars;
5797 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005798 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005799
5800 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5801 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5802 vc_conn.done;
5803}
5804
Harald Welte9bbbfb52018-04-05 09:33:19 +02005805/***********************************************************************
5806 * IPA Style Dynamic Timeslot Support
5807 ***********************************************************************/
5808
5809private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5810runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005811 /* Expect BTS to immediately acknowledge activation as PDCH */
5812 PCU.clear;
5813 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5814 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005815 timer T_wait := 2.0;
5816 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005817 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005818 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005819 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005820 [] T_wait.timeout {
5821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5822 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5823 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005824 }
5825 /* try to activate this PDCH from the PCU point of view */
5826 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5827 /* FIXME: is there a response? */
5828
5829 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5830}
5831
5832private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5833runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005834 /* Send RSL CHAN REL (deactivate) */
5835 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5836 PCU.clear;
5837 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005838 timer T_wait := 2.0;
5839 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005840 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005841 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005842 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005843 [] T_wait.timeout {
5844 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5845 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5846 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005847 }
5848 /* Emulate PCU asking BTS to deactivate PDCH */
5849 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5850 alt {
5851 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5852 setverdict(pass);
5853 }
5854 [] RSL.receive { repeat; }
5855 }
5856}
5857
5858/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005859private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005860 var PCUIF_Message first_info;
5861 var integer ts_nr := g_chan_nr.tn;
5862 var integer trx_nr := 0;
5863 var integer bts_nr := 0;
5864 var integer pcu_conn_id := -1;
5865
5866 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5867
5868 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5869 f_sleep(3.0);
5870 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5871
5872 setverdict(pass);
5873
5874}
5875testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5876 var ConnHdlrPars pars;
5877 var ConnHdlr vc_conn;
5878 f_init();
5879
5880 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5881 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5882 vc_conn.done;
5883}
5884
5885/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005886private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005887 var PCUIF_Message first_info;
5888 var integer ts_nr := g_chan_nr.tn;
5889 var integer trx_nr := 0;
5890 var integer bts_nr := 0;
5891 var integer pcu_conn_id := -1;
5892
5893 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5894
5895 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5896 "RSL CHAN ACT");
5897 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5898 "RF CHAN REL", true);
5899 setverdict(pass);
5900}
5901testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5902 var ConnHdlrPars pars;
5903 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005904 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005905
5906 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5907 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5908 vc_conn.done;
5909}
5910
5911/* 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 +07005912private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005913 var PCUIF_Message first_info;
5914 var integer ts_nr := g_chan_nr.tn;
5915 var integer trx_nr := 0;
5916 var integer bts_nr := 0;
5917 var integer pcu_conn_id := -1;
5918
5919 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5920
5921 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5922 "RSL CHAN ACT");
5923
5924 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5925 alt {
5926 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5927 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005929 }
5930 [] RSL.receive { repeat; }
5931 }
5932
5933 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5934 "RF CHAN REL", true);
5935 setverdict(pass);
5936}
5937testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5938 var ConnHdlrPars pars;
5939 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005940 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005941
5942 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5943 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5944 vc_conn.done;
5945}
5946
5947/* 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 +07005948private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005949 var PCUIF_Message first_info;
5950 var integer ts_nr := g_chan_nr.tn;
5951 var integer trx_nr := 0;
5952 var integer bts_nr := 0;
5953 var integer pcu_conn_id := -1;
5954
5955 /* register for the TCH/F channel number */
5956 f_rslem_register(0, g_chan_nr);
5957
5958 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5959
5960 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5961
5962 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5963 "RSL CHAN ACT");
5964
5965 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5966
5967 setverdict(pass);
5968}
5969testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5970 var ConnHdlrPars pars;
5971 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005972 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005973
5974 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5975 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5976 vc_conn.done;
5977}
5978
5979
Harald Welte0472ab42018-03-12 15:02:26 +01005980/***********************************************************************
5981 * LAPDm / RLL related
5982 ***********************************************************************/
5983
5984private function f_tx_lapdm(template (value) LapdmFrame l,
5985 template (value) RslLinkId link_id) runs on ConnHdlr {
5986 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005987 var template (value) SacchL1Header l1h;
5988
5989 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005990 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005991 /* Compose dummy L1 header */
5992 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5993 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 +02005994 } else {
5995 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005996 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 +01005997 }
Harald Welte0472ab42018-03-12 15:02:26 +01005998}
5999
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006000private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006001 uint3_t sapi,
6002 RslLinkId link_id,
6003 octetstring l3,
6004 boolean exp
6005}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006006private type record of RllTestCase RllTestCases;
6007private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
6008 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006009 sapi := sapi,
6010 link_id := id,
6011 l3 := l3,
6012 exp := exp
6013}
6014
6015/* execute the same callback function with a set of different parameters (tcs) on a
6016 * variety of logical channels */
6017private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6018 var ConnHdlrPars pars;
6019 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006020 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006021
6022 /* test on each of the channels we have */
6023 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6024 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6025
6026 /* test each of the test cases on the current channel */
6027 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6028 pars.spec.rll := tcs[j];
6029 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6030 vc_conn := f_start_handler(fn, pars);
6031 vc_conn.done;
6032 }
6033 }
6034
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006035 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006036}
6037
6038/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6039private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6040 var RllTestCase tc := g_pars.spec.rll;
6041 timer T := 3.0;
6042
6043 f_l1_tune(L1CTL);
6044 RSL.clear;
6045
6046 /* activate the logical channel */
6047 f_est_dchan();
6048 L1CTL.clear;
6049
6050 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6051 T.start;
6052 alt {
6053 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6054 if (tc.exp) {
6055 setverdict(pass);
6056 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006057 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006058 }
6059 }
6060 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6061 if (tc.exp) {
6062 setverdict(pass);
6063 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006064 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006065 }
6066 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006067 /* We also expect to receive the measurements */
6068 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006069 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006071 }
6072 [not tc.exp] T.timeout {
6073 setverdict(pass);
6074 }
6075 }
6076
6077 f_rsl_chan_deact();
6078 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6079 f_rslem_unregister(0, g_chan_nr);
6080}
6081testcase TC_rll_est_ind() runs on test_CT {
6082 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006083 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006084 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006085 /* normal SAPI0 establishment */
6086 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006087 /* SAPI 3 doesn't support contention resolution */
6088 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6089 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6090 /* normal SAPI3 establishment on main DCCH */
6091 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6092 /* normal SAPI3 establishment on SACCH */
6093 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6094 };
6095 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6096}
6097
6098/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6099private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6100 var RllTestCase tc := g_pars.spec.rll;
6101 var L1ctlDlMessage dl;
6102 timer T := 3.0;
6103
6104 f_l1_tune(L1CTL);
6105 RSL.clear;
6106
6107 /* activate the logical channel */
6108 f_est_dchan();
6109 L1CTL.clear;
6110
6111 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6112 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6113 T.start;
6114 alt {
6115 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6116 var LapdmFrame lapdm;
6117 var octetstring l2 := dl.payload.data_ind.payload;
6118 if (dl.dl_info.link_id.c == SACCH) {
6119 /* remove L1 header */
6120 l2 := substr(l2, 2, lengthof(l2)-2);
6121 }
6122 lapdm.ab := dec_LapdmFrameAB(l2);
6123 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6124 setverdict(pass);
6125 } else {
6126 repeat;
6127 }
6128 }
6129 [] L1CTL.receive { repeat; }
6130 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006132 }
6133 }
6134
6135 f_rsl_chan_deact();
6136 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6137 f_rslem_unregister(0, g_chan_nr);
6138}
6139testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6140 var RllTestCases tcs := {
6141 /* normal SAPI3 establishment on main DCCH */
6142 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6143 };
6144 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6145}
6146testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6147 var RllTestCases tcs := {
6148 /* normal SAPI3 establishment on SACCH */
6149 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6150 }
6151 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6152}
6153
6154/* altstep to receive a LAPDm frame matching the given template */
6155private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6156 var L1ctlDlMessage dl;
6157 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6158 var LapdmFrame lapdm;
6159 var octetstring l2 := dl.payload.data_ind.payload;
6160 if (dl.dl_info.link_id.c == SACCH) {
6161 /* remove L1 header */
6162 l2 := substr(l2, 2, lengthof(l2)-2);
6163 }
6164 if (ischosen(exp.ab)) {
6165 lapdm.ab := dec_LapdmFrameAB(l2);
6166 } else if (ischosen(exp.b4)) {
6167 lapdm.b4 := dec_LapdmFrameB4(l2);
6168 } else if (ischosen(exp.bbis)) {
6169 lapdm.bbis := dec_LapdmFrameBbis(l2);
6170 }
6171 log("Rx LAPDm ", lapdm);
6172 if (match(lapdm, exp)) {
6173 setverdict(pass);
6174 } else {
6175 repeat;
6176 }
6177 }
6178 [] L1CTL.receive { repeat; }
6179}
6180private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6181 timer T := t;
6182 T.start;
6183 alt {
6184 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006185 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006186 }
6187 [] as_l1_exp_lapdm(exp);
6188 }
6189}
6190
6191/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6192private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6193 /* send SABM from MS -> BTS */
6194 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6195 /* expect RLL EST IND on Abis */
6196 alt {
6197 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6198 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6199 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006200 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006201 }
6202 [] RSL.receive { repeat; }
6203 }
6204 /* expect UA from BTS -> MS */
6205 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6206}
6207
6208/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6209private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6210 var RllTestCase tc := g_pars.spec.rll;
6211
6212 f_l1_tune(L1CTL);
6213 RSL.clear;
6214
6215 /* activate the logical channel */
6216 f_est_dchan();
6217 L1CTL.clear;
6218
6219 /* first establish the link-layer */
6220 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6221
6222 /* then send the DISC */
6223 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6224 /* ... and expect the REL IND on the RSL side */
6225 alt {
6226 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6227 setverdict(pass);
6228 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006229 /* We also expect to receive the measurements */
6230 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006231 }
6232
6233 /* release the channel */
6234 f_rsl_chan_deact();
6235 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6236 f_rslem_unregister(0, g_chan_nr);
6237}
6238testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6239 var RllTestCases tcs := {
6240 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6241 };
6242 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6243}
6244
6245testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6246 var RllTestCases tcs := {
6247 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6248 };
6249 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6250}
6251testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6252 var RllTestCases tcs := {
6253 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6254 };
6255 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6256}
6257testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6258 var RllTestCases tcs := {
6259 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6260 };
6261 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6262}
6263
6264/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6265private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6266 var RllTestCase tc := g_pars.spec.rll;
6267 f_l1_tune(L1CTL);
6268 RSL.clear;
6269
6270 /* activate the logical channel */
6271 f_est_dchan();
6272 L1CTL.clear;
6273
6274 /* first establish the link-layer */
6275 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6276
6277 /* then send the REL REQ via RSL */
6278 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6279 /* ... and expect the DISC on the Um side */
6280 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006281 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006282 /* FIXME: send a UA in resposne to the DISC */
6283 }
6284 }
6285
6286 /* release the channel */
6287 f_rsl_chan_deact();
6288 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6289 f_rslem_unregister(0, g_chan_nr);
6290}
6291testcase TC_rll_rel_req() runs on test_CT {
6292 var RllTestCases tcs := {
6293 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6294 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6295 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6296 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6297 };
6298 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6299}
6300
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006301/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006302testcase TC_rll_data_req() runs on test_CT {
6303}
6304
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006305/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006306testcase TC_rll_data_ind() runs on test_CT {
6307}
6308
6309/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6310private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6311 var RllTestCase tc := g_pars.spec.rll;
6312
6313 f_l1_tune(L1CTL);
6314 RSL.clear;
6315
6316 f_est_dchan();
6317 L1CTL.clear;
6318
6319 /* Send UNITDATA REQ on RSL side */
6320 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6321 /* Expect it to arrive on the other side */
6322 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006323 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006324 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006325 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006326 }
6327
6328 /* release the channel */
6329 f_rsl_chan_deact();
6330 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6331 f_rslem_unregister(0, g_chan_nr);
6332}
6333testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6334 var octetstring l3 := f_rnd_octstring(15);
6335 var RllTestCases tcs := {
6336 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6337 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6338 };
6339 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6340}
6341testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6342 var octetstring l3 := f_rnd_octstring(19);
6343 var RllTestCases tcs := {
6344 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6345 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6346 };
6347 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6348}
6349
6350/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6351private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6352 var RllTestCase tc := g_pars.spec.rll;
6353
6354 f_l1_tune(L1CTL);
6355 RSL.clear;
6356
6357 f_est_dchan();
6358 L1CTL.clear;
6359
6360 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006361 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006362 /* Expdct RLL UNITDATA IND on RSL side */
6363 alt {
6364 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6365 setverdict(pass);
6366 }
6367 [] RSL.receive { repeat; }
6368 }
6369
6370 /* release the channel */
6371 f_rsl_chan_deact();
6372 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6373 f_rslem_unregister(0, g_chan_nr);
6374}
6375testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006376 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006377 var RllTestCases tcs := {
6378 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6379 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6380 };
6381 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6382}
6383testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6384 var octetstring l3 := f_rnd_octstring(18);
6385 var RllTestCases tcs := {
6386 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6387 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6388 };
6389 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6390}
6391
Harald Weltee613f962018-04-18 22:38:16 +02006392/***********************************************************************
6393 * Encryption Related
6394 ***********************************************************************/
6395
6396/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006397private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006398 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6399 if (link_id.c == SACCH) {
6400 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6401 } else {
6402 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6403 }
6404}
6405
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006406/* Expect (or not expect) other kinds of messages */
6407private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6408 [exp_any] RSL.receive { repeat; }
6409 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006411 }
6412}
6413
Harald Weltee613f962018-04-18 22:38:16 +02006414/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006415private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006416 RslLinkId link_id,
6417 octetstring l3,
6418 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006419 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006420) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006421 timer T := 3.0;
6422 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6423 T.start;
6424 /* Expect RLL UNITDATA IND on RSL side */
6425 alt {
6426 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6427 setverdict(pass);
6428 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006429 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006430 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006431 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006433 }
Harald Weltee613f962018-04-18 22:38:16 +02006434 }
6435}
6436
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006437/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6438private function f_data_mo(
6439 RslLinkId link_id,
6440 boolean p, uint3_t nr, uint3_t ns,
6441 octetstring l3,
6442 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006443 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006444) runs on ConnHdlr {
6445 timer T := 3.0;
6446 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6447 T.start;
6448 /* Expect RLL DATA IND on RSL side */
6449 alt {
6450 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6451 setverdict(pass);
6452 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006453 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006454 [] as_rsl_any_ind(exp_any);
6455 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006456 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006457 }
6458 }
6459}
6460
Harald Weltee613f962018-04-18 22:38:16 +02006461/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006462private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006463 f_l1_tune(L1CTL);
6464 f_est_dchan(true);
6465
6466 /* now we actually need to transmit some data both ways to check if the encryption works */
6467 var L1ctlDlMessage dl;
6468
Stefan Sperling603d98e2018-07-25 16:47:28 +02006469 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006470 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6471
6472 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6473 f_unitdata_mt(link_id, l3);
6474
6475 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6476 f_unitdata_mo(link_id, l3);
6477
6478 /* release the channel */
6479 f_rsl_chan_deact();
6480 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6481 f_rslem_unregister(0, g_chan_nr);
6482}
6483testcase TC_chan_act_a51() runs on test_CT {
6484 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6485 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6486 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6487}
6488testcase TC_chan_act_a52() runs on test_CT {
6489 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6490 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6491 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6492}
6493testcase TC_chan_act_a53() runs on test_CT {
6494 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6495 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6496 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6497}
6498
Eric Wildf1827a72019-05-28 17:37:35 +02006499/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6500 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 +07006501private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006502 f_l1_tune(L1CTL);
6503 f_est_dchan(true);
6504
6505 /* now we actually need to transmit some data both ways to check if the encryption works */
6506 var L1ctlDlMessage dl;
6507
6508 var octetstring l3 := f_rnd_octstring(20);
6509 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6510
6511 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6512 f_unitdata_mt(link_id, l3);
6513
6514 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6515 f_unitdata_mo(link_id, l3);
6516
6517 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006518 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006519
6520 /* modify key to break proper encryption */
6521 g_pars.encr.key := f_rnd_octstring(8);
6522 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6523 rsl.ies := rsl.ies & { ei };
6524 RSL.send(rsl);
6525
6526 timer T0 := 1.0;
6527 T0.start;
6528 /* Expect RSL MODIFY ACK */
6529 alt {
6530 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6531 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6532 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6533 }
6534 [] T0.timeout {
6535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6536 }
6537 }
6538
6539 var octetstring l3msg := f_rnd_octstring(15);
6540 timer T1 := 3.0;
6541 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6542 due to broken encryption */
6543 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6544 T1.start;
6545 alt {
6546 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6547 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6548 }
6549 [] T1.timeout {
6550 setverdict(pass);
6551 }
6552 }
6553
6554 /* release the channel */
6555 f_rsl_chan_deact();
6556 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6557 f_rslem_unregister(0, g_chan_nr);
6558}
6559testcase TC_rsl_modify_encr() runs on test_CT {
6560 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6561 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6562 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6563}
Harald Weltee613f962018-04-18 22:38:16 +02006564
6565/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006566private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006567 /* L3 payload doesn't matter, as it is passed transparently */
6568 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6569 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6570 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6571
6572 f_l1_tune(L1CTL);
6573
6574 /* first establish a dedicated channel in the clear */
6575 f_est_dchan(false);
6576
6577 /* Establish ABM */
6578 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6579
6580 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6581 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6582 /* expect the L3 to arrive still unencrypted on the MS side */
6583 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6584
6585 /* configure L1 to apply ciphering */
6586 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6587 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6588
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006589 /* send first ciphered I-frame in response and expect it on RSL */
6590 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006591
6592 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6593 * and hence enable encryption also on the downlink */
6594
6595 /* expect bi-directional communication work in encrypted mode */
6596 f_unitdata_mo(link_id, f_rnd_octstring(15));
6597 f_unitdata_mt(link_id, f_rnd_octstring(15));
6598
6599 /* release the channel */
6600 f_rsl_chan_deact();
6601 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6602 f_rslem_unregister(0, g_chan_nr);
6603}
6604testcase TC_encr_cmd_a51() runs on test_CT {
6605 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6606 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6607 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6608}
6609testcase TC_encr_cmd_a52() runs on test_CT {
6610 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6611 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6612 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6613}
6614testcase TC_encr_cmd_a53() runs on test_CT {
6615 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6616 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6617 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6618}
6619
6620private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6621 var LapdmFrame lf;
6622 var octetstring reenc;
6623
6624 /* decode the LAPDm frame */
6625 if (ischosen(exp_match.ab)) {
6626 lf.ab := dec_LapdmFrameAB(enc);
6627 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006628 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006629 }
6630
6631 /* check if decoder result matches expectation */
6632 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006633 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006634 } else {
6635 log(name, ": matched");
6636 setverdict(pass);
6637 }
6638
6639 /* test if re-encoded frame equals original input */
6640 reenc := enc_LapdmFrame(lf);
6641 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006642 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006643 } else {
6644 setverdict(pass);
6645 }
6646}
6647
6648testcase TC_lapdm_selftest() runs on test_CT {
6649 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6650 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6651 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6652 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6653 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6654 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6655 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6656}
6657
Stefan Sperling4880be42018-08-07 18:12:59 +02006658/***********************************************************************
6659 * DTX Related (see GSM 05.08, section 8.3)
6660 ***********************************************************************/
6661
6662/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006663private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006664 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6665 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6666 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6667 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6668}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006669private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006670 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6671 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6672}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006673private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006674 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6675 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6676 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6677 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6678}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006679private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006680 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6681 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6682 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6683 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6684 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6685 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6686 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6687 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6688}
6689
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006690private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006691 var L1ctlDlMessage dl;
6692 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6693 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6694 var GsmFrameNumber first_fn;
6695 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006696 var integer nfill_frames_sacch := 0;
6697 var integer nfill_frames_nonsacch := 0;
6698 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006699 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6700 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006701 const integer frame_dtx_tchf_mod := 104;
6702 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6703 * which operates in terms of blocks rather than frames. */
6704 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6705 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006706 timer T := 5.0;
6707
6708 f_l1_tune(L1CTL);
6709 RSL.clear;
6710 L1CTL.clear;
6711
6712 /* activate TCHF signalling channel */
6713 f_est_dchan(false);
6714
6715 T.start;
6716 alt {
6717 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6718 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6719 var octetstring l2 := dl.payload.data_ind.payload;
6720
6721 if (is_first_frame) {
6722 is_first_frame := false;
6723 first_fn := dl.dl_info.frame_nr;
6724 }
6725
6726 if (dl.dl_info.link_id.c == SACCH) {
6727 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6728 if (not match(l2_fill_frame_sacch, l2)) {
6729 repeat;
6730 }
6731 } else if (not match(l2_fill_frame, l2)) {
6732 repeat;
6733 }
6734
6735 if (dtxd) {
6736 if (not f_g_chan_is_tchf()) {
6737 T.stop;
6738 f_rsl_chan_deact();
6739 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006740 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 +02006741 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006742 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006743 T.stop;
6744 f_rsl_chan_deact();
6745 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006746
6747 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6748 * 2 SACCH, 1 TCH/F */
6749 expected_fill_frames := 3;
6750
6751 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6752 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6753 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006755 } else {
6756 setverdict(pass);
6757 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006758 } else {
6759 if (dl.dl_info.link_id.c == SACCH) {
6760 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006761 repeat;
6762 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006763 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6764 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6765 * we should only see the subset of frames numbers which correspond to a block boundary.
6766 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6767 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6768 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6769 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6770 repeat;
6771 }
6772 }
6773 log("Received DTX TCH fill frame with bad frame number: ", fn,
6774 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6775 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6776 f_rsl_chan_deact();
6777 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006779 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006780 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006781 if (dl.dl_info.link_id.c == SACCH) {
6782 nfill_frames_sacch := nfill_frames_sacch + 1;
6783 } else {
6784 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6785 }
6786 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006787 T.stop;
6788 if (f_g_chan_is_tchf()) {
6789 /* Without DTX we can expect 25 fill frames for every 104 frames.
6790 * (24 FACCH + 1 SACCH filling) */
6791 expected_fill_frames := 25;
6792 } else if (f_g_chan_is_tchh()) {
6793 /* We can expect 2 fill frames for every 104 frames. */
6794 expected_fill_frames := 2;
6795 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6796 /* We can expect 5 fill frames for every 104 frames. */
6797 expected_fill_frames := 5;
6798 } else {
6799 f_rsl_chan_deact();
6800 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006801 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006802 }
6803
6804 f_rsl_chan_deact();
6805 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006806
6807 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006808 setverdict(pass);
6809 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006810 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6811 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006812 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006813 }
6814 } else {
6815 repeat;
6816 }
6817 }
6818 }
6819 [] L1CTL.receive { repeat; }
6820 [] T.timeout {
6821 f_rsl_chan_deact();
6822 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006823 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006824 }
6825 }
6826}
6827
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006828private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006829 f_test_l2_fill_frames(false);
6830}
6831
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006832private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006833 f_test_l2_fill_frames(true);
6834}
6835
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006836private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006837 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02006838 var ConnHdlr vc_conn;
6839 var ConnHdlrPars pars;
6840 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006841 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006842 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02006843 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006844 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02006845 if (dtxd) {
6846 if (i >= 4) { /* DTX is only allowed on TCH/F */
6847 break;
6848 }
6849 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6850 } else {
6851 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6852 }
6853 vc_conn.done;
6854 }
6855}
6856
6857/* Verify that L2 fill frames are sent on TCH in signaling mode if
6858 * there is nothing to transmit while DTX is disabled on downlink. */
6859testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6860 f_tch_sign_l2_fill_frame(false);
6861}
6862
6863/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6864 * there is nothing to transmit while DTX is enabled on downlink. */
6865testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6866 f_tch_sign_l2_fill_frame(true);
6867}
Harald Welte0472ab42018-03-12 15:02:26 +01006868
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006869testcase TC_chopped_ipa_ping() runs on test_CT {
6870 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6871}
6872
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006873testcase TC_chopped_ipa_payload() runs on test_CT {
6874 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6875}
6876
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006877
6878/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6879 * Return value: Measurement Report to be sent (encoded octetstring). */
6880type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6881 runs on ConnHdlr return octetstring;
6882
6883private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6884runs on ConnHdlr {
6885 var L1ctlDlMessage l1_dl;
6886 var SacchL1Header l1h;
6887 var octetstring l2;
6888
6889 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6890 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6891 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6892 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6893
6894 /* Pass it to the user specified call-back function */
6895 l2 := cb.apply(l1h, num_blocks);
6896 /* Send a Measurement Report generated by the call-back */
6897 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6898 l1_dl.dl_info.link_id,
6899 l1h, l2));
6900
6901 /* Shall we keep going? */
6902 num_blocks := num_blocks - 1;
6903 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6904 if (num_blocks > 0) { repeat; }
6905 }
6906 [] L1CTL.receive { repeat; }
6907}
6908
6909private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6910runs on ConnHdlr return octetstring {
6911 /* Command the L1 to apply received parameters */
6912 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6913
6914 /* Dummy measurement report (the results are invalid) */
6915 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6916}
6917
6918private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6919runs on ConnHdlr return octetstring {
6920 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6921 setverdict(fail, "Unexpected MS Power level change: ",
6922 g_pars.l1_pars.ms_power_level, " -> ",
6923 l1h.ms_power_lvl);
6924 }
6925
6926 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6927}
6928
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07006929private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
6930runs on ConnHdlr return octetstring {
6931 /* UL RSSI oscillation driven by SACCH block number */
6932 if (num_blocks rem 2 == 0) {
6933 f_trxc_fake_rssi(-100);
6934 } else {
6935 f_trxc_fake_rssi(-50);
6936 }
6937
6938 /* Make sure that MS power level remains constant */
6939 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
6940}
6941
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006942/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6943private function f_TC_ms_pwr_ctrl_constant(charstring id)
6944runs on ConnHdlr {
6945 var integer num_blocks := 8;
6946 timer T := int2float(num_blocks);
6947
6948 f_l1_tune(L1CTL);
6949 RSL.clear;
6950
6951 /* These IEs are needed for autonomous MS power control */
6952 var template (value) RSL_IE_List ies := {
6953 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6954 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6955 }),
6956 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6957 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6958 })
6959 };
6960
6961 /* Ensure that 'rx-current' equals 'rx-target' */
6962 f_trxc_fake_rssi(mp_uplink_power_target);
6963
6964 /* Establish a dedicated channel */
6965 f_est_dchan(more_ies := valueof(ies));
6966
6967 L1CTL.clear;
6968 T.start;
6969 alt {
6970 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
6971 [] T.timeout {
6972 setverdict(fail, "Not all SACCH blocks were processed in time, ",
6973 num_blocks, " were not handled");
6974 }
6975 }
6976}
6977testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
6978 var ConnHdlr vc_conn;
6979 var ConnHdlrPars pars;
6980
6981 f_init();
6982
6983 /* Explicitly configure the Uplink power target (in dBm) */
6984 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
6985
6986 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
6987 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6988 log(testcasename(), ": starting on ", pars.chan_nr);
6989
6990 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
6991 pars, trxc_comp := true);
6992 vc_conn.done;
6993 }
6994
6995 /* No need to reset Uplink power parameters - the IUT restarts anyway */
6996 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6997}
6998
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07006999/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7000private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7001runs on ConnHdlr {
7002 var integer num_blocks := 16;
7003 timer T := int2float(num_blocks);
7004
7005 f_l1_tune(L1CTL);
7006 RSL.clear;
7007
7008 /* These IEs are needed for autonomous MS power control */
7009 var template (value) RSL_IE_List ies := {
7010 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7011 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7012 }),
7013 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7014 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7015 })
7016 };
7017
7018 /* Ensure that 'rx-current' equals 'rx-target' */
7019 f_trxc_fake_rssi(mp_uplink_power_target);
7020
7021 /* Establish a dedicated channel */
7022 f_est_dchan(more_ies := valueof(ies));
7023
7024 L1CTL.clear;
7025 T.start;
7026 alt {
7027 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7028 [] T.timeout {
7029 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7030 num_blocks, " were not handled");
7031 }
7032 }
7033}
7034testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7035 var ConnHdlr vc_conn;
7036 var ConnHdlrPars pars;
7037
7038 f_init();
7039
7040 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7041 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7042 /* Explicitly configure the Uplink power range (target and delte) */
7043 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7044 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7045
7046 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7047 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7048 log(testcasename(), ": starting on ", pars.chan_nr);
7049
7050 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7051 pars, trxc_comp := true);
7052 vc_conn.done;
7053 }
7054
7055 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7056 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7057}
7058
Harald Welte0472ab42018-03-12 15:02:26 +01007059/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7060/* protocol error as per 44.006 */
7061/* link layer failure (repetition of I-frame N200 times without ACK */
7062/* repetition of SABM or DISC N200 times without ACK */
7063/* receptiom of SABM in multi-frame established state */
7064
7065
Harald Welte68e495b2018-02-25 00:05:57 +01007066/* TODO Areas:
7067
7068* channel activation
7069** with BS_Power / MS_Power, bypassing power control loop
7070** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007071** with timing advance from initial activation on
7072* mode modify
7073** encryption
7074** multirate
7075* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007076** unsupported algorithm
7077* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007078* BS Power Control
7079* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007080* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007081* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007082** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007083* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007084** DATA_IND from BTS->PCU
7085** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007086
7087*/
Harald Welte70767382018-02-21 12:16:40 +01007088
7089control {
7090 execute( TC_chan_act_stress() );
7091 execute( TC_chan_act_react() );
7092 execute( TC_chan_deact_not_active() );
7093 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007094 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007095 execute( TC_sacch_filling() );
7096 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007097 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007098 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007099 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007100 execute( TC_sacch_chan_act_ho_async() );
7101 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007102 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007103 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007104 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007105 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007106 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007107 execute( TC_rach_load_idle_thresh0() );
7108 execute( TC_rach_load_idle_below_thresh() );
7109 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007110 execute( TC_meas_res_speech_tchf() );
7111 execute( TC_meas_res_speech_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007112 execute( TC_meas_res_sign_tchf() );
7113 execute( TC_meas_res_sign_tchh() );
7114 execute( TC_meas_res_sign_sdcch4() );
7115 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007116 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007117 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007118 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007119 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007120 execute( TC_rsl_bs_pwr_static_ass() );
7121 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007122 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007123 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007124 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007125 execute( TC_rsl_ms_pwr_dyn_up() );
7126 execute( TC_rsl_ms_pwr_dyn_down() );
7127 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7128 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007129 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007130 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007131 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007132 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007133 execute( TC_paging_imsi_80percent() );
7134 execute( TC_paging_tmsi_80percent() );
7135 execute( TC_paging_imsi_200percent() );
7136 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007137 execute( TC_rsl_protocol_error() );
7138 execute( TC_rsl_mand_ie_error() );
7139 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007140 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007141 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007142 execute( TC_si_sched_2bis() );
7143 execute( TC_si_sched_2ter() );
7144 execute( TC_si_sched_2ter_2bis() );
7145 execute( TC_si_sched_2quater() );
7146 execute( TC_si_sched_13() );
7147 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007148 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007149 execute( TC_ipa_crcx_twice_not_active() );
7150 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007151 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007152 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007153
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007154 if (mp_pcu_socket != "") {
7155 execute( TC_pcu_act_req() );
7156 execute( TC_pcu_act_req_wrong_ts() );
7157 execute( TC_pcu_act_req_wrong_bts() );
7158 execute( TC_pcu_act_req_wrong_trx() );
7159 execute( TC_pcu_deact_req() );
7160 execute( TC_pcu_deact_req_wrong_ts() );
7161 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007162 if (mp_l1_supports_gprs) {
7163 execute( TC_pcu_data_req_pdtch() );
7164 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007165 execute( TC_pcu_data_req_wrong_bts() );
7166 execute( TC_pcu_data_req_wrong_trx() );
7167 execute( TC_pcu_data_req_wrong_ts() );
7168 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007169 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007170 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007171 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007172 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007173 execute( TC_pcu_data_req_imm_ass_pch() );
7174 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007175 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007176 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007177 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007178 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007179 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007180 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007181 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007182 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007183 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007184 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007185 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007186 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007187 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007188 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007189 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007190 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007191 execute( TC_dyn_osmo_pdch_act_deact() );
7192 execute( TC_dyn_osmo_pdch_double_act() );
7193 execute( TC_dyn_ipa_pdch_act_deact() );
7194 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7195
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007196 if (PCUIF_Types.mp_pcuif_version >= 10) {
7197 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007198 execute( TC_pcu_socket_nsvc_ipv4() );
7199 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007200 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007201 } else {
7202 log("PCU socket path not available, skipping PCU tests");
7203 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007204
Harald Welte3d04ae62018-04-04 20:29:05 +02007205 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007206 execute( TC_dyn_osmo_pdch_tchf_act() );
7207 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007208 execute( TC_dyn_ipa_pdch_tchf_act() );
7209 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007210
7211 execute( TC_rll_est_ind() );
7212 execute( TC_rll_est_req_DCCH_3() );
7213 execute( TC_rll_est_req_ACCH_3() );
7214 execute( TC_rll_rel_ind_DCCH_0() );
7215 execute( TC_rll_rel_ind_DCCH_3() );
7216 execute( TC_rll_rel_ind_ACCH_0() );
7217 execute( TC_rll_rel_ind_ACCH_3() );
7218 execute( TC_rll_rel_req() );
7219 execute( TC_rll_unit_data_req_DCCH() );
7220 execute( TC_rll_unit_data_req_ACCH() );
7221 execute( TC_rll_unit_data_ind_DCCH() );
7222 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007223
7224 execute( TC_chan_act_a51() );
7225 execute( TC_chan_act_a52() );
7226 execute( TC_chan_act_a53() );
7227 execute( TC_encr_cmd_a51() );
7228 execute( TC_encr_cmd_a52() );
7229 execute( TC_encr_cmd_a53() );
7230
Harald Welteee25aae2019-05-19 14:32:37 +02007231 execute( TC_err_rep_wrong_mdisc() );
7232 execute( TC_err_rep_wrong_msg_type() );
7233 execute( TC_err_rep_wrong_sequence() );
7234
Harald Weltee613f962018-04-18 22:38:16 +02007235 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007236
7237 execute( TC_tch_sign_l2_fill_frame() );
7238 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007239
7240 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007241 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007242
7243 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007244 execute( TC_ms_pwr_ctrl_pf_ewma() );
Harald Welte70767382018-02-21 12:16:40 +01007245}
7246
7247
7248}