blob: 6fc396d016fd3b04b1e0ff54267bfd0044607f22 [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;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100109 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200110 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200111 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200112 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
113 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700114 /* how many transceivers do we expect to connect */
115 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700116 /* frequency hopping status */
117 boolean mp_freq_hop_enabled := false;
118 /* frequency hopping parameters */
119 FreqHopConfig mp_fh_config;
Harald Welte70767382018-02-21 12:16:40 +0100120}
121
Harald Welte629cc6b2018-03-11 17:19:05 +0100122type record of RslChannelNr ChannelNrs;
123
Harald Welte70767382018-02-21 12:16:40 +0100124type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100125 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100126 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100127 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100128 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100129 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100130 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100131
132 /* L1CTL port (for classic tests) */
133 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100134
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700135 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700136 port TRXC_CODEC_PT BTS_TRXC;
137 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100138
Harald Weltef50e3ae2018-09-10 10:27:56 +0200139 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100140 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200141 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100142
Harald Welte883340c2018-02-28 18:59:29 +0100143 /* PCU Interface of BTS */
144 port PCUIF_CODEC_PT PCU;
145 var integer g_pcu_conn_id;
146 /* Last PCU INFO IND we received */
147 var PCUIF_Message g_pcu_last_info;
148
Harald Welte48494ca2018-02-25 16:59:50 +0100149 /* SI configuration */
150 var SystemInformationConfig si_cfg := {
151 bcch_extended := false,
152 si1_present := false,
153 si2bis_present := false,
154 si2ter_present := false,
155 si2quater_present := false,
156 si7_present := false,
157 si8_present := false,
158 si9_present := false,
159 si13_present := false,
160 si13alt_present := false,
161 si15_present := false,
162 si16_present := false,
163 si17_present := false,
164 si2n_present := false,
165 si21_present := false,
166 si22_present := false
167 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100168
169 /* all logical channels available on the BTS */
170 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100171 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100172}
173
174/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200175type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100176 port L1CTL_PT L1CTL;
177
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700178 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700179 port TRXC_CODEC_PT BTS_TRXC;
180 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100181
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200182 /* port to be initialized optionally to access BSC VTY */
183 port TELNETasp_PT BSCVTY;
184
Harald Welte70767382018-02-21 12:16:40 +0100185 timer g_Tguard;
186 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
187
188 var ConnHdlrPars g_pars;
189 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100190 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200191
192 /* PCU Interface of BTS */
193 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100194}
195
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700196private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700197 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200198 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700199 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200200 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700201 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200202 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700203 timer T;
204
Harald Welte70767382018-02-21 12:16:40 +0100205 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
206 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
207
208 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
209 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
210 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
211
212 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
213 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700214
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700215 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700216 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700217 T.start(mp_ipa_up_timeout);
218 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700219 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700220 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
221 /* Make sure that all transceivers use unique stream ID */
222 if (trx_mask[enum2int(ev.sid)] == '1'B) {
223 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
224 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
225 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700226
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700227 trx_mask[enum2int(ev.sid)] := '1'B;
228 trx_count := trx_count + 1;
229
230 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200231 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700232 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200233 /* This message (RF RESource INDication) is sent by the IUT itself */
234 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
235 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
237 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
238 }
239 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
241 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
242 }
243
244 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
245 rfind_count := rfind_count + 1;
246 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
247 if (rfind_count < mp_transceiver_num) { repeat; }
248 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700249 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
250 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
251 [] T.timeout {
252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
253 "Timeout waiting for RSL bring up");
254 }
255 }
Harald Welte70767382018-02-21 12:16:40 +0100256}
257
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700258friend type record FreqHopPars {
259 /* Whether frequency hopping is in use */
260 boolean enabled,
261 /* Mobile Allocation Index Offset / Hopping Sequence Number */
262 MaioHsn maio_hsn,
263 /* MA bitmap to be indicated in RR Immediate Assignment */
264 MobileAllocationLV ma_map,
265 /* The actual Mobile Allocation (ARFCN list) to be used */
266 L1ctlMA ma
267};
268
Harald Welte70767382018-02-21 12:16:40 +0100269type record ConnHdlrPars {
270 RslChannelNr chan_nr,
271 RSL_IE_ChannelMode chan_mode,
272 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100273 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200274 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200275 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700276 BtsBand bts0_band optional,
277
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700278 /* Frequency hopping parameters */
279 FreqHopPars fhp
280};
Harald Welte0472ab42018-03-12 15:02:26 +0100281
282/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700283private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100284 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100285}
286
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700287private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100288 max_retrans := RACH_MAX_RETRANS_7,
289 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100290 cell_barr_access := false,
291 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100292 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100293};
294
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700295private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100296 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200297 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100298 acs := '0'B,
299 neci := true,
300 rxlev_access_min := 0
301}
302
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700303private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100304 mcc_mnc := '262F42'H,
305 lac := 42
306}
307
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700308private template (value) GPRSIndicator ts_GPRSIndicator_def := {
309 ra_colour := 0,
310 si13_pos := '0'B
311}
312
313private template (value) SI3RestOctets ts_SI3RestOctets_def
314modifies ts_SI3RestOctets := {
315 gprs_ind := {
316 presence := CSN1_H,
317 ind := ts_GPRSIndicator_def
318 }
319}
320
321private template (value) SI4RestOctets ts_SI4RestOctets_def
322modifies ts_SI4RestOctets := {
323 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700324 presence := CSN1_H,
325 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700326 }
327}
328
Harald Welte7484fc42018-02-24 14:09:45 +0100329/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700330private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100331 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100332 payload := {
333 si3 := {
334 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100335 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100336 ctrl_chan_desc := {
337 msc_r99 := true,
338 att := true,
339 bs_ag_blks_res := 1,
340 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100341 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100342 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
343 spare := '00'B,
344 bs_pa_mfrms := 0, /* 2 multiframes */
345 t3212 := 1 /* 6 minutes */
346 },
Harald Welte82ccef72018-02-25 16:17:33 +0100347 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100348 dn_ind := false,
349 pwrc := false,
350 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100351 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100352 },
Harald Weltef10153f2018-02-25 16:34:05 +0100353 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100354 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200355 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100356 }
357 }
358}
Harald Welte70767382018-02-21 12:16:40 +0100359
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700360private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100361 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100362 payload := {
363 si2 := {
364 bcch_freq_list := '00000000000000000000000000000000'O,
365 ncc_permitted := '11111111'B,
366 rach_control := ts_RachCtrl_default
367 }
368 }
369}
370
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700371private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100372 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100373 payload := {
374 si4 := {
375 lai := ts_LAI_default,
376 cell_sel_par := ts_CellSelPar_default,
377 rach_control := ts_RachCtrl_default,
378 cbch_chan_desc := omit,
379 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200380 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100381 }
382 }
383}
384
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700385private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100386runs on test_CT {
387 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700388 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100389}
390
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700391private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100392runs on test_CT {
393 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
394 log("Setting ", rsl_si_type, ": ", si_dec);
395 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
396}
397
Harald Welte505cf9b2018-09-15 17:47:23 +0300398friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100399 map(self:BTSVTY, system:BTSVTY);
400 f_vty_set_prompts(BTSVTY);
401 f_vty_transceive(BTSVTY, "enable");
402}
403
Harald Welte505cf9b2018-09-15 17:47:23 +0300404friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200405 map(self:BSCVTY, system:BSCVTY);
406 f_vty_set_prompts(BSCVTY, "OsmoBSC");
407 f_vty_transceive(BSCVTY, "enable");
408}
409
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200410friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
411 map(self:BSCVTY, system:BSCVTY);
412 f_vty_set_prompts(BSCVTY, "OsmoBSC");
413 f_vty_transceive(BSCVTY, "enable");
414}
415
Harald Welte883340c2018-02-28 18:59:29 +0100416/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200417private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
418 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100419 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200420 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
421 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100422 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200423 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100425 }
426}
427
Harald Weltef26de0b2018-04-04 20:28:05 +0200428private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
429 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100430 timer T := 2.0;
431 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100432 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200433 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100434 return;
435 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200436 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100437
438 T.start;
439 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200440 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100441 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200442 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100443 }
444 }
445}
446
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700447private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
448 out integer trxc_conn_id) {
449 var Result res;
450
451 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
452 "", -1, -1, { udp := {} }, {});
453 if (not ispresent(res.connId)) {
454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
455 "Could not connect to the control (TRXC) interface " &
456 "of FakeTRX, check your configuration");
457 }
458 trxc_conn_id := res.connId;
459}
460
Harald Welte70767382018-02-21 12:16:40 +0100461/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700462friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200463 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100464 g_AllChannels := {
465 /* TS 1..4: TCH/F */
466 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
467 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
468 /* TS 5: TCH/H */
469 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
470 /* TS 0: SDCCH/4 */
471 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
472 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
473 /* TS 6: SDCCH/8 */
474 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
475 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
476 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
477 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
478 };
479
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200480 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700481 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200482 g_AllChanTypes := {
483 /* TS 1..4: TCH/F */
484 valueof(ts_RslChanNr_Bm(1)),
485 /* TS 5: TCH/H */
486 valueof(ts_RslChanNr_Lm(5,1)),
487 /* TS 0: SDCCH/4 */
488 valueof(ts_RslChanNr_SDCCH4(0,2)),
489 /* TS 6: SDCCH/8 */
490 valueof(ts_RslChanNr_SDCCH8(6,4))
491 };
492 } else {
493 g_AllChanTypes := {
494 /* TS 1..4: TCH/F */
495 valueof(ts_RslChanNr_Bm(1)),
496 /* TS 0: SDCCH/4 */
497 valueof(ts_RslChanNr_SDCCH4(0,2)),
498 /* TS 6: SDCCH/8 */
499 valueof(ts_RslChanNr_SDCCH8(6,4))
500 };
501 }
Harald Welte70767382018-02-21 12:16:40 +0100502 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100503 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100504 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200505 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100506
507 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100508 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
509 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
510 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
511 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100512
Harald Weltef26de0b2018-04-04 20:28:05 +0200513 map(self:PCU, system:PCU);
514 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100515
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700516 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100517 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700518
519 /* Init TRXC interface to FakeTRX */
520 map(self:BTS_TRXC, system:BTS_TRXC);
521 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
522
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700523 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700524 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 +0700525 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700526 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
527 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100528 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200529
530 /* Wait some extra time to make sure the BTS emits a stable carrier.
531 * (this is only relevant when running the tests with a physical BTS.) */
532 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100533}
534
Harald Welte68e495b2018-02-25 00:05:57 +0100535/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700536friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100537 map(self:L1CTL, system:L1CTL);
538 f_connect_reset(L1CTL);
539}
540
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700541private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100542
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700543private type record length(8) of FreqHopGroups FreqHopConfig;
544
545private type record of FreqHopGroup FreqHopGroups;
546private type record FreqHopGroup {
547 uint6_t hsn,
548 FreqHopGroupItems trx_maio
549};
550
551private type record of FreqHopGroupItem FreqHopGroupItems;
552private type record FreqHopGroupItem {
553 uint8_t trx_nr,
554 uint6_t maio
555};
556
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700557friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
558 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700559{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700560 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700561 var integer i, j;
562
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700563 fhp.enabled := false;
564
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700565 for (i := 0; i < lengthof(groups); i := i + 1) {
566 var FreqHopGroup g := groups[i];
567 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
568 var FreqHopGroupItem gi := g.trx_maio[j];
569 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700570 fhp.maio_hsn.maio := gi.maio;
571 fhp.maio_hsn.hsn := g.hsn;
572 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700573 break;
574 }
575 }
576
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700577 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700578 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700579 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
580 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
581 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700582
583 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700584 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
585 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700586 fhp.ma := fhp.ma & { l1ctl_ma_def[gi.trx_nr] };
587 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700588 }
589
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700590 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700591 break; /* We're done */
592 }
593 }
594}
595
Harald Welte70767382018-02-21 12:16:40 +0100596/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700597friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
598 boolean pcu_comp := false,
599 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100600runs on test_CT return ConnHdlr {
601 var charstring id := testcasename();
602 var ConnHdlr vc_conn;
603
604 vc_conn := ConnHdlr.create(id);
605 /* connect to RSL Emulation main component */
606 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
607 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700608
609 /* The ConnHdlr component may want to talk to some ports directly,
610 * so we disconnect it from the test_CT and connect it to the component.
611 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200612 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200613 unmap(self:PCU, system:PCU);
614 map(vc_conn:PCU, system:PCU);
615 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700616 if (trxc_comp) {
617 unmap(self:BTS_TRXC, system:BTS_TRXC);
618 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
619 }
Harald Welte70767382018-02-21 12:16:40 +0100620
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700621 /* Obtain frequency hopping parameters for a given timeslot */
622 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700623 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700624 }
625
Harald Welte70767382018-02-21 12:16:40 +0100626 vc_conn.start(f_handler_init(fn, id, pars));
627 return vc_conn;
628}
629
Harald Welte70767382018-02-21 12:16:40 +0100630private altstep as_Tguard() runs on ConnHdlr {
631 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100633 }
634}
635
Harald Welte990a3612019-05-27 14:02:13 +0200636friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
637 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100638}
639
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700640private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100641 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700642 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100643}
644
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700645private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100646 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700647 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100648}
649
650/* first function started in ConnHdlr component */
651private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
652runs on ConnHdlr {
653 g_pars := pars;
654 g_chan_nr := pars.chan_nr;
655
656 map(self:L1CTL, system:L1CTL);
657 f_connect_reset(L1CTL);
658
Harald Welted48c0c72019-06-05 10:01:15 +0200659 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700660 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100661 }
Harald Welte70767382018-02-21 12:16:40 +0100662
663 g_Tguard.start(pars.t_guard);
664 activate(as_Tguard());
665
666 f_rslem_register(0, pars.chan_nr);
667
668 /* call the user-supplied test case function */
669 fn.apply(id);
670}
671
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700672private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
673 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200674runs on ConnHdlr return RSL_Message {
675 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100676 timer T := 3.0;
677 RSL.send(tx);
678 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100679 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200680 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100681 T.stop;
682 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100683 }
Harald Welte1eba3742018-02-25 12:48:14 +0100684 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200685 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100686 }
Harald Welte21240e62018-03-11 21:43:35 +0100687 [not ignore_other] as_l1_sacch();
688 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700689 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700690 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100691 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200692 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100693 }
Harald Welte21240e62018-03-11 21:43:35 +0100694 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100695 }
Harald Welteb1726c92018-03-30 11:56:38 +0200696 return rx;
697}
698
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700699friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
700 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200701runs on ConnHdlr {
702 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100703}
704
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700705friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
706 boolean encr_enable := false,
707 RSL_IE_List more_ies := {},
708 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
709runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200710 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200711 if (encr_enable) {
712 /* append encryption related IEs, if requested */
713 var RSL_IE_EncryptionInfo encr_info;
714 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
715 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
716encr_info})) };
717 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200718 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200719 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100720}
721
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700722friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100723 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 +0100724 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100725}
726
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700727/* Default Mobile Allocation to be used for frequency hopping */
728private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
729 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
730
Harald Welte2f2b2b72019-05-31 22:24:57 +0200731friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100732 template RSL_IE_ChannelMode chan_mode,
733 float t_guard := 20.0) := {
734 chan_nr := valueof(chan_nr),
735 chan_mode := valueof(chan_mode),
736 t_guard := t_guard,
737 l1_pars := {
738 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100739 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100740 meas_ul := {
741 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200742 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100743 rxqual := 0
744 },
745 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200746 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100747 rxqual := 0
748 }
749 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200750 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100751 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200752 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200753 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100754 },
Harald Weltee613f962018-04-18 22:38:16 +0200755 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200756 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700757 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700758 fhp := {
759 enabled := false,
760 maio_hsn := ts_HsnMaio(0, 0),
761 ma_map := c_MA_null,
762 ma := l1ctl_ma_def
763 }
Harald Welte70767382018-02-21 12:16:40 +0100764}
765
Harald Welte93640c62018-02-25 16:59:33 +0100766/***********************************************************************
767 * Channel Activation / Deactivation
768 ***********************************************************************/
769
Harald Welte70767382018-02-21 12:16:40 +0100770/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700771private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100772 for (var integer i := 0; i < 500; i := i+1) {
773 f_rsl_chan_act(g_pars.chan_mode);
774 f_rsl_chan_deact();
775 }
776 setverdict(pass);
777}
778testcase TC_chan_act_stress() runs on test_CT {
779 var ConnHdlr vc_conn;
780 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200781 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100782 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
783 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100785}
786
787/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700788private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100789 f_rsl_chan_act(g_pars.chan_mode);
790 /* attempt to activate the same lchan again -> expect reject */
791 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
792 alt {
793 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200794 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100795 }
796 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
797 setverdict(pass);
798 }
799 }
800 f_rsl_chan_deact();
801}
802testcase TC_chan_act_react() runs on test_CT {
803 var ConnHdlr vc_conn;
804 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100805 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100806 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
807 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100809}
810
811/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700812private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100813 timer T := 3.0;
814 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
815 T.start;
816 alt {
817 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
818 setverdict(pass);
819 }
820 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100822 }
823 }
824}
825testcase TC_chan_deact_not_active() runs on test_CT {
826 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100827 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100828 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
829 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200830 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100831}
832
833/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700834private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100835 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
836 alt {
837 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200838 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100839 }
840 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
841 setverdict(pass);
842 }
843 }
844}
845private type record WrongChanNrCase {
846 RslChannelNr chan_nr,
847 charstring description
848}
849private type record of WrongChanNrCase WrongChanNrCases;
850private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
851 chan_nr := chan_nr,
852 description := desc
853}
854
855testcase TC_chan_act_wrong_nr() runs on test_CT {
856 var ConnHdlr vc_conn;
857 var ConnHdlrPars pars;
858
Harald Welte294b0a22018-03-10 23:26:48 +0100859 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100860
861 var WrongChanNrCases wrong := {
862 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
863 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
864 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
865 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
866 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
867 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
868 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
869 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
870 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
871 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
872 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
873 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
874 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
875 };
876
877 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
878 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
879 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
880 vc_conn.done;
881 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100883}
884
Harald Weltee613f962018-04-18 22:38:16 +0200885/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200886friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200887 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200888 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200889
890 /* test on each of the channels we have */
891 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
892 pars.chan_nr := valueof(g_AllChanTypes[i]);
893
894 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
895 vc_conn := f_start_handler(fn, pars);
896 vc_conn.done;
897 }
898
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200899 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200900}
901
Harald Welte93640c62018-02-25 16:59:33 +0100902/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100903 * SACCH handling
904 ***********************************************************************/
905
906private function f_exp_sacch(boolean exp) runs on ConnHdlr {
907 timer T_sacch := 3.0;
908 T_sacch.start;
909 alt {
910 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100912 }
913 [not exp] T_sacch.timeout {
914 setverdict(pass);
915 }
916 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
917 setverdict(pass);
918 }
919 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200920 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100921 }
922 [] L1CTL.receive { repeat; }
923 [] RSL.receive { repeat; }
924 }
925}
926
927/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
928private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
929 f_l1_tune(L1CTL);
930 RSL.clear;
931
932 /* activate the logical channel */
933 f_est_dchan();
934 L1CTL.clear;
935
936 /* check that SACCH actually are received as expected */
937 f_exp_sacch(true);
938
939 /* deactivate SACCH on the logical channel */
940 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
941 f_sleep(1.0);
942 L1CTL.clear;
943
944 /* check that no SACCH are received anymore */
945 f_exp_sacch(false);
946
947 /* release the channel */
948 f_rsl_chan_deact();
949 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
950}
951testcase TC_deact_sacch() runs on test_CT {
952 var ConnHdlr vc_conn;
953 var ConnHdlrPars pars;
954 f_init();
955 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
956 //for (var integer i := 0; i < 1; i := i+1) {
957 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
958 log(testcasename(), ": Starting for ", g_AllChannels[i]);
959 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
960 vc_conn.done;
961 }
962 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200963 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100964}
965
Harald Welte55700662018-03-12 13:15:43 +0100966/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100967private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
968 var L1ctlDlMessage dl;
969 /* check that the specified SI5 value is actually sent */
970 timer T_sacch := 3.0;
971 L1CTL.clear;
972 T_sacch.start;
973 alt {
974 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
975 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
976 if (match(l3, l3_exp)) {
977 setverdict(pass);
978 } else {
979 repeat;
980 }
981 }
982 [] L1CTL.receive { repeat; }
983 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100985 }
986 }
987}
988
Harald Welte55700662018-03-12 13:15:43 +0100989/* verify that given SACCH payload is not present */
990private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
991 var L1ctlDlMessage dl;
992 /* check that the specified SI5 value is actually sent */
993 timer T_sacch := 3.0;
994 L1CTL.clear;
995 T_sacch.start;
996 alt {
997 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
998 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
999 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001001 } else {
1002 repeat;
1003 }
1004 }
1005 [] L1CTL.receive { repeat; }
1006 [] T_sacch.timeout {
1007 setverdict(pass);
1008 }
1009 }
1010}
1011
Harald Welte629cc6b2018-03-11 17:19:05 +01001012/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001013private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1014 /* Set a known default SACCH filling for SI5 */
1015 var octetstring si5 := f_rnd_octstring(19);
1016 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1017
1018 f_l1_tune(L1CTL);
1019 RSL.clear;
1020
1021 /* activate the logical channel */
1022 f_est_dchan();
1023
1024 /* check that the specified SI5 value is actually sent */
1025 f_sacch_present(si5);
1026
1027 /* release the channel */
1028 RSL.clear;
1029 f_rsl_chan_deact();
1030 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1031}
1032testcase TC_sacch_filling() runs on test_CT {
1033 var ConnHdlr vc_conn;
1034 var ConnHdlrPars pars;
1035 f_init();
1036 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1037 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1038 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1039 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1040 vc_conn.done;
1041 }
1042 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001044}
1045
Harald Welte629cc6b2018-03-11 17:19:05 +01001046/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001047private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1048 /* Set a known default SACCH filling for SI5 */
1049 var octetstring si5 := f_rnd_octstring(19);
1050 var octetstring si5_diff := f_rnd_octstring(19);
1051 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1052
1053 f_l1_tune(L1CTL);
1054 RSL.clear;
1055
1056 log("Activating channel, expecting standard SI5");
1057 /* activate the logical channel */
1058 f_est_dchan();
1059 /* check that the specified SI5 value is actually sent */
1060 f_sacch_present(si5);
1061
1062 /* set channel-specific different SI5 */
1063 log("Setting channel specific SACCH INFO, expecting it");
1064 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1065 /* check that the specified lchan-specific value is now used */
1066 f_sacch_present(si5_diff);
1067
1068 /* deactivate the channel and re-activate it, this should result in default SI5 */
1069 log("De-activating and re-activating channel, expecting standard SI5");
1070 f_rsl_chan_deact();
1071 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1072 /* Verify that the TRX-wide default SACCH filling is present again */
1073 f_sacch_present(si5);
1074
1075 /* release the channel */
1076 RSL.clear;
1077 f_rsl_chan_deact();
1078 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1079}
1080testcase TC_sacch_info_mod() runs on test_CT {
1081 var ConnHdlr vc_conn;
1082 var ConnHdlrPars pars;
1083 f_init();
1084 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1085 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1086 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1087 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1088 vc_conn.done;
1089 }
1090 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001091 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001092}
1093
Harald Welte075d84c2018-03-12 13:07:24 +01001094/* Test SACCH scheduling of multiple different SI message types */
1095private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1096 var octetstring si5 := f_rnd_octstring(19);
1097 var octetstring si5bis := f_rnd_octstring(19);
1098 var octetstring si5ter := f_rnd_octstring(19);
1099 var octetstring si6 := f_rnd_octstring(19);
1100
1101 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1102 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1103 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1104 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1105
1106 f_l1_tune(L1CTL);
1107 RSL.clear;
1108
1109 /* activate the logical channel */
1110 f_est_dchan();
1111 L1CTL.clear;
1112
1113 /* check that SACCH actually are received as expected */
1114 f_sacch_present(si5);
1115 f_sacch_present(si5bis);
1116 f_sacch_present(si5ter);
1117 f_sacch_present(si6);
1118
1119 /* release the channel */
1120 f_rsl_chan_deact();
1121 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1122}
1123testcase TC_sacch_multi() runs on test_CT {
1124 var ConnHdlr vc_conn;
1125 var ConnHdlrPars pars;
1126 f_init();
1127 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1128 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1129 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1130 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1131 vc_conn.done;
1132 }
1133 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001134 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001135}
1136
Harald Welte55700662018-03-12 13:15:43 +01001137/* Test if SACH information is modified as expected */
1138private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1139 var octetstring si5 := f_rnd_octstring(19);
1140 var octetstring si6 := f_rnd_octstring(19);
1141
1142 /* First, configure both SI5 and SI6 to be transmitted */
1143 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1144 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1145
1146 f_l1_tune(L1CTL);
1147 RSL.clear;
1148
1149 /* activate the logical channel */
1150 f_est_dchan();
1151 L1CTL.clear;
1152
1153 /* check that SACCH actually are received as expected */
1154 f_sacch_present(si5);
1155 f_sacch_present(si6);
1156
1157 /* disable SI6 */
1158 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1159
1160 /* check that SI5 is still transmitted */
1161 f_sacch_present(si5);
1162 /* check if SI6 is now gone */
1163 f_sacch_missing(si6);
1164
1165 /* release the channel */
1166 f_rsl_chan_deact();
1167 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1168}
1169testcase TC_sacch_multi_chg() runs on test_CT {
1170 var ConnHdlr vc_conn;
1171 var ConnHdlrPars pars;
1172 f_init();
1173 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1174 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1175 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1176 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1177 vc_conn.done;
1178 }
1179 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001181}
1182
Harald Weltec8d363c2019-05-19 20:36:48 +02001183/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1184private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1185 var octetstring si5 := f_rnd_octstring(19);
1186 var octetstring si6 := f_rnd_octstring(19);
1187 var octetstring si5_specific := f_rnd_octstring(19);
1188 var octetstring si6_specific := f_rnd_octstring(19);
1189
1190 /* First, configure both SI5 and SI6 to be transmitted */
1191 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1192 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1193
1194 f_l1_tune(L1CTL);
1195 RSL.clear;
1196
1197 /* activate channel with different SACCH filling */
1198 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1199 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1200 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1201 }));
1202 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1203 RSL_IE_Body:{sacch_info := sacch_info})) };
1204 f_est_dchan(more_ies := addl_ies);
1205
1206 /* check that SACCH actually are received as expected */
1207 f_sacch_present(si5_specific);
1208 f_sacch_present(si6_specific);
1209
1210 /* release the channel */
1211 f_rsl_chan_deact();
1212 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1213}
1214testcase TC_sacch_chan_act() runs on test_CT {
1215 var ConnHdlr vc_conn;
1216 var ConnHdlrPars pars;
1217 f_init();
1218
1219 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1220 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1221 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1222 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1223 vc_conn.done;
1224 }
1225 /* TODO: do the above in parallel, rather than sequentially? */
1226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1227}
1228
Harald Welte8b01c792019-05-19 22:51:25 +02001229/* verify that SACCH DL transmission is started only if MS power IE present
1230 * see section 4.1.3 of 3GPP TS 48.058 */
1231private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1232 var octetstring si5 := f_rnd_octstring(19);
1233
1234 f_l1_tune(L1CTL);
1235 RSL.clear;
1236
1237 /* Step 1: Activate ASYNC HO channel without MS power IE */
1238
1239 /* Activate channel on BTS side */
1240 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1241 /* don't perform immediate assignment here, as we're testing non-IA case */
1242 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001243 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001244
1245 /* Verify that no DL SACCH is being received */
1246 f_sacch_missing(?);
1247
1248 f_rsl_chan_deact();
1249 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1250
1251
1252 /* Step 2: Activate ASYNC HO channel with MS power IE */
1253
1254 /* Activate channel on BTS side */
1255 var RSL_IE_List addl_ies := {
1256 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1257 };
1258 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1259 /* don't perform immediate assignment here, as we're testing non-IA case */
1260 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001261 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001262
1263 /* Verify that DL SACCH is being received */
1264 f_sacch_present(si5);
1265
1266 f_rsl_chan_deact();
1267 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1268}
1269testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1270 var ConnHdlr vc_conn;
1271 var ConnHdlrPars pars;
1272 f_init();
1273
1274 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1275 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1276 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1277 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1278 vc_conn.done;
1279 }
1280 /* TODO: do the above in parallel, rather than sequentially? */
1281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1282}
1283
1284/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1285 * see section 4.1.4 of 3GPP TS 48.058 */
1286private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1287 var octetstring si5 := f_rnd_octstring(19);
1288 var RSL_IE_List addl_ies;
1289
1290 f_l1_tune(L1CTL);
1291 RSL.clear;
1292
1293 /* Step 1: Activate SYNC HO channel without MS power IE */
1294
1295 /* Activate channel on BTS side */
1296 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1297 /* don't perform immediate assignment here, as we're testing non-IA case */
1298 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001299 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001300
1301 /* Verify that no DL SACCH is being received */
1302 f_sacch_missing(?);
1303
1304 f_rsl_chan_deact();
1305 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1306
1307
1308 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1309
1310 /* Activate channel on BTS side */
1311 addl_ies := {
1312 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1313 };
1314 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1315 /* don't perform immediate assignment here, as we're testing non-IA case */
1316 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001317 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001318
1319 /* Verify that no DL SACCH is being received */
1320 f_sacch_missing(?);
1321
1322 f_rsl_chan_deact();
1323 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1324
1325
1326 /* Step 2b: Activate SYNC HO channel with TA IE */
1327
1328 /* Activate channel on BTS side */
1329 addl_ies := {
1330 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1331 };
1332 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1333 /* don't perform immediate assignment here, as we're testing non-IA case */
1334 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001335 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001336
1337 /* Verify that no DL SACCH is being received */
1338 f_sacch_missing(?);
1339
1340 f_rsl_chan_deact();
1341 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1342
1343
1344 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1345
1346 /* Activate channel on BTS side */
1347 addl_ies := {
1348 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1349 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1350 };
1351 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1352 /* don't perform immediate assignment here, as we're testing non-IA case */
1353 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001354 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001355
1356 /* Verify that DL SACCH is being received */
1357 f_sacch_present(si5);
1358
1359 f_rsl_chan_deact();
1360 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1361}
1362testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1363 var ConnHdlr vc_conn;
1364 var ConnHdlrPars pars;
1365 f_init();
1366
1367 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1368 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1369 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1370 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1371 vc_conn.done;
1372 }
1373 /* TODO: do the above in parallel, rather than sequentially? */
1374 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1375}
Harald Welte629cc6b2018-03-11 17:19:05 +01001376
1377
1378/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001379 * RACH Handling
1380 ***********************************************************************/
1381
Harald Welte8c24c2b2018-02-26 08:31:31 +01001382/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001383private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001384 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001385 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001386 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001387
Harald Welte8c24c2b2018-02-26 08:31:31 +01001388 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001389 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001390 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001391 var OCT1 ra := f_rnd_ra_emerg();
1392 if (emerg == true) {
1393 ra := f_rnd_ra_emerg();
1394 } else {
1395 ra := f_rnd_ra_cs();
1396 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001397 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1398 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001399 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001400 }
1401 fn_last := fn;
1402
1403 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001404 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001405 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001406 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001407 T.stop;
1408 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001409 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001411 }
1412 [] RSL_CCHAN.receive { repeat; }
1413 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001414 test_failed := true;
1415 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001416 }
1417 }
1418 }
Maxba06feb2019-03-05 10:52:46 +01001419 if (test_failed) {
1420 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001421 }
Maxba06feb2019-03-05 10:52:46 +01001422 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001424}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001425
Philipp Maier16ade782020-07-08 21:36:00 +02001426/* Normal variant */
1427testcase TC_rach_content() runs on test_CT {
1428 f_TC_rach_content(emerg := false);
1429}
1430
1431/* Emergency call variant */
1432testcase TC_rach_content_emerg() runs on test_CT {
1433 f_TC_rach_content(emerg := true);
1434}
1435
Harald Welte8c24c2b2018-02-26 08:31:31 +01001436/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1437testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001438 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001439 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001440 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001441 f_l1_tune(L1CTL);
1442
1443 var GsmFrameNumber fn_last := 0;
1444 for (var integer i := 0; i < 1000; i := i+1) {
1445 var OCT1 ra := f_rnd_ra_cs();
1446 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1447 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001449 }
1450 fn_last := fn;
1451 }
1452 var integer rsl_chrqd := 0;
1453 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001454 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001455 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001456 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001457 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001458 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001459 repeat;
1460 }
1461 [] RSL_CCHAN.receive { repeat; }
1462 [] T.timeout { }
1463 }
1464 if (rsl_chrqd == 1000) {
1465 setverdict(pass);
1466 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001468 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001470}
1471
Harald Welte3453ab42019-05-24 21:19:58 +02001472private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1473 var charstring bts_str := "bts " & int2str(bts_nr);
1474 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1475}
1476
1477/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1478private template integer tr_rach_slots_per_interval := (90 .. 130);
1479
1480/* Expect 0 RACH load on an idle BTS that has just started up */
1481testcase TC_rach_load_idle_thresh0() runs on test_CT {
1482 var ASP_RSL_Unitdata rx_ud;
1483
1484 f_init_vty_bsc();
1485 /* send load indications even at 0% load */
1486 f_vty_load_ind_thresh(0);
1487 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1488 f_sleep(2.0);
1489
1490 f_init();
1491
Harald Weltee37f9a52020-10-11 20:45:23 +02001492 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1493 alt {
1494 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1495 [] RSL_CCHAN.receive { repeat }
1496 }
1497
Harald Welte3453ab42019-05-24 21:19:58 +02001498 timer T := 5.0;
1499 T.start;
1500 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001501 [] 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 +02001502 setverdict(pass);
1503 repeat;
1504 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001505 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001506 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1507 repeat;
1508 }
1509 [] RSL_CCHAN.receive {
1510 repeat;
1511 }
1512 [] T.timeout { }
1513 }
1514
1515 f_vty_load_ind_thresh(10);
1516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1517}
1518
1519/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1520testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1521 var ASP_RSL_Unitdata rx_ud;
1522
1523 f_init_vty_bsc();
1524 f_init();
1525
1526 timer T := 5.0;
1527 T.start;
1528 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001529 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001530 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1531 repeat;
1532 }
1533 [] RSL_CCHAN.receive {
1534 repeat;
1535 }
1536 [] T.timeout {
1537 setverdict(pass);
1538 }
1539 }
1540
1541 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1542}
1543
1544/* Expect 0 RACH load on an idle BTS that has just started up */
1545testcase TC_rach_load_count() runs on test_CT {
1546 var ASP_RSL_Unitdata rx_ud;
1547 var integer load_access_count := 0;
1548
1549 f_init_vty_bsc();
1550 /* send load indications even at 0% load */
1551 f_vty_load_ind_thresh(0);
1552 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1553 f_sleep(2.0);
1554 f_init();
1555
1556 f_init_l1ctl();
1557 f_sleep(1.0);
1558 f_l1_tune(L1CTL);
1559
Harald Welte52ae1682020-10-11 20:45:55 +02001560 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1561 alt {
1562 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1563 [] RSL_CCHAN.receive { repeat }
1564 }
1565
Harald Welte3453ab42019-05-24 21:19:58 +02001566 var GsmFrameNumber fn_last := 0;
1567 for (var integer i := 0; i < 1000; i := i+1) {
1568 var OCT1 ra := f_rnd_ra_cs();
1569 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1570 if (fn == fn_last) {
1571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1572 }
1573 fn_last := fn;
1574 }
1575
1576 timer T := 5.0;
1577 T.start;
1578 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001579 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001580 -> value rx_ud {
1581 var RSL_IE_Body ie;
1582 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1583 load_access_count := load_access_count + ie.rach_load.access_count;
1584 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1585 setverdict(fail, "Access count cannot be < Busy count");
1586 }
1587 repeat;
1588 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001589 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001590 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1591 repeat;
1592 }
1593 [] RSL_CCHAN.receive {
1594 repeat;
1595 }
1596 [] T.timeout { }
1597 }
1598 if (load_access_count == 1000) {
1599 setverdict(pass);
1600 } else {
1601 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1602 }
1603
1604 f_vty_load_ind_thresh(10);
1605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1606}
1607
Harald Welte54a2a2d2018-02-26 09:14:05 +01001608private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001609 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001610 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001611 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001612 f_sleep(0.5);
1613
1614 /* Transmit RACH request + wait for confirmation */
1615 var OCT1 ra := f_rnd_ra_cs();
1616 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1617
1618 /* Check for expected result */
1619 timer T := 1.5;
1620 T.start;
1621 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001622 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001623 setverdict(pass);
1624 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001625 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001627 }
1628 [] RSL_CCHAN.receive { repeat; }
1629 [not expect_pass] T.timeout {
1630 setverdict(pass);
1631 }
1632 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001633 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001634 }
1635 }
1636}
1637
1638/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1639testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001640 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001641 f_init_l1ctl();
1642 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001643 f_sleep(1.0);
1644
1645 /* default max-ta is 63 (full range of GSM timing advance */
1646
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001647 /* We allow early arrival up to 2 symbols */
1648 f_rach_toffs(-1*256, true);
1649 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001650 f_rach_toffs(-10*256, false);
1651
1652 /* 0 / 32 / 63 bits is legal / permitted */
1653 f_rach_toffs(0, true);
1654 f_rach_toffs(32*256, true);
1655 f_rach_toffs(63*256, true);
1656
1657 /* more than 63 bits is not legal / permitted */
1658 f_rach_toffs(64*256, false);
1659 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001660 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001661}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001662
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001663private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001664 var GsmFrameNumber fn;
1665 var RSL_Message rm;
1666
1667 f_l1_tune(L1CTL);
1668 RSL.clear;
1669
1670 /* Generate a random Handover Reference */
1671 var integer ho_ref := oct2int(f_rnd_octstring(1));
1672
1673 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1674 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1675 RSL_IE_Body:{ handover_ref := ho_ref }));
1676
1677 /* Activate a channel on the BTS side (no encryption) */
1678 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1679 act_type := t_RSL_IE_ActType_HO_SYNC);
1680
1681 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1682 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001683 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001684
1685 /* Send handover Access Burst */
1686 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1687
1688 /* TODO: test mismatching Handover Reference, and missing IE */
1689
1690 /* Wait for handover detection */
1691 timer T := 3.0;
1692 T.start;
1693 alt {
1694 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1695 log("Handover RACH has been detected: ", rm);
1696 setverdict(pass);
1697 }
1698 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1700 log2str("RSL_CHAN_RQD was not expected: ", rm));
1701 }
1702 [] RSL.receive { repeat; }
1703 [] T.timeout {
1704 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1705 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1706 }
1707 }
1708
1709 /* Release the channel */
1710 f_rsl_chan_deact();
1711 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1712}
1713
1714/* Test handover RACH detection */
1715testcase TC_ho_rach() runs on test_CT {
1716 var ConnHdlrPars pars;
1717 var ConnHdlr vc_conn;
1718
1719 f_init();
1720
1721 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1722 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1723 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1724 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1725 vc_conn.done;
1726 }
1727
1728 /* TODO: do the above in parallel, rather than sequentially? */
1729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1730}
1731
Harald Welte93640c62018-02-25 16:59:33 +01001732/***********************************************************************
1733 * Measurement Processing / Reporting
1734 ***********************************************************************/
1735
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001736private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001737 spare := '0'B,
1738 lpd := 0,
1739 sapi := sapi,
1740 c_r := c_r,
1741 ea := true
1742}
1743
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001744private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001745 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001746 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001747 len := 0, /* overwritten */
1748 m := false,
1749 el := 1,
1750 payload := pl
1751}
1752
1753/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001754private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001755 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001756 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001757 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001758 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 +01001759 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001760 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001761
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001762 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1763 g_pars.l1_pars.ms_power_level, false,
1764 g_pars.l1_pars.ms_actual_ta);
1765
1766 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1767 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1768
1769 log("Sending Measurement Report: ", l1h, l2);
1770 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001771 repeat;
1772 }
1773}
1774
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001775private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001776 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001777 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001778 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1779 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001780 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1781 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001782 repeat;
1783 }
1784}
1785
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001786private altstep as_l1_tch_loop() runs on ConnHdlr {
1787 var L1ctlDlMessage l1_dl;
1788 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1789 log("TCH received: ", l1_dl.payload.traffic_ind.data);
1790 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1791 l1_dl.payload.traffic_ind.data));
1792 repeat;
1793 }
1794}
1795
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001796private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001797 uint6_t rxlev,
1798 uint3_t rxqual
1799}
1800
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001801private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001802 MeasElem full,
1803 MeasElem sub
1804}
1805
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001806private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001807 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001808 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001809 MeasElemFS meas_ul,
1810 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001811 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001812 uint5_t ms_power_level,
1813 uint8_t ms_actual_ta
1814}
1815
1816/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1817private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1818 return 63 + (toffs256s/256);
1819}
1820
Harald Welted5684392018-03-10 18:22:04 +01001821private function f_max(integer a, integer b) return integer {
1822 if (a > b) {
1823 return a;
1824 } else {
1825 return b;
1826 }
1827}
1828
1829private function f_min(integer a, integer b) return integer {
1830 if (a < b) {
1831 return a;
1832 } else {
1833 return b;
1834 }
1835}
1836
1837/* compute negative tolerance val-tolerance, ensure >= min */
1838private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1839 val := val - tolerance;
1840 return f_max(val, min);
1841}
1842
1843/* compute positive tolerance val+tolerance, ensure <= max */
1844private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1845 val := val + tolerance;
1846 return f_min(val, max);
1847}
1848
1849/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1850private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1851return template integer {
1852 var template integer ret;
1853 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1854 return ret;
1855}
1856
1857
Harald Welte70767382018-02-21 12:16:40 +01001858/* build a template for matching measurement results against */
1859private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1860 var ConnL1Pars l1p := g_pars.l1_pars;
1861 var template RSL_IE_UplinkMeas ul_meas := {
1862 len := 3,
1863 rfu := '0'B,
1864 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001865 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001866 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001867 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001868 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001869 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1870 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001871 supp_meas_info := omit
1872 };
Harald Welte685d5982018-02-27 20:42:05 +01001873 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001874 ul_meas.len := (3+8);
1875 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001876 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001877 toa256_min := ?,
1878 toa256_max := ?,
1879 toa256_std_dev := ?
1880 }
Harald Welte685d5982018-02-27 20:42:05 +01001881 }
Harald Welte70767382018-02-21 12:16:40 +01001882 var template RSL_IE_BS_Power bs_power := {
1883 reserved := 0,
1884 epc := false,
1885 fpc := false,
1886 power_level := l1p.bs_power_level
1887 };
1888 var template RSL_IE_L1Info l1_info := {
1889 ms_power_lvl := l1p.ms_power_level,
1890 fpc := false,
1891 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001892 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001893 };
1894 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001895 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001896 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1897 ?, t_toffs);
1898}
1899
Philipp Maierdd841d32019-12-17 14:44:54 +01001900/* build a template for matching measurement results that do not contain any
1901 * MS related measurement (l1_info, l3_info and ms timing offset). */
1902private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1903 var ConnL1Pars l1p := g_pars.l1_pars;
1904 var template RSL_IE_UplinkMeas ul_meas := {
1905 len := 3,
1906 rfu := '0'B,
1907 dtx_d := l1p.dtx_enabled,
1908 rxlev_f_u := ?,
1909 reserved1 := '00'B,
1910 rxlev_s_u := ?,
1911 reserved2 := '00'B,
1912 rxq_f_u := ?,
1913 rxq_s_u := ?,
1914 supp_meas_info := omit
1915 };
1916 if (l1p.toa256_enabled) {
1917 ul_meas.len := (3+8);
1918 ul_meas.supp_meas_info := {
1919 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1920 toa256_min := ?,
1921 toa256_max := ?,
1922 toa256_std_dev := ?
1923 }
1924 }
1925 var template RSL_IE_BS_Power bs_power := {
1926 reserved := 0,
1927 epc := false,
1928 fpc := false,
1929 power_level := l1p.bs_power_level
1930 };
1931
1932 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1933}
1934
Harald Welte70767382018-02-21 12:16:40 +01001935/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001936private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001937 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001938 var boolean chan_est := false;
1939
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001940 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001941
1942 /* Receive osmocom specific measurement reports. This is the normal
1943 * case. Here we verify that the measurement reports we sent are
1944 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001945 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1946 /* increment counter of next to-be-expected meas rep */
1947 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1948 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001949 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001950
1951 /* The following two cases may only happen in the beginning
1952 * of the channel establishment phase. Once we have received
1953 * the "our" measurement report the first time, the channel
1954 * is established and empty or hardcoded TRXCON reports must
1955 * not occur anymore. */
1956 chan_est := true;
1957
1958 repeat;
1959 }
1960
1961 /* When the BTS has established the channel, the MS might need slightly
1962 * more time to establish the channel and actually start sending. The
1963 * result is then a measurement report that just lacks the measurement
1964 * information of the MS. This is normal and we tolerate this behavior. */
1965 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1966 /* increment counter of next to-be-expected meas rep */
1967 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1968 /* Re-start the timer expecting the next MEAS RES */
1969 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001970 repeat;
1971 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001972
1973 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1974 * measurements if the TTCN3 side does not supply measurement input in
1975 * time. In those cases TRXCON will either use a cached measurement
1976 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1977 * report the templates above will not match. We tolerate this
1978 * behavior, but only once. */
1979 [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 +01001980 /* increment counter of next to-be-expected meas rep */
1981 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1982 if (g_first_meas_res) {
1983 g_first_meas_res := false;
1984 repeat;
1985 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001987 }
Harald Welte70767382018-02-21 12:16:40 +01001988 }
1989 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001991 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001992 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001994 }
1995}
1996
Harald Weltee613f962018-04-18 22:38:16 +02001997private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1998 select (rsl_alg_id) {
1999 case (RSL_ALG_ID_A5_0) { return 0; }
2000 case (RSL_ALG_ID_A5_1) { return 1; }
2001 case (RSL_ALG_ID_A5_2) { return 2; }
2002 case (RSL_ALG_ID_A5_3) { return 3; }
2003 case (RSL_ALG_ID_A5_4) { return 4; }
2004 case (RSL_ALG_ID_A5_5) { return 5; }
2005 case (RSL_ALG_ID_A5_6) { return 6; }
2006 case (RSL_ALG_ID_A5_7) { return 7; }
2007 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2009 /* Make compiler happy by calling mtc.stop here. It is already
2010 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002011 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002012 }
2013 }
2014}
2015
2016private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2017 select (rsl_alg_id) {
2018 case (RSL_ALG_ID_A5_1) { return '000'B; }
2019 case (RSL_ALG_ID_A5_2) { return '001'B; }
2020 case (RSL_ALG_ID_A5_3) { return '010'B; }
2021 case (RSL_ALG_ID_A5_4) { return '011'B; }
2022 case (RSL_ALG_ID_A5_5) { return '100'B; }
2023 case (RSL_ALG_ID_A5_6) { return '101'B; }
2024 case (RSL_ALG_ID_A5_7) { return '110'B; }
2025 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002026 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2027 /* Make compiler happy by calling mtc.stop here. It is already
2028 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002029 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002030 }
2031 }
2032}
2033
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002034/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2035private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2036 var GsmFrameNumber fn;
2037 timer T := 8.0;
2038
2039 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2040 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2041
2042 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2043 /* Send the actual RACH */
2044 fn := f_L1CTL_RACH(L1CTL, ra);
2045
2046 T.start;
2047 alt {
2048 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2049 [] T.timeout {
2050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2051 }
2052 }
2053 T.stop
2054 return fn;
2055}
Harald Weltee613f962018-04-18 22:38:16 +02002056
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002057/* Tune to a dedicated channel: L1CTL only */
2058private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002059 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002060 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2061 7 /* TODO: mp_tsc */,
2062 mp_trx0_arfcn));
2063 } else {
2064 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2065 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002066 pars.fhp.maio_hsn.hsn,
2067 pars.fhp.maio_hsn.maio,
2068 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002069 }
2070}
2071
Harald Welte70767382018-02-21 12:16:40 +01002072/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002073private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002074 var GsmFrameNumber fn;
2075 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002076 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002077 var integer ra := 23;
2078
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002079 /* Send RACH request and wait for ChanReq */
2080 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002081
2082 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002083 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002084
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002085 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002086 if (g_pars.fhp.enabled) {
2087 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002088 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002089 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002090 }
2091
Harald Welte70767382018-02-21 12:16:40 +01002092 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002093 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 +01002094 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2095
2096 /* receive IMM.ASS on MS side */
2097 var ImmediateAssignment ia_um;
2098 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002099
2100 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2101 if (ch_desc.h != ia_um.chan_desc.h) {
2102 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2103 }
2104
Harald Welte70767382018-02-21 12:16:40 +01002105 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002106 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002107 /* enable encryption, if requested */
2108 if (encr_enable) {
2109 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2110 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2111 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002112
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002113 /* Send TCH Mode Request to the L1 if needed */
2114 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2115 var L1ctlTchMode tch_mode;
2116
2117 select (g_pars.chan_mode.coding_alg_rate) {
2118 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2119 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2120 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2121 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2122 case else {
2123 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2124 " is not supported by the L1, falling back to signalling");
2125 tch_mode := L1CTL_CHAN_MODE_SIGN;
2126 }
2127 }
2128
2129 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2130 }
2131
Harald Weltefa45e9e2018-03-10 18:59:03 +01002132 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002133}
2134
2135/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002136private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002137 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002138 RSL.clear;
2139
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002140 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002141 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002142 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002143 }
Harald Welte70767382018-02-21 12:16:40 +01002144
2145 f_est_dchan();
2146
2147 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2148 * RSL measurement reports on Abis side */
2149 timer T := 8.0;
2150 T.start;
2151 alt {
2152 [] as_l1_sacch();
2153 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002154 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002155 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002156 [] L1CTL.receive { repeat; }
2157 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002158 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002159 * of any earlier errors, so if we reach this timeout, we're good */
2160 setverdict(pass);
2161 }
2162 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002163 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002164 }
2165 }
2166 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002167 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002168}
Harald Welte0472ab42018-03-12 15:02:26 +01002169
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002170/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2171private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002172 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002173 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2174 timer Tup := 10.0;
2175 Tup.start;
2176 alt {
2177 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2178 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2179 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002180
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002181 if (rx_lvl != max_rx_lvl) {
2182 repeat;
2183 }
2184 Tup.stop;
2185 }
2186 [] L1CTL.receive { repeat; }
2187 [] Tup.timeout {
2188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2189 log2str("Didn't reach full power ", max_rx_lvl));
2190 }
2191 }
2192 return max_rx_lvl;
2193}
2194
2195/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2196private function f_verify_ramp_up() runs on ConnHdlr {
2197 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002198 var integer initial_rx_lvl := -1;
2199 var integer last_rx_lvl := -1;
2200 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2201
2202 timer T := 2.0;
2203 alt {
2204 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2205 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2206 log("Received rx_level=", rx_lvl);
2207 if (initial_rx_lvl == -1) {
2208 initial_rx_lvl := rx_lvl;
2209 last_rx_lvl := rx_lvl;
2210
2211 /* Expect a somehow low value during first received messages */
2212 if (initial_rx_lvl >= max_rx_lvl / 2) {
2213 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2214 log2str("Detected high initial tx power during ramp up: ",
2215 initial_rx_lvl , ", full power is", max_rx_lvl));
2216 }
2217 }
2218
2219 /* received Rx level bigger than maximum allowed power by CN */
2220 if (rx_lvl > max_rx_lvl) {
2221 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2222 log2str("Detected Tx power higher than full power: ",
2223 rx_lvl , " > ", max_rx_lvl));
2224 }
2225
2226 /* Make sure it never decreases, since we are rumping up */
2227 if (last_rx_lvl > rx_lvl) {
2228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2229 log2str("Detected Tx power decrease during ramp up: ",
2230 last_rx_lvl , " -> ", rx_lvl));
2231 }
2232
2233 if (rx_lvl == max_rx_lvl and not T.running) {
2234 /* We reached the maximum power, start timer and receive
2235 /* a few more to make sure we don't surpass it */
2236 log("Reached full power, wating a bit more until success");
2237 T.start;
2238 }
2239
2240 last_rx_lvl := rx_lvl;
2241 repeat;
2242 }
2243 [] L1CTL.receive { repeat; }
2244 [] T.timeout { }
2245 }
2246
2247 /* We didn't increase tx power during ramp up */
2248 if (initial_rx_lvl < last_rx_lvl) {
2249 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2250 } else {
2251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2252 log2str("No Tx power increase during whole ramp up: ",
2253 initial_rx_lvl , " -> ", last_rx_lvl));
2254 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002255}
2256
2257/* verify BTS ramps power down to rx_level 0 */
2258private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2259 var L1ctlDlMessage l1_dl;
2260 var integer last_rx_lvl := max_rx_lvl;
2261
2262 timer Tdown := 5.0;
2263 Tdown.start;
2264 alt {
2265 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2266 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2267 log("Received rx_level=", rx_lvl);
2268
2269 /* received Rx level bigger than maximum allowed power by CN */
2270 if (rx_lvl > max_rx_lvl) {
2271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2272 log2str("Detected Tx power higher than full power: ",
2273 rx_lvl , " > ", max_rx_lvl));
2274 }
2275
2276 /* Make sure it never increases, since we are rumping down */
2277 if (last_rx_lvl < rx_lvl) {
2278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2279 log2str("Detected Tx power increase during ramp up: ",
2280 last_rx_lvl , " -> ", rx_lvl));
2281 }
2282
2283 last_rx_lvl := rx_lvl;
2284 if (last_rx_lvl != 0) {
2285 repeat;
2286 }
2287 /* we reached power level 0, we are done */
2288 Tdown.stop;
2289 }
2290 [] L1CTL.receive { repeat; }
2291 [] Tdown.timeout { }
2292 }
2293
2294 /* We didn't increase tx power during ramp down */
2295 if (max_rx_lvl > last_rx_lvl) {
2296 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2297 } else {
2298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2299 log2str("No Tx power decrease during whole ramp down: ",
2300 max_rx_lvl , " -> ", last_rx_lvl));
2301 }
2302}
2303
2304/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002305private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002306 f_l1_tune(L1CTL);
2307 RSL.clear;
2308
2309 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002310
2311 setverdict(pass);
2312}
2313testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2314 var ConnHdlr vc_conn;
2315 var ConnHdlrPars pars;
2316 f_init();
2317 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2318 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2319 pcu_comp := false, trxc_comp := true);
2320 vc_conn.done;
2321 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2322}
2323
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002324/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002325private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002326 f_connhdlr_init_vty_bsc();
2327
2328 f_l1_tune(L1CTL);
2329 RSL.clear;
2330
2331 /* Wait until BTS is started and at full power */
2332 var integer max_rx_lvl := f_wait_ramp_up();
2333 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2334
2335 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2336 f_verify_ramp_down(max_rx_lvl);
2337
2338 setverdict(pass);
2339}
2340testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2341 var ConnHdlr vc_conn;
2342 var ConnHdlrPars pars;
2343 f_init();
2344 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2345 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2346 pcu_comp := false, trxc_comp := true);
2347 vc_conn.done;
2348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2349}
2350
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002351/* Verify Tx power:
2352 * + ramping down during ADM state UNLOCKED->LOCKED
2353 * + ramping up during ADM state LOCKED->UNLOCKED
2354 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002355private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002356 var L1ctlDlMessage l1_dl;
2357 var integer last_rx_lvl;
2358
2359 f_connhdlr_init_vty_bsc();
2360
2361 f_l1_tune(L1CTL);
2362 RSL.clear;
2363
2364 /* Wait until BTS is started and at full power */
2365 var integer max_rx_lvl := f_wait_ramp_up();
2366 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2367
2368 log("ADM STATE UNLOCKED->LOCKED");
2369 f_vty_enter_cfg_trx(BSCVTY);
2370 f_vty_transceive(BSCVTY, "rf_locked 1");
2371 last_rx_lvl := max_rx_lvl;
2372 f_verify_ramp_down(max_rx_lvl);
2373
2374 /* Let some time after we received 0dBm, then check we don't receive BCCH
2375 * anymore because scheduler has stopped after ramping down */
2376 f_sleep(2.0);
2377 L1CTL.clear;
2378 timer Tlocked := 2.0;
2379 Tlocked.start;
2380 alt {
2381 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2382 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2383 log2str("Received data_ind during rf_locked: ", l1_dl));
2384 }
2385 [] L1CTL.receive { repeat; }
2386 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2387 }
2388
2389 log("ADM STATE LOCKED->UNLOCKED");
2390 f_vty_transceive(BSCVTY, "rf_locked 0");
2391 f_verify_ramp_up();
2392 setverdict(pass);
2393}
2394testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2395 var ConnHdlr vc_conn;
2396 var ConnHdlrPars pars;
2397 f_init();
2398 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2399 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2400 pcu_comp := false, trxc_comp := true);
2401 vc_conn.done;
2402 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2403}
2404
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002405private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002406 timer T := 8.0;
2407 T.start;
2408 var RSL_Message rsl;
2409 alt {
2410 [] as_l1_sacch();
2411 [] L1CTL.receive { repeat; }
2412 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2413 if (rsl.ies[3].body.bs_power.power_level == level) {
2414 setverdict(pass)
2415 } else {
2416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2417 }
2418 }
2419 [] T.timeout {
2420 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2421 }
2422 }
2423}
2424
2425/* see if the rsl meas res contains our expeced bs power level
2426bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002427private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002428 f_l1_tune(L1CTL);
2429 RSL.clear;
2430
2431 if (mp_bts_trxc_port != -1) {
2432 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2433 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2434 }
2435
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002436 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002437 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2438 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2439
2440 f_est_dchan(more_ies :={valueof(pwr)});
2441
2442 f_check_meas_bs_power_level(pwr_var);
2443
2444 f_rsl_chan_deact();
2445 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2446}
2447
2448/* see if the rsl meas res contains our expeced bs power level
2449bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002450private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002451 f_l1_tune(L1CTL);
2452 RSL.clear;
2453
2454 if (mp_bts_trxc_port != -1) {
2455 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2456 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2457 }
2458
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002459 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002460 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2461
2462 f_est_dchan();
2463
2464 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2465
2466 f_check_meas_bs_power_level(pwr_var);
2467
2468 f_rsl_chan_deact();
2469 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2470}
2471
2472testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2473 var ConnHdlr vc_conn;
2474 var ConnHdlrPars pars;
2475 f_init();
2476 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2477 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2478 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2479 pcu_comp := false, trxc_comp := true);
2480 vc_conn.done;
2481 }
2482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2483}
2484
2485testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2486 var ConnHdlr vc_conn;
2487 var ConnHdlrPars pars;
2488 f_init();
2489 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2490 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2491 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2492 pcu_comp := false, trxc_comp := true);
2493 vc_conn.done;
2494 }
2495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2496}
2497
Eric Wild61edb7e2019-06-03 12:38:31 +02002498/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2499second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2500These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002501private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002502 var uint5_t pwr_var := 7;
2503 var L1ctlDlMessage l1_dl;
2504
2505 f_trxc_fake_rssi(rxlev2dbm(10));
2506 f_l1_tune(L1CTL);
2507 RSL.clear;
2508
2509 var RSL_IE_List addl_ies;
2510 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2511
2512 addl_ies := {
2513 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2514 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2515 };
2516
2517 /* establish with power parameters */
2518 f_est_dchan(more_ies := addl_ies);
2519
2520 /* set a high value to ensure L1 power control level increases */
2521 f_trxc_fake_rssi(rxlev2dbm(20));
2522
2523 timer T2 := 6.0;
2524 T2.start;
2525 alt {
2526 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002527 /* Update sent MS power to follow what BTS requests */
2528 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2529 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002530 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002531 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002532 T2.stop;
2533 }
2534 [] L1CTL.receive { repeat; }
2535 [] T2.timeout {
2536 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2537 "Power Level in L1 header has not increased sufficiently");
2538 }
2539 }
2540
2541 /* set a low value to ensure L1 power control level decreases */
2542 f_trxc_fake_rssi(rxlev2dbm(0));
2543
2544 timer T4 := 6.0;
2545 T4.start;
2546 alt {
2547 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002548 /* Update sent MS power to follow what BTS requests */
2549 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2550 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002551 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002552 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002553 T4.stop;
2554 setverdict(pass, "Power level in L1 decreased/increased as expected");
2555 }
2556 [] L1CTL.receive { repeat; }
2557 [] T4.timeout {
2558 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2559 "Power Level in L1 header has not decreased sufficiently");
2560 }
2561 }
2562
2563 f_rsl_chan_deact();
2564 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2565
2566}
2567
2568/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002569private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002570 var uint5_t pwr_var := 7;
2571 var L1ctlDlMessage l1_dl;
2572
2573 /* set a low value to ensure power increases */
2574 f_trxc_fake_rssi(rxlev2dbm(10));
2575 f_l1_tune(L1CTL);
2576 RSL.clear;
2577
2578 var RSL_IE_List addl_ies;
2579 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2580
2581 addl_ies := {
2582 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2583 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2584 };
2585
2586 /* establish with power parameters */
2587 f_est_dchan(more_ies := addl_ies);
2588
2589 timer T1 := 10.0;
2590 T1.start;
2591 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002592 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2593 /* Update sent MS power to follow what BTS requests */
2594 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2595 repeat;
2596 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002597 [] L1CTL.receive { repeat; }
2598 [] T1.timeout {
2599 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2600 setverdict(fail, "Power level in L1 header should not have changed");
2601 }
2602 }
2603 }
2604
2605 f_rsl_chan_deact();
2606 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2607
2608}
2609
2610/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002611private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002612 var L1ctlDlMessage l1_dl;
2613 var uint5_t pwr_var := 15;
2614 var uint5_t pwr_max_var := f_get_max_power_from_band();
2615
2616 /* set a low value to ensure power increases */
2617 f_trxc_fake_rssi(rxlev2dbm(10));
2618 f_l1_tune(L1CTL);
2619 RSL.clear;
2620
2621 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2622 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2623
2624 /* establish with fixed power level */
2625 f_est_dchan(more_ies :={valueof(pwr)});
2626
2627 /* check our initial power level */
2628 f_wait_for_l1_power_level(pwr_var);
2629
2630 /* update power param to enable power loop
2631 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2632 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2633
2634 /* wait, then check that our power level was reduced */
2635 timer T1 := 10.0;
2636 T1.start;
2637 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002638 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2639 /* Update sent MS power to follow what BTS requests */
2640 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2641 repeat;
2642 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002643 [] L1CTL.receive { repeat; }
2644 [] T1.timeout {
2645 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2646 if( f_power_level_is_highest_dbm(rcv) ){
2647 setverdict(pass, "Power level in L1 header reduced as expected");
2648 } else {
2649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2650 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2651 }
2652 }
2653 }
2654
2655 f_rsl_chan_deact();
2656 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2657
2658}
2659
2660/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002661private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002662 var L1ctlDlMessage l1_dl;
2663
2664 /* set a high value to ensure power decreases */
2665 f_trxc_fake_rssi(rxlev2dbm(50));
2666 f_l1_tune(L1CTL);
2667 RSL.clear;
2668
2669 var uint5_t pwr_var := 5;
2670 var uint5_t pwr_target_val := 15;
2671
2672 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2673 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2674
2675 /* establish with fixed power level */
2676 f_est_dchan(more_ies :={valueof(pwr)});
2677
2678 /* check our initial power level */
2679 f_wait_for_l1_power_level(pwr_var);
2680
2681 /* update power param to enable power loop
2682 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002683 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002684
2685 /* wait, then check that our power level was increased */
2686 timer T1 := 10.0;
2687 T1.start;
2688 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002689 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2690 /* Update sent MS power to follow what BTS requests */
2691 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2692 repeat;
2693 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002694 [] L1CTL.receive { repeat; }
2695 [] T1.timeout {
2696 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2697 setverdict(pass, "Power level in L1 header increased to lowest power value");
2698 } else {
2699 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2700 "Power level in L1 header NOT increased to lowest power value");
2701 }
2702 }
2703 }
2704
2705 f_rsl_chan_deact();
2706 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2707
2708}
2709
Eric Wild095024b2019-06-17 15:08:57 +02002710/* see if we change the power level without receiving power parameters, which should not happen
2711rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002712private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002713 var L1ctlDlMessage l1_dl;
2714
2715 /* set a high value to ensure power decreases */
2716 f_trxc_fake_rssi(rxlev2dbm(50));
2717 f_l1_tune(L1CTL);
2718 RSL.clear;
2719
2720 var uint5_t pwr_var := 5;
2721
2722 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2723 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2724
2725 /* establish with fixed power level */
2726 f_est_dchan(more_ies :={valueof(pwr)});
2727
2728 /* check our initial power level */
2729 f_wait_for_l1_power_level(pwr_var);
2730
2731 /* wait, then check that our power level did not change */
2732 timer T1 := 10.0;
2733 T1.start;
2734 alt {
2735 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2736 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2737 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2738 "BS power control should not be active unless we receive a power parameters IE!");
2739 }
2740 repeat;
2741 }
2742 [] L1CTL.receive { repeat; }
2743 [] T1.timeout { setverdict(pass); }
2744 }
2745
2746 f_rsl_chan_deact();
2747 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2748
2749}
2750
Eric Wild095024b2019-06-17 15:08:57 +02002751/* see if we change the power level without receiving power parameters, which should not happen
2752ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002753private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002754 var L1ctlDlMessage l1_dl;
2755
2756 /* set a high value to ensure power decreases */
2757 f_trxc_fake_rssi(rxlev2dbm(50));
2758 f_l1_tune(L1CTL);
2759 RSL.clear;
2760
2761 var uint5_t pwr_var := 5;
2762
2763 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2764 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2765
2766 /* establish with fixed power level */
2767 f_est_dchan(more_ies :={valueof(pwr)});
2768
2769 /* check our initial power level */
2770 f_wait_for_l1_power_level(pwr_var);
2771
2772 /* pwr control without power params IE, should NOT activate MS power control*/
2773 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2774
2775 /* wait, then check that our power level did not change */
2776 timer T1 := 10.0;
2777 T1.start;
2778 alt {
2779 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2780 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2782 "BS power control should not be active unless we receive a power parameters IE!");
2783 }
2784 repeat;
2785 }
2786 [] L1CTL.receive { repeat; }
2787 [] T1.timeout { setverdict(pass); }
2788 }
2789
2790 f_rsl_chan_deact();
2791 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2792
2793}
2794
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002795private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002796 var L1ctlDlMessage l1_dl;
2797 timer T0 := 10.0;
2798 T0.start;
2799 alt {
2800 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2801 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2802 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2803 "Power level in L1 header != signaled (RSL) power level.");
2804 }
2805 }
2806 [] L1CTL.receive { repeat; }
2807 [] T0.timeout {
2808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2809 "Timeout waiting for initial power level");
2810 }
2811 }
2812 T0.stop;
2813}
2814
2815private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2816 var IntegerRecord min_dbm_level;
2817 var IntegerRecord max_dbm_level;
2818 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2819
2820 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2821 if (min_dbm_level[i] == level) {
2822 return true;
2823 }
2824 }
2825 return false;
2826}
2827
2828private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2829 var IntegerRecord min_dbm_level;
2830 var IntegerRecord max_dbm_level;
2831 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2832
2833 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2834 if (max_dbm_level[i] == level) {
2835 return true;
2836 }
2837 }
2838 return false;
2839}
2840
2841private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2842 var IntegerRecord min_dbm_level;
2843 var IntegerRecord max_dbm_level;
2844 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2845 return max_dbm_level[0];
2846}
2847
2848type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002849private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002850private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2851 // 45.005 4.1.1
2852 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2853 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2854 2, 1, 0};
2855 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2856 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2857 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2858 var IntegerRecord rv;
2859
2860 select(band){
2861 case (BtsBand_allGSM){
2862 rv := gsm_power;
2863 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2864 max_dbm_level := {2, 1, 0};
2865 }
2866 case("DCS1800"){
2867 rv := dcs_power;
2868 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2869 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2870 }
2871 case("PCS1900"){
2872 rv := pcs_power;
2873 min_dbm_level := {15};
2874 max_dbm_level := {30};
2875 }
Harald Welte194b6912020-10-11 21:01:55 +02002876 case else {
2877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2878 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002879 }
2880
2881 return rv;
2882}
2883
2884private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002885 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 +02002886}
2887
2888testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2889 var ConnHdlr vc_conn;
2890 var ConnHdlrPars pars;
2891 f_init();
2892 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2893 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2894 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2895 pars.bts0_band := f_vty_get_bts0_band();
2896 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2897 vc_conn.done;
2898 }
2899 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2901}
2902
2903testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2904 var ConnHdlr vc_conn;
2905 var ConnHdlrPars pars;
2906 f_init();
2907 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2908 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2909 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2910 pars.bts0_band := f_vty_get_bts0_band();
2911 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2912 vc_conn.done;
2913 }
2914 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2916}
2917
2918testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2919 var ConnHdlr vc_conn;
2920 var ConnHdlrPars pars;
2921 f_init();
2922 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2923 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2924 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2925 pars.bts0_band := f_vty_get_bts0_band();
2926 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2927 vc_conn.done;
2928 }
2929 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2930 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2931}
2932
2933testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2934 var ConnHdlr vc_conn;
2935 var ConnHdlrPars pars;
2936 f_init();
2937 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2938 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2939 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2940 pars.bts0_band := f_vty_get_bts0_band();
2941 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2942 vc_conn.done;
2943 }
2944 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2945 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2946}
2947
Eric Wild280ccb82019-06-17 11:11:52 +02002948testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2949 var ConnHdlr vc_conn;
2950 var ConnHdlrPars pars;
2951 f_init();
2952 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2953 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2954 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2955 pars.bts0_band := f_vty_get_bts0_band();
2956 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2957 vc_conn.done;
2958 }
2959 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2961}
2962
Eric Wild095024b2019-06-17 15:08:57 +02002963testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2964 var ConnHdlr vc_conn;
2965 var ConnHdlrPars pars;
2966 f_init();
2967 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2968 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2969 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2970 pars.bts0_band := f_vty_get_bts0_band();
2971 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2972 vc_conn.done;
2973 }
2974 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2976}
2977
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07002978testcase TC_meas_res_speech_tchf() runs on test_CT {
2979 var template RSL_IE_ChannelMode ch_mode;
2980 var ConnHdlr vc_conn;
2981 var ConnHdlrPars pars;
2982 f_init();
2983 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
2984 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
2985 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
2986 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2987 pcu_comp := false, trxc_comp := true);
2988 vc_conn.done;
2989 }
2990 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2991}
2992testcase TC_meas_res_speech_tchh() runs on test_CT {
2993 var template RSL_IE_ChannelMode ch_mode;
2994 var ConnHdlr vc_conn;
2995 var ConnHdlrPars pars;
2996 f_init();
2997 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
2998 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
2999 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3000 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3001 pcu_comp := false, trxc_comp := true);
3002 vc_conn.done;
3003 }
3004 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3005}
3006
Harald Welte70767382018-02-21 12:16:40 +01003007testcase TC_meas_res_sign_tchf() runs on test_CT {
3008 var ConnHdlr vc_conn;
3009 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003010 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003011 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3012 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003013 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3014 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003015 vc_conn.done;
3016 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003017 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003018}
3019testcase TC_meas_res_sign_tchh() runs on test_CT {
3020 var ConnHdlr vc_conn;
3021 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003022 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003023 for (var integer ss := 0; ss <= 1; ss := ss+1) {
3024 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003025 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3026 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003027 vc_conn.done;
3028 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003030}
3031testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3032 var ConnHdlr vc_conn;
3033 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003034 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003035 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3036 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003037 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3038 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003039 vc_conn.done;
3040 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003041 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003042}
3043testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3044 var ConnHdlr vc_conn;
3045 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003046 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003047 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3048 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003049 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3050 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003051 vc_conn.done;
3052 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003053 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003054}
Harald Welte685d5982018-02-27 20:42:05 +01003055testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3056 var ConnHdlr vc_conn;
3057 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003058 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003059 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3060 for (var integer ss := 0; ss <= 1; ss := ss+1) {
3061 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
3062 pars.l1_pars.toa256_enabled := true;
3063 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
3064 vc_conn.done;
3065 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003066 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003067}
3068
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003069/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3070 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003071private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003072 var L1ctlDlMessage l1_dl;
3073 var RSL_IE_MS_Power ms_power;
3074 var RSL_Message rsl;
3075 var uint5_t power_level := 0;
3076
3077 f_l1_tune(L1CTL);
3078 RSL.clear;
3079
3080 f_est_dchan();
3081
3082 ms_power.reserved := 0;
3083 ms_power.fpc_epc := false;
3084
3085 /* Send the first power control command. This will disable any BTS/TRX
3086 * internal power control and switch the MS (which is not in scope of
3087 * this test) to a constant power level. We start with a power level
3088 * of 0 */
3089 ms_power.power_level := power_level;
3090 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3091 RSL.send(rsl);
3092
3093 alt {
3094
3095 /* Pick all SACCH blocks for checking */
3096 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3097
3098 /* The first byte of the L1 header contains the power level.
3099 * The reserved bits and the fpc bit is set to 0, so we may
3100 * compare directly. */
3101 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3102 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3103 }
3104
3105 /* Signal a new power level via RSL for the next turn. */
3106 if (power_level < 31) {
3107 power_level := power_level + 1;
3108 ms_power.power_level := power_level;
3109 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3110 RSL.send(rsl);
3111 repeat;
3112 }
3113
3114 }
3115
3116 /* Ignore all other blocks */
3117 [] L1CTL.receive { repeat; }
3118
3119 }
3120
3121 f_rsl_chan_deact();
3122 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3123
3124 setverdict(pass);
3125}
3126
3127testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3128 var ConnHdlr vc_conn;
3129 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003130 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003131
3132 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3133 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3134 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3135 vc_conn.done;
3136 }
3137 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3138}
Harald Welte70767382018-02-21 12:16:40 +01003139
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003140/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003141TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003142private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003143 var L1ctlDlMessage l1_dl;
3144 var uint5_t ta_to_test := 16;
3145
3146
3147 f_l1_tune(L1CTL);
3148 RSL.clear;
3149
3150 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003151 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003152
3153 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3154
3155
3156 alt {
3157
3158 /* Pick all SACCH blocks for checking */
3159 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3160
3161 /* The second byte of the L1 header contains the TA. */
3162 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3163 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3164 }
3165
3166 }
3167
3168 /* Ignore all other blocks */
3169 [] L1CTL.receive { repeat; }
3170
3171 }
3172
3173 f_rsl_chan_deact();
3174 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3175
3176 setverdict(pass);
3177}
3178
3179testcase TC_rsl_chan_initial_ta() runs on test_CT {
3180 var ConnHdlr vc_conn;
3181 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003182 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003183 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003184 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3185 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003186 vc_conn.done;
3187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3188}
3189
Eric Wilde57e1a62019-05-28 13:30:55 +02003190/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003191private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003192 var L1ctlDlMessage l1_dl;
3193 var uint5_t ms_power_level := 7;
3194
3195 var RSL_IE_MS_Power ms_power;
3196 ms_power.reserved := 0;
3197 ms_power.fpc_epc := false;
3198 ms_power.power_level := ms_power_level;
3199
3200 f_l1_tune(L1CTL);
3201 RSL.clear;
3202
3203 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3204
3205 timer T := 1.0;
3206 T.start;
3207 alt {
3208 /* Pick all SACCH blocks for checking */
3209 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3210 /* The first byte of the L1 header contains the power level.. */
3211 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3212 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3213 }
3214 }
3215 /* Ignore all other blocks */
3216 [] L1CTL.receive { repeat; }
3217 [] T.timeout {
3218 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3219 }
3220 }
3221
3222 f_rsl_chan_deact();
3223 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3224 setverdict(pass);
3225}
3226
3227testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3228 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3229 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3230}
3231
Harald Welte0472ab42018-03-12 15:02:26 +01003232/* 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 +01003233private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003234 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003235 RSL.clear;
3236
3237 f_est_dchan();
3238 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003239 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003240
3241 timer T := 40.0;
3242 T.start;
3243 alt {
3244 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3245 setverdict(pass)
3246 }
3247 [] RSL.receive { repeat };
3248 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003250 }
3251 }
3252 f_rsl_chan_deact();
3253}
3254testcase TC_conn_fail_crit() runs on test_CT {
3255 var ConnHdlr vc_conn;
3256 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003257 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003258 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3259 pars.t_guard := 60.0;
3260 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3261 vc_conn.done;
3262}
3263
Harald Welte93640c62018-02-25 16:59:33 +01003264/***********************************************************************
3265 * Paging
3266 ***********************************************************************/
3267
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003268private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003269 if (tmsi == 'FFFFFFFF'O) {
3270 return true;
3271 } else {
3272 return false;
3273 }
3274}
Harald Welte70767382018-02-21 12:16:40 +01003275
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003276private type record allowedFn { integer frame_nr }
3277private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3278private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3279private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3280private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3281private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3282private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3283private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3284private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3285private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003286{
3287 var integer frame_nr_51;
3288 frame_nr_51 := frame_nr mod 51
3289
3290 var allowedFn fn_check;
3291 fn_check.frame_nr := frame_nr_51;
3292
3293 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003294 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003295 return;
3296 }
3297
3298 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3299 return;
3300 }
3301 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3302 return;
3303 }
3304 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3305 return;
3306 }
3307 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3308 return;
3309 }
3310 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3311 return;
3312 }
3313 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3314 return;
3315 }
3316 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3317 return;
3318 }
3319 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3320 return;
3321 }
3322
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003323 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003324 return;
3325}
3326
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003327private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3328 inout integer num_paging_rcv_ids,
3329 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003330runs on test_CT {
3331 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003332 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003333 repeat;
3334 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003335 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003336 var octetstring without_plen :=
3337 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3338 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003339
3340 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3341
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003342 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3343 /* Ignore empty RR Paging Request (PCH filling) messages.
3344 * TODO: does it make sense to count them? */
3345 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003346 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3347 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003348 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003349 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3350 }
3351 } else if (match(rr, tr_PAGING_REQ2)) {
3352 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3353 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3354 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3355 }
3356 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3357 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3358 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003359 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003360 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3361 }
3362 } else if (match(rr, tr_PAGING_REQ3)) {
3363 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3364 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3365 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3366 }
3367 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3368 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3369 }
3370 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3371 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3372 }
3373 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3374 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3375 }
3376 }
3377 repeat;
3378 }
3379}
3380
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003381private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003382 boolean combined_ccch,
3383 integer bs_ag_blks_res,
3384 float load_factor,
3385 boolean exp_load_ind,
3386 boolean exp_overload,
3387 boolean use_tmsi
3388}
3389
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003390private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003391 integer num_paging_sent,
3392 integer num_paging_rcv_msgs,
3393 integer num_paging_rcv_ids,
3394 integer num_overload
3395}
3396
Harald Welte68e495b2018-02-25 00:05:57 +01003397/* Helper function for paging related testing */
3398private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003399 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003400 f_init_l1ctl();
3401 f_l1_tune(L1CTL);
3402
3403 var PagingTestState st := {
3404 num_paging_sent := 0,
3405 num_paging_rcv_msgs := 0,
3406 num_paging_rcv_ids := 0,
3407 num_overload := 0
3408 };
3409
3410 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3411 var float max_pch_imsi_per_sec;
3412 if (cfg.use_tmsi) {
3413 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3414 } else {
3415 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3416 }
3417 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3418 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003419 var float time_total := 20.0;
3420 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3421 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003422
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003423 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3424 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003425
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003426 timer T_itv := 0.0;
3427 T_itv.start;
3428 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003429 alt {
3430 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003431 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003432 st.num_overload := st.num_overload + 1;
3433 repeat;
3434 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003435 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003437 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003438 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003439 log("Rx LOAD_IND");
3440 /* FIXME: analyze/verify interval + contents */
3441 repeat;
3442 }
3443 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003444 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003445 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003446 [] T_itv.timeout {
3447 /* Send paging cmds based on elapsed time */
3448 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3449 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003450 var MobileIdentityV mi;
3451
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003452 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003453 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003454 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003455 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003456 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003457 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003458
3459 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003460 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 +02003461
3462 st.num_paging_sent := st.num_paging_sent + 1;
3463 }
3464 if (st.num_paging_sent < pkt_total) {
3465 /* Wait for interval to next PAGING COMMAND */
3466 var float time_now := T_total.read;
3467 var float next_sched := int2float(st.num_paging_sent)*interval;
3468 if (next_sched > time_now) {
3469 T_itv.start(next_sched - time_now);
3470 } else {
3471 T_itv.start(0.0);
3472 }
3473 } else {
3474 /* We are done, no need to keep counting */
3475 T_total.stop;
3476 }
3477 }
3478 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003479 }
3480 }
3481
3482 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3483 timer T_wait := 18.0;
3484 T_wait.start;
3485 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003486 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003487 [] L1CTL.receive { repeat; }
3488 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003489 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3490 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003491 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003493 }
Harald Welte68e495b2018-02-25 00:05:57 +01003494 }
3495
3496 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3497 " rcvd_ids=", st.num_paging_rcv_ids);
3498 return st;
3499}
3500
3501/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3502 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3503 * - that CCCH LOAD IND (PCH) are being generated
3504 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3505testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003506 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003507 var PagingTestCfg cfg := {
3508 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003509 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003510 load_factor := 0.8,
3511 exp_load_ind := true,
3512 exp_overload := false,
3513 use_tmsi := false
3514 };
3515 var PagingTestState st := f_TC_paging(cfg);
3516 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3518 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003519 } else {
3520 setverdict(pass);
3521 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003523}
3524
3525/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3526 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3527 * - that CCCH LOAD IND (PCH) are being generated
3528 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3529testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003530 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003531 var PagingTestCfg cfg := {
3532 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003533 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003534 load_factor := 0.8,
3535 exp_load_ind := true,
3536 exp_overload := false,
3537 use_tmsi := true
3538 };
3539 var PagingTestState st := f_TC_paging(cfg);
3540 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003541 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3542 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003543 } else {
3544 setverdict(pass);
3545 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003546 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003547}
3548
3549/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3550 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3551 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3552 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3553testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003554 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003555 var PagingTestCfg cfg := {
3556 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003557 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003558 load_factor := 2.0,
3559 exp_load_ind := true,
3560 exp_overload := true,
3561 use_tmsi := false
3562 };
3563 var PagingTestState st := f_TC_paging(cfg);
3564 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3565 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003566 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003567 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003568 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 +01003569 } else {
3570 setverdict(pass);
3571 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003572 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003573}
3574
3575/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3576 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3577 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3578 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3579testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003580 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003581 var PagingTestCfg cfg := {
3582 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003583 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003584 load_factor := 2.0,
3585 exp_load_ind := true,
3586 exp_overload := true,
3587 use_tmsi := true
3588 };
3589 var PagingTestState st := f_TC_paging(cfg);
3590 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3591 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003592 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003593 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003594 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 +01003595 } else {
3596 setverdict(pass);
3597 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003598 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003599}
3600
3601
Harald Welte93640c62018-02-25 16:59:33 +01003602/***********************************************************************
3603 * Immediate Assignment / AGCH
3604 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003605private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003606 len := 0,
3607 ma := ''B
3608}
Harald Welte93640c62018-02-25 16:59:33 +01003609
Harald Weltee8d750e2018-06-10 21:41:35 +02003610private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3611 return int2str(num_tx) & " sent, "
3612 & int2str(num_rx) & " received, "
3613 & int2str(num_del) & " deleted";
3614}
3615
3616private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3617 var L1ctlDlMessage l1_dl;
3618 timer T := 10.0;
3619 var integer num_tx := 0;
3620 var integer num_rx := 0;
3621 var integer num_del := 0;
3622 var charstring res_str;
3623 var float rx_ratio;
3624
Harald Welte10474062019-05-30 16:48:17 +02003625 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003626 f_init_l1ctl();
3627 f_l1_tune(L1CTL);
3628
3629 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003630 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003631 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3632 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003633 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003634 num_tx := num_tx+1;
3635 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003636 }
3637 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003638 T.start;
3639 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003640 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003641 num_del := num_del+1;
3642 repeat;
3643 }
3644 [] RSL_CCHAN.receive {
3645 repeat;
3646 }
3647 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003648 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3649 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3650 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003651 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003652 } else {
3653 num_rx := num_rx+1;
3654 }
3655 repeat;
3656 }
3657 [] L1CTL.receive { repeat; }
3658 [] T.timeout { }
3659 }
3660 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3661 log("AGCH test: " & res_str);
3662 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003663 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003664 }
3665 rx_ratio := int2float(num_rx) / int2float(num_tx);
3666 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003667 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 +02003668 } else {
3669 setverdict(pass);
3670 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003672}
3673
Harald Weltee8d750e2018-06-10 21:41:35 +02003674/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3675testcase TC_imm_ass_1000_20ms() runs on test_CT {
3676 f_TC_imm_ass(1000, 0.02, 0.25);
3677}
3678
3679/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3680testcase TC_imm_ass_200_0ms() runs on test_CT {
3681 f_TC_imm_ass(200, 0.0, 0.05);
3682}
3683
3684/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3685testcase TC_imm_ass_200_76ms() runs on test_CT {
3686 f_TC_imm_ass(150, 0.076, 1.00);
3687}
3688
3689
3690
Harald Welte48494ca2018-02-25 16:59:50 +01003691/***********************************************************************
3692 * BCCH
3693 ***********************************************************************/
3694
3695/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003696private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003697 GsmFrameNumber frame_number,
3698 SystemInformation si
3699}
3700
3701/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003702private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003703
3704/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003705private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003706
3707/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003708private function f_si_vecslot_contains(SystemInformationVector arr,
3709 RrMessageType key,
3710 boolean bcch_ext := false)
3711return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003712 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3713 var integer fn_mod51 := arr[i].frame_number mod 51;
3714 if (not bcch_ext and fn_mod51 == 2 or
3715 bcch_ext and fn_mod51 == 6) {
3716 if (arr[i].si.header.message_type == key) {
3717 return true;
3718 }
3719 }
3720 }
3721 return false;
3722}
3723
3724/* 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 +07003725private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3726 integer tc, RrMessageType key,
3727 boolean ext_bcch := false)
3728{
Harald Welte48494ca2018-02-25 16:59:50 +01003729 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003730 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003731 }
3732}
3733
3734/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003735private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3736 RrMessageType key)
3737return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003738 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3739 if (f_si_vecslot_contains(arr[tc], key) or
3740 f_si_vecslot_contains(arr[tc], key, true)) {
3741 return true;
3742 }
3743 }
3744 return false;
3745}
3746
3747/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003748private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3749 RrMessageType key,
3750 boolean bcch_ext := false,
3751 integer n := 1, integer m := 4)
3752return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003753 var integer count := 0;
3754 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003755 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3756 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003757 }
3758 for (var integer i:= 0; i < m; i := i + 1) {
3759 var integer fn_mod51 := arr[i].frame_number mod 51;
3760 if (not bcch_ext and fn_mod51 == 2 or
3761 bcch_ext and fn_mod51 == 6) {
3762 if (arr[i].si.header.message_type == key) {
3763 count := count + 1;
3764 }
3765 }
3766 }
3767 if (count >= n) {
3768 return true;
3769 } else {
3770 return false;
3771 }
3772}
3773
3774/* 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 +07003775private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3776 integer tc, RrMessageType key,
3777 boolean ext_bcch := false,
3778 integer n, integer m)
3779{
Harald Welte48494ca2018-02-25 16:59:50 +01003780 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003782 }
3783}
3784
3785/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003786private function f_si_vecslot_contains_only(SystemInformationVector arr,
3787 RrMessageType key,
3788 boolean bcch_ext := false)
3789return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003790 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3791 var integer fn_mod51 := arr[i].frame_number mod 51;
3792 if (not bcch_ext and fn_mod51 == 2 or
3793 bcch_ext and fn_mod51 == 6) {
3794 if (arr[i].si.header.message_type != key) {
3795 return false;
3796 }
3797 }
3798 }
3799 return true;
3800}
3801
3802/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003803private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3804 integer tc, RrMessageType key,
3805 boolean ext_bcch := false)
3806{
Harald Welte48494ca2018-02-25 16:59:50 +01003807 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003808 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003809 }
3810}
3811
3812/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003813private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003814 boolean bcch_extended,
3815 boolean si1_present,
3816 boolean si2bis_present,
3817 boolean si2ter_present,
3818 boolean si2quater_present,
3819 boolean si7_present,
3820 boolean si8_present,
3821 boolean si9_present,
3822 boolean si13_present,
3823 boolean si13alt_present,
3824 boolean si15_present,
3825 boolean si16_present,
3826 boolean si17_present,
3827 boolean si2n_present,
3828 boolean si21_present,
3829 boolean si22_present
3830}
3831
3832/* 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 +07003833private function f_validate_si_scheduling(SystemInformationConfig cfg,
3834 SystemInformationVectorPerTc si_per_tc)
3835{
Harald Welte48494ca2018-02-25 16:59:50 +01003836 var integer i;
3837 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3838 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003839 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003840 }
3841 }
3842 if (cfg.si1_present) {
3843 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3844 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3845 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3846 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3847 /* make sure *ALL* contain SI1 */
3848 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3849 }
3850 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3851 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3852 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3853 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3854 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3855 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3856
3857 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3858 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3859 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3860 * consecutive occurrences of TC = 4. */
3861 if (cfg.si2bis_present and not cfg.si2ter_present) {
3862 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3863 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3864 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3865 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3866 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3867 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3868 }
3869
3870 if (cfg.si7_present or cfg.si8_present) {
3871 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3872 * if System Information type 4 does not contain all information needed for cell
3873 * selection and reselection. */
3874 if (not cfg.bcch_extended) {
3875 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3876 }
3877 if (cfg.si7_present) {
3878 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3879 }
3880 if (cfg.si8_present) {
3881 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3882 }
3883 }
3884
3885 if (cfg.si2quater_present) {
3886 /* iii) System information type 2 quater is sent if needed, as determined by the system
3887 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3888 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3889 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3890 * within any of 4 consecutive occurrences of TC = 5. */
3891 if (not (cfg.bcch_extended)) {
3892 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3893 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3894 } else {
3895 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3896 }
3897 } else {
3898 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3899 }
3900 }
3901 if (cfg.si9_present) {
3902 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3903 * in system information type 3 as defined in 3GPP TS 44.018. */
3904 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3905 }
3906 if (cfg.si13_present) {
3907 /* vii) System Information type 13 is only related to the GPRS service. System Information
3908 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3909 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3910 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3911 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3912 * within any of 4 consecutive occurrences of TC=4. */
3913 if (not cfg.bcch_extended) {
3914 log("not-bccch-extended");
3915 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3916 } else {
3917 log("bccch-extended");
3918 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3919 }
3920 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003921 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003922 }
3923 }
3924 if (cfg.si16_present or cfg.si17_present) {
3925 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3926 * should not be sent in a cell where network sharing is used (see rule xv). */
3927 if (cfg.si22_present) {
3928 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3929 }
3930 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003931 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003932 }
3933 if (not cfg.bcch_extended) {
3934 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3935 }
3936 if (cfg.si16_present) {
3937 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3938 }
3939 if (cfg.si17_present) {
3940 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3941 }
3942 }
3943
3944 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3945 * broadcast information. The frequency with which they are sent is determined by the
3946 * system operator. System Information type 9 identifies the scheduling of System
3947 * Information type 18 and 20 messages. */
3948
3949 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3950 * Information Type 19 is present, then its scheduling shall be indicated in System
3951 * Information Type 9. */
3952
3953 if (cfg.si15_present) {
3954 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3955 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3956 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3957 * 4 consecutive occurrences of TC = 1. */
3958 if (not cfg.bcch_extended) {
3959 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3960 } else {
3961 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3962 }
3963 }
3964 if (cfg.si13alt_present) {
3965 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3966 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3967 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3968 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3969 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3970 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3971 * of TC = 4. */
3972 if (cfg.si13_present) {
3973 testcase.stop("Error: Cannot have SI13alt and SI13");
3974 }
3975 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003977 }
3978 if (not cfg.bcch_extended) {
3979 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3980 } else {
3981 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3982 }
3983 }
3984 if (cfg.si2n_present) {
3985 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3986 * as determined by the system operator. In the case that the message is sent on the
3987 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3988 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3989 * consecutive occurrences of TC = 4. */
3990 if (not cfg.bcch_extended) {
3991 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3992 } else {
3993 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3994 }
3995 }
3996 if (cfg.si21_present) {
3997 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3998 * determined by the system operator. If Extended Access Barring is in use in the cell
3999 * then this message is sent at least once within any of 4 consecutive occurrences of
4000 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4001 * cell then this message shall only be sent on BCCH Ext. */
4002 if (not cfg.bcch_extended) {
4003 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4004 } else {
4005 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4006 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004007 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004008 }
4009 }
4010 }
4011 if (cfg.si22_present) {
4012 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4013 * should not be sent in a cell where SoLSA is used (see rule viii). System
4014 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4015 * =2 and TC=6. */
4016 if (cfg.si16_present or cfg.si17_present) {
4017 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4018 }
4019 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4020 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004022 }
4023 if (not cfg.bcch_extended) {
4024 testcase.stop("Error: SI22 requires BCCH Extd!");
4025 } else {
4026 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4027 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4028 }
4029 }
4030}
4031
4032/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004033private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4034return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004035 timer T := duration;
4036 var SystemInformationVectorPerTc si_per_tc;
4037 var L1ctlDlMessage l1_dl;
4038
4039 /* initialize all per-TC vectors empty */
4040 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4041 si_per_tc[i] := {};
4042 }
4043
4044 /* flush all previous L1 queued msgs */
4045 pt.clear;
4046
4047 T.start;
4048 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004049 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004050 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4051 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4052 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004053 repeat;
4054 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004055
Harald Welte48494ca2018-02-25 16:59:50 +01004056 var integer tc := f_gsm_compute_tc(sig.frame_number);
4057 log("SI received at TC=", tc, ": ", sig.si);
4058 /* append to the per-TC bucket */
4059 si_per_tc[tc] := si_per_tc[tc] & { sig };
4060 repeat;
4061 }
4062 [] pt.receive { repeat; }
4063 [] T.timeout { }
4064 }
4065
4066 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4067 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4068 }
4069 log("si_per_tc=", si_per_tc);
4070 return si_per_tc;
4071}
4072
4073/* helper function: Set given SI via RSL + validate scheduling.
4074 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004075private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004076 var SystemInformationVectorPerTc si_per_tc;
4077 f_init_l1ctl();
4078 f_l1_tune(L1CTL);
4079
4080 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004081 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004082 f_validate_si_scheduling(si_cfg, si_per_tc);
4083
4084 setverdict(pass);
4085}
4086
4087testcase TC_si_sched_default() runs on test_CT {
4088 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004089 /* 2+3+4 are mandatory and set in f_init() */
4090 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004091 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004092}
4093
4094testcase TC_si_sched_1() runs on test_CT {
4095 f_init();
4096 si_cfg.si1_present := true;
4097 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004098 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004099 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004100}
4101
4102testcase TC_si_sched_2bis() runs on test_CT {
4103 f_init();
4104 si_cfg.si2bis_present := true;
4105 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4106 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004107 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004108}
4109
4110testcase TC_si_sched_2ter() runs on test_CT {
4111 f_init();
4112 si_cfg.si2ter_present := true;
4113 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4114 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004116}
4117
4118testcase TC_si_sched_2ter_2bis() runs on test_CT {
4119 f_init();
4120 si_cfg.si2bis_present := true;
4121 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4122 si_cfg.si2ter_present := true;
4123 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4124 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004125 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004126}
4127
4128testcase TC_si_sched_2quater() runs on test_CT {
4129 f_init();
4130 si_cfg.si2quater_present := true;
4131 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004132 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004134}
4135
4136testcase TC_si_sched_13() runs on test_CT {
4137 f_init();
4138 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004139 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004140 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004141 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004142}
4143
4144testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4145 f_init();
4146 si_cfg.si2bis_present := true;
4147 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4148 si_cfg.si2ter_present := true;
4149 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4150 si_cfg.si2quater_present := true;
4151 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4152 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004153 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004154 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004156}
4157
4158
Harald Welte68e495b2018-02-25 00:05:57 +01004159testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004160 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004161 /* FIXME: enable / disable individual BCCH info */
4162 //ts_RSL_BCCH_INFO(si_type, info);
4163 /* expect no ERROR REPORT after either of them *
4164 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004165 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004166}
4167
Harald Welte93640c62018-02-25 16:59:33 +01004168/***********************************************************************
4169 * Low-Level Protocol Errors / ERROR REPORT
4170 ***********************************************************************/
4171
Harald Welte01d982c2018-02-25 01:31:40 +01004172private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4173 timer T := 5.0;
4174 T.start;
4175 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004176 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004177 setverdict(pass);
4178 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004179 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004181 }
4182 [] RSL_CCHAN.receive {
4183 repeat;
4184 }
4185 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004186 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004187 }
4188 }
4189}
4190
4191/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4192testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004193 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004194 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4195 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004196 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004197
4198 f_exp_err_rep(RSL_ERR_PROTO);
4199}
4200
4201/* Provoke a mandatory IE error and match on ERROR REPORT */
4202testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004203 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004204
4205 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4206 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004207 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004208
4209 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4210}
4211
4212/* Provoke an IE content error and match on ERROR REPORT */
4213testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004214 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004215 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4216 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004217 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004218
4219 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4220}
4221
Harald Welteee25aae2019-05-19 14:32:37 +02004222/* attempt to activate channel with wrong RSL Message Discriminator IE */
4223function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4224 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4225 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4226 RSL.send(rsl);
4227 f_rslem_unregister(0, g_chan_nr);
4228}
4229testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4230 var ConnHdlr vc_conn;
4231 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4232
Harald Welte10474062019-05-30 16:48:17 +02004233 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004234
4235 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4236 vc_conn.done;
4237 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4238
4239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4240}
4241
4242/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004243private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004244 var template (value) RSL_Message rsl_tx;
4245 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4246 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4247 RSL.send(rsl_tx);
4248 f_rslem_unregister(0, g_chan_nr);
4249}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004250private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004251 var template (value) RSL_Message rsl_tx;
4252 /* we first have to activate the dedicated channel */
4253 f_rsl_chan_act(g_pars.chan_mode);
4254 /* ... to then send an invalid RLL message */
4255 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4256 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4257 RSL.send(rsl_tx);
4258 f_rslem_unregister(0, g_chan_nr);
4259}
4260testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4261 var ConnHdlr vc_conn;
4262 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4263 var template (value) RSL_Message rsl_tx;
4264
Harald Welte10474062019-05-30 16:48:17 +02004265 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004266
4267 /* Common Channel with wrong message type */
4268 RSL_CCHAN.clear;
4269 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4270 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004271 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004272 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4273
4274 /* TRX Management */
4275 RSL_CCHAN.clear;
4276 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4277 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004278 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004279 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4280
4281 /* Dedicated Channel */
4282 RSL_CCHAN.clear;
4283 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4284 vc_conn.done;
4285 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4286
4287 /* RLL */
4288 RSL_CCHAN.clear;
4289 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4290 vc_conn.done;
4291 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4292}
4293
4294/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004295private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004296 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4297 f_rslem_unregister(0, g_chan_nr);
4298}
4299testcase TC_err_rep_wrong_sequence() runs on test_CT {
4300 var ConnHdlr vc_conn;
4301 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4302
Harald Welte10474062019-05-30 16:48:17 +02004303 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004304
4305 RSL_CCHAN.clear;
4306 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4307 vc_conn.done;
4308 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4309}
4310
Harald Welte93640c62018-02-25 16:59:33 +01004311/***********************************************************************
4312 * IPA CRCX/MDCX/DLCS media stream handling
4313 ***********************************************************************/
4314
Harald Weltea871a382018-02-25 02:03:14 +01004315/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004316private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004317 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4318 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004319}
4320testcase TC_ipa_dlcx_not_active() runs on test_CT {
4321 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004322 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004323 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4324 vc_conn.done;
4325}
Harald Welte68e495b2018-02-25 00:05:57 +01004326
Harald Weltea3f1df92018-02-25 12:49:55 +01004327/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004328private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004329 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4330 "IPA CRCX ACK");
4331 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4332 "IPA CRCX NACK");
4333}
4334testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4335 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004336 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004337 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4338 vc_conn.done;
4339}
4340
4341/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004342private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004343 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4344 "IPA CRCX ACK");
4345 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4346 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4347 var uint7_t rtp_pt2 := f_rnd_int(127);
4348 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4349 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4350 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4351 "IPA MDCX ACK");
4352 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4353 "IPA DLCX ACK");
4354}
4355testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4356 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004357 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004358 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4359 vc_conn.done;
4360}
4361
Harald Welte3ae11da2018-02-25 13:36:06 +01004362/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004363private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004364 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4365 "IPA CRCX ACK");
4366 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4367 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4368 var uint7_t rtp_pt2 := f_rnd_int(127);
4369 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4370 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4371 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4372 "IPA MDCX ACK");
4373 /* Second MDCX */
4374 remote_ip := f_rnd_int(c_UINT32_MAX);
4375 remote_port := f_rnd_int(c_UINT16_MAX);
4376 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4377 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4378 "IPA MDCX ACK");
4379 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4380 "IPA DLCX ACK");
4381}
4382testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4383 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004384 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004385 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4386 vc_conn.done;
4387}
4388
Harald Welte9912eb52018-02-25 13:30:15 +01004389/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004390private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004391 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4392 "IPA CRCX NACK");
4393}
4394testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4395 var ConnHdlrPars pars;
4396 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004397 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004398
4399 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4400 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4401 vc_conn.done;
4402
4403 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4404 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4405 vc_conn.done;
4406}
4407
Harald Weltea3f1df92018-02-25 12:49:55 +01004408
Harald Welte883340c2018-02-28 18:59:29 +01004409/***********************************************************************
4410 * PCU Socket related tests
4411 ***********************************************************************/
4412
Harald Welte07bd2d22019-05-25 11:03:30 +02004413/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004414friend 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 +01004415runs on test_CT {
4416 timer T := 3.0;
4417
4418 /* we don't expect any RTS.req before PDCH are active */
4419 T.start;
4420 alt {
4421 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004423 }
4424 [] PCU.receive { repeat; }
4425 [] T.timeout { }
4426 }
4427
4428 /* Send PDCH activate request for known PDCH timeslot */
4429 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4430
4431 /* we now expect RTS.req for this timeslot (only) */
4432 T.start;
4433 alt {
4434 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4435 setverdict(pass);
4436 }
4437 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4438 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004440 }
4441 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004442 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004443 }
4444 [] PCU.receive { repeat; }
4445 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004446 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004447 }
4448 [not exp_success] T.timeout {
4449 setverdict(pass);
4450 }
4451 }
4452}
4453
Harald Welte07bd2d22019-05-25 11:03:30 +02004454/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004455friend 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 +01004456runs on test_CT {
4457 timer T := 3.0;
4458
4459 /* Send PDCH activate request for known PDCH timeslot */
4460 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 +02004461 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4462 * when it will actually have been executed in the BTS */
4463 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004464 PCU.clear;
4465 /* we now expect no RTS.req for this timeslot */
4466 T.start;
4467 alt {
4468 [] 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 +02004469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004470 }
4471 [] PCU.receive { repeat; }
4472 [] T.timeout {
4473 setverdict(pass);
4474 }
4475 }
4476}
4477
Harald Weltead033dc2019-05-25 17:28:16 +02004478friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004479 f_init();
4480 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4481}
4482
Harald Welte883340c2018-02-28 18:59:29 +01004483/* PDCH activation via PCU socket; check for presence of RTS.req */
4484testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004485 f_init_pcu_test();
4486
Harald Welte883340c2018-02-28 18:59:29 +01004487 f_TC_pcu_act_req(0, 0, 7, true);
4488}
4489
4490/* PDCH activation via PCU socket on non-PDCU timeslot */
4491testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004492 f_init_pcu_test();
4493
Harald Welte883340c2018-02-28 18:59:29 +01004494 f_TC_pcu_act_req(0, 0, 1, false);
4495}
4496
4497/* PDCH activation via PCU socket on wrong BTS */
4498testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004499 f_init_pcu_test();
4500
Harald Welte883340c2018-02-28 18:59:29 +01004501 f_TC_pcu_act_req(23, 0, 7, false);
4502}
4503
4504/* PDCH activation via PCU socket on wrong TRX */
4505testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004506 f_init_pcu_test();
4507
Harald Welte883340c2018-02-28 18:59:29 +01004508 f_TC_pcu_act_req(0, 23, 7, false);
4509}
4510
4511/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4512testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004513 f_init_pcu_test();
4514
Harald Welte883340c2018-02-28 18:59:29 +01004515 /* Activate PDCH */
4516 f_TC_pcu_act_req(0, 0, 7, true);
4517 f_sleep(1.0);
4518 /* and De-Activate again */
4519 f_TC_pcu_deact_req(0, 0, 7);
4520}
4521
4522/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4523testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004524 f_init_pcu_test();
4525
Harald Welte883340c2018-02-28 18:59:29 +01004526 f_TC_pcu_deact_req(0, 0, 1);
4527}
4528
4529/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4530testcase TC_pcu_ver_si13() runs on test_CT {
4531 const octetstring si13 := '00010203040506070909'O;
4532 var PCUIF_send_data sd;
4533 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004534 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004535
4536 /* Set SI13 via RSL */
4537 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004538
Harald Welte883340c2018-02-28 18:59:29 +01004539 T.start;
4540 alt {
4541 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4542 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4543 setverdict(pass);
4544 } else {
4545 repeat;
4546 }
4547 }
4548 [] PCU.receive { repeat; }
4549 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004550 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004551 }
4552 }
4553}
4554
4555private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4556
4557/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004558friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004559 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4560runs on test_CT
4561{
4562 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4563 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4564}
4565
4566/* 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 +02004567friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4568 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004569runs on test_CT
4570{
4571 var PCUIF_send_data sd;
4572
4573 timer T := 3.0;
4574 T.start;
4575 alt {
4576 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4577 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4578 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4579 sd.data.u.rts_req.fn, sapi, data);
4580 }
4581 [] PCU.receive { repeat; }
4582 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004584 }
4585 }
4586}
4587
4588/* Send DATA.req on invalid BTS */
4589testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004590 var TfiUsfArr tua := f_TfiUsfArrInit();
4591 var octetstring data := '0000'O & f_rnd_octstring(21);
4592
4593 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004594
Harald Welte883340c2018-02-28 18:59:29 +01004595 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004596 f_TfiUsfArrSet(tua, 7, 0);
4597 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4598 f_sleep(1.0);
4599
4600 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004601}
4602
4603/* Send DATA.req on invalid TRX */
4604testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004605 var TfiUsfArr tua := f_TfiUsfArrInit();
4606 var octetstring data := '0000'O & f_rnd_octstring(21);
4607
4608 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004609
Harald Welte883340c2018-02-28 18:59:29 +01004610 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004611 f_TfiUsfArrSet(tua, 7, 0);
4612 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4613 f_sleep(1.0);
4614
4615 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004616}
4617
4618/* Send DATA.req on invalid timeslot */
4619testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004620 var TfiUsfArr tua := f_TfiUsfArrInit();
4621 var octetstring data := '0000'O & f_rnd_octstring(21);
4622
4623 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004624
Harald Welte883340c2018-02-28 18:59:29 +01004625 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004626 f_TfiUsfArrSet(tua, 7, 0);
4627 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4628 f_sleep(1.0);
4629
4630 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004631}
4632
4633/* Send DATA.req on timeslot that hasn't been activated */
4634testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004635 var TfiUsfArr tua := f_TfiUsfArrInit();
4636 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004637
Harald Welte7162a612019-05-26 12:56:09 +02004638 f_virtphy_common();
4639
4640 f_TfiUsfArrSet(tua, 7, 0);
4641 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4642 f_sleep(1.0);
4643
4644 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004645}
4646
Harald Weltead033dc2019-05-25 17:28:16 +02004647private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004648 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4649 boolean wait_rts := true)
4650runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004651 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004652 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004653
4654 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004655 if (wait_rts) {
4656 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4657 } else {
4658 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4659 }
Harald Weltead033dc2019-05-25 17:28:16 +02004660
4661 T.start;
4662 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004663 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004664 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4665 setverdict(pass);
4666 }
Harald Welte7162a612019-05-26 12:56:09 +02004667 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4668 setverdict(fail, "Received unexpected ", rx_dl);
4669 }
Harald Weltead033dc2019-05-25 17:28:16 +02004670 [] L1CTL.receive {
4671 repeat;
4672 }
Harald Welte7162a612019-05-26 12:56:09 +02004673 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004674 setverdict(fail, "Timeout waiting for ", data);
4675 }
Harald Welte7162a612019-05-26 12:56:09 +02004676 [not expect_data] T.timeout {
4677 setverdict(pass);
4678 }
Harald Weltead033dc2019-05-25 17:28:16 +02004679 }
4680}
4681
4682private function f_disable_dynamic_ts() runs on test_CT
4683{
4684 f_init_vty_bsc();
4685 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4686 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4687 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4688 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004689 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004690}
4691
4692private function f_virtphy_common() runs on test_CT {
4693 f_disable_dynamic_ts();
4694 f_init_l1ctl();
4695 f_l1_tune(L1CTL);
4696}
4697
4698testcase TC_pcu_data_req_pdtch() runs on test_CT {
4699 var TfiUsfArr tua := f_TfiUsfArrInit();
4700 var octetstring data := '0000'O & f_rnd_octstring(21);
4701
4702 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004703
Harald Welte883340c2018-02-28 18:59:29 +01004704 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004705 f_TfiUsfArrSet(tua, 7, 0);
4706 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4707 f_sleep(1.0);
4708
4709 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004710}
4711
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004712/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004713testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004714 var TfiUsfArr tua := f_TfiUsfArrInit();
4715 var octetstring data := '0000'O & f_rnd_octstring(21);
4716
4717 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004718
Harald Welte883340c2018-02-28 18:59:29 +01004719 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004720 f_TfiUsfArrSet(tua, 7, 0);
4721 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4722 f_sleep(1.0);
4723
4724 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004725}
4726
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004727private function f_TC_pcu_ptcch_ul(uint16_t ra)
4728runs on test_CT {
4729 var template PCUIF_Message pcu_rach_ind;
4730 var PCUIF_send_data sd;
4731 var GsmFrameNumber fn;
4732 timer T;
4733
4734 /* Send an Access Burst on PTCCH/U over the Um-interface */
4735 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4736 chan_nr := ts_RslChanNr_PDCH(7),
4737 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4738
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004739 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4740 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004741
4742 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4743 T.start(52.0 * 4.615 / 1000.0);
4744 alt {
4745 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4746 log("Rx an Access Burst on the PCU interface: ", sd.data);
4747 setverdict(pass);
4748 T.stop;
4749 }
4750 [] PCU.receive { repeat; }
4751 [] T.timeout {
4752 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4753 /* Keep going, that's not the end of the world */
4754 }
4755 }
4756}
4757
4758testcase TC_pcu_ptcch() runs on test_CT {
4759 var L1ctlDlMessage dl;
4760 var octetstring data;
4761 timer T;
4762
4763 f_init_pcu_test();
4764 f_init_l1ctl();
4765 f_l1_tune(L1CTL);
4766
4767 /* Activate PDCH channel on TS7 */
4768 f_TC_pcu_act_req(0, 0, 7, true);
4769
4770 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004771 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004772 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004773 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004774 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004775
4776 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4777 for (var integer i := 0; i < 16; i := i + 1) {
4778 log("Sending an Access Burst towards the L1CTL interface");
4779 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4780 }
4781
4782 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4783 data := f_rnd_octstring(23);
4784
4785 /* Verify PTCCH/D: send a random data block, make sure it's received */
4786 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4787 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4788
4789 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4790 * let's give it more time in case if we miss the beginning. */
4791 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4792 alt {
4793 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4794 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4795 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4796 frame := data)) -> value dl {
4797 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4798 setverdict(pass);
4799 T.stop;
4800 }
4801 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4802 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4803 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4804 l2_data := data)) -> value dl {
4805 log("Rx PTCCH/D data block on L1CTL: ", dl);
4806 setverdict(pass);
4807 T.stop;
4808 }
4809 [] L1CTL.receive { repeat; }
4810 [] T.timeout {
4811 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4812 }
4813 }
4814}
4815
Harald Welte883340c2018-02-28 18:59:29 +01004816/* Send AGCH from PCU; check it appears on Um side */
4817testcase TC_pcu_data_req_agch() runs on test_CT {
4818 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004819 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004820 f_init_l1ctl();
4821 f_l1_tune(L1CTL);
4822
4823 f_TC_pcu_act_req(0, 0, 7, true);
4824 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4825
4826 T.start;
4827 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004828 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004829 setverdict(pass);
4830 }
4831 [] L1CTL.receive { repeat; }
4832 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004834 }
4835 }
4836}
4837
Harald Welte928622b2019-05-26 13:22:59 +02004838/* Send AGCH from PCU; check it appears on Um side */
4839testcase TC_pcu_data_req_pch() runs on test_CT {
4840 timer T := 3.0;
4841 f_init_pcu_test();
4842 f_init_l1ctl();
4843 f_l1_tune(L1CTL);
4844
4845 f_TC_pcu_act_req(0, 0, 7, true);
4846 /* three characters prefix: last 3 digits of IMSI as ASCII */
4847 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4848
4849 T.start;
4850 alt {
4851 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4852 setverdict(pass);
4853 }
4854 [] L1CTL.receive { repeat; }
4855 [] T.timeout {
4856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4857 }
4858 }
4859}
4860
Harald Welte883340c2018-02-28 18:59:29 +01004861/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4862testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4863 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004864 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004865 f_init_l1ctl();
4866 f_l1_tune(L1CTL);
4867
4868 /* append 3 last imsi digits so BTS can compute pagng group */
4869 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4870
4871 timer T := 0.5;
4872 T.start;
4873 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004874 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004875 /* TODO: verify paging group */
4876 setverdict(pass);
4877 }
4878 [] L1CTL.receive { repeat; }
4879 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004881 }
4882 }
4883}
4884
4885/* Send RACH from Um side, expect it to show up on PCU socket */
4886testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004887 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004888 f_init_l1ctl();
4889 f_l1_tune(L1CTL);
4890
4891 var GsmFrameNumber fn_last := 0;
4892 for (var integer i := 0; i < 1000; i := i+1) {
4893 var OCT1 ra := f_rnd_ra_ps();
4894 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4895 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004896 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004897 }
4898 fn_last := fn;
4899
4900 timer T := 2.0;
4901 T.start;
4902 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004903 [] 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 +01004904 T.stop;
4905 }
4906 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004907 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004908 }
4909 [] PCU.receive { repeat; }
4910 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004912 }
4913 }
4914 }
4915 setverdict(pass);
4916}
4917
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004918/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4919 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4920testcase TC_pcu_ext_rach_content() runs on test_CT {
4921 var template PCUIF_Message pcu_rach_ind;
4922 var GsmFrameNumber fn_last := 0;
4923 var L1ctlRachSynchSeq synch_seq;
4924 var PCUIF_BurstType pcu_bt;
4925 var GsmFrameNumber fn;
4926 var BIT11 ra11;
4927
4928 f_init_pcu_test();
4929 f_init_l1ctl();
4930 f_l1_tune(L1CTL);
4931
4932 for (var integer i := 0; i < 1000; i := i+1) {
4933 /* We need to test both TS1 & TS2 */
4934 if (i rem 2 == 0) {
4935 synch_seq := RACH_SYNCH_SEQ_TS1;
4936 pcu_bt := BURST_TYPE_1;
4937 } else {
4938 synch_seq := RACH_SYNCH_SEQ_TS2;
4939 pcu_bt := BURST_TYPE_2;
4940 }
4941
4942 ra11 := f_rnd_ra11_ps();
4943 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4944 if (fn == fn_last) {
4945 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4946 "Two RACH in same FN?!?");
4947 }
4948 fn_last := fn;
4949
4950 /* Compose the expected message */
4951 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004952 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004953 ra := bit2int(ra11),
4954 is_11bit := 1,
4955 burst_type := pcu_bt,
4956 fn := fn);
4957
4958 timer T := 2.0;
4959 T.start;
4960 alt {
4961 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4962 T.stop;
4963 }
4964 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4965 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4966 }
4967 [] PCU.receive { repeat; }
4968 [] T.timeout {
4969 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4970 }
4971 }
4972 }
4973 setverdict(pass);
4974}
4975
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004976private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4977runs on test_CT {
4978 var template PCUIF_send_data sdt;
4979 var PCUIF_send_data sd;
4980 var int16_t lqual_cb;
4981 timer T := 1.0;
4982
4983 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4984 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4985
4986 /* Send a random PDTCH frame over Um */
4987 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4988 '0000'O & f_rnd_octstring(21)));
4989
4990 T.start;
4991 alt {
4992 /* If expected link quality is above the threshold */
4993 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4994 lqual_cb := sd.data.u.data_ind.lqual_cb;
4995 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4996
4997 /* Make sure the actual link quality matches the expected value */
4998 if (not match(lqual_cb, lqual_cb_exp)) {
4999 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5000 "expected value ", lqual_cb_exp));
5001 } else {
5002 setverdict(pass);
5003 }
5004 }
5005 /* If expected link quality is below the threshold */
5006 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5007 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5008 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5009 }
5010 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5011 [] PCU.receive { repeat; }
5012 [lqual_cb_exp < thresh] T.timeout {
5013 log("Rx nothing, as expected");
5014 setverdict(pass);
5015 }
5016 [lqual_cb_exp >= thresh] T.timeout {
5017 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5018 "Timeout waiting for PCUIF_DATA.ind");
5019 }
5020 }
5021}
5022
5023/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5024testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
5025 f_init_pcu_test();
5026 PCU.clear;
5027
5028 f_init_l1ctl();
5029 f_l1_tune(L1CTL);
5030
5031 /* Activate a PDCH channel on TS7 */
5032 f_TC_pcu_act_req(0, 0, 7, true);
5033
5034 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005035 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005036 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005037 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005038 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005039
5040 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5041 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5042 var TrxcMessage ret;
5043
5044 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5045 valueof(ts_TRXC_FAKE_CI(i)));
5046
5047 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5048 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5049 }
5050}
5051
Harald Welte883340c2018-02-28 18:59:29 +01005052/* Send PAGING via RSL, expect it to shw up on PCU socket */
5053testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01005054 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01005055
5056 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005057 var MobileIdentityLV mi_lv;
5058 var octetstring mi_lv_enc;
5059 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005060 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005061
Harald Welte883340c2018-02-28 18:59:29 +01005062 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005063 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005064 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005065 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005066 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005067
5068 /* Fancy encoding for PCUIF */
5069 mi_lv := valueof(ts_MI_LV(mi));
5070 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5071 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005072
5073 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005074 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005075 T.start;
5076 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005077 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005078 }
5079 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005081 }
5082 [] PCU.receive { repeat; }
5083 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005085 }
5086 }
5087 }
5088 setverdict(pass);
5089}
5090
Harald Welted66c9b82019-05-25 09:03:15 +02005091/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5092testcase TC_pcu_time_ind() runs on test_CT {
5093 var PCUIF_send_data pcu_sd;
5094 var integer num_time_ind := 0;
5095 var integer first_fn, last_fn;
5096 var float test_duration := 5.0;
5097 timer T;
5098
5099 f_init_pcu_test();
5100 f_TC_pcu_act_req(0, 0, 7, true);
5101
5102 PCU.clear;
5103 T.start(test_duration);
5104 alt {
5105 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5106 num_time_ind := num_time_ind + 1;
5107 if (not isbound(first_fn)) {
5108 first_fn := pcu_sd.data.u.time_ind.fn;
5109 }
5110 last_fn := pcu_sd.data.u.time_ind.fn;
5111 repeat;
5112 }
5113 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5114 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5115 repeat;
5116 }
5117 [] PCU.receive {
5118 repeat;
5119 }
5120 [] T.timeout {}
5121 }
5122 var integer fn_expired := last_fn - first_fn;
5123 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5124
5125 /* verify the number of frames expired matches our expectation */
5126 const float c_GSM_FN_DURATION_MS := 4.61538;
5127 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005128 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005129 if (not match(fn_expired, t_fn_expected)) {
5130 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5131 }
5132
5133 /* There are three TIME.ind in every fn MOD 13 */
5134 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5135 /* Add some tolerance */
5136 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5137 if (not match(num_time_ind, t_time_ind_exp)) {
5138 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5139 }
5140
5141 setverdict(pass);
5142}
5143
Harald Welte4832c862019-05-25 14:57:18 +02005144/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5145testcase TC_pcu_rts_req() runs on test_CT {
5146 var PCUIF_send_data pcu_sd;
5147 var integer first_fn, last_fn;
5148 var integer num_rts_pdtch := 0;
5149 var integer num_rts_ptcch := 0;
5150 var float test_duration := 5.0;
5151 timer T;
5152
5153 f_init_pcu_test();
5154 f_TC_pcu_act_req(0, 0, 7, true);
5155
5156 PCU.clear;
5157 T.start(test_duration);
5158 alt {
5159 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5160 -> value pcu_sd {
5161 num_rts_pdtch := num_rts_pdtch + 1;
5162 if (not isbound(first_fn)) {
5163 first_fn := pcu_sd.data.u.rts_req.fn;
5164 }
5165 last_fn := pcu_sd.data.u.rts_req.fn;
5166 repeat;
5167 }
5168 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5169 -> value pcu_sd {
5170 num_rts_ptcch := num_rts_ptcch + 1;
5171 if (not isbound(first_fn)) {
5172 first_fn := pcu_sd.data.u.rts_req.fn;
5173 }
5174 last_fn := pcu_sd.data.u.rts_req.fn;
5175 repeat;
5176 }
5177 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5178 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5179 repeat;
5180 }
5181 [] PCU.receive {
5182 repeat;
5183 }
5184 [] T.timeout {}
5185 }
5186 var integer fn_expired := last_fn - first_fn;
5187 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5188 ", num_rts_ptcch=", num_rts_ptcch);
5189
5190 /* verify the number of frames expired matches our expectation */
5191 const float c_GSM_FN_DURATION_MS := 4.61538;
5192 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005193 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005194 if (not match(fn_expired, t_fn_expected)) {
5195 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5196 }
5197
5198 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5199 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5200 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5201 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5202 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5203 t_ptcch_exp);
5204 }
5205
5206 /* We have 12 PDTCH blocks every 52-multiframe */
5207 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5208 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5209 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5210 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5211 t_pdtch_exp);
5212 }
5213
5214 setverdict(pass);
5215}
5216
Harald Welte07bd2d22019-05-25 11:03:30 +02005217/* test for generating Abis side OML ALERT from the PCU */
5218testcase TC_pcu_oml_alert() runs on test_CT {
5219 var PCUIF_send_data pcu_sd;
5220 var integer num_time_ind := 0;
5221 var integer first_fn, last_fn;
5222 var float test_duration := 5.0;
5223 timer T;
5224
5225 f_init_pcu_test();
5226 f_TC_pcu_act_req(0, 0, 7, true);
5227
5228 /* re-connect CTRL port from BTS to BSC */
5229 f_ipa_ctrl_stop();
5230 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5231
5232 /* Send that OML Alert */
5233 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5234
5235 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5236 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5237 setverdict(pass);
5238}
5239
Harald Welteeaa9a862019-05-26 23:01:08 +02005240/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5241private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5242 var PCUIF_Message first_info;
5243 var integer pcu_conn_id := -1;
5244 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5245 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5246 var OCT4 tlli := '01020304'O;
5247 var OCT1 cause := '23'O;
5248 timer T := 5.0;
5249
5250 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5251
5252 f_l1_tune(L1CTL);
5253 RSL.clear;
5254
5255 f_est_dchan();
5256 L1CTL.clear;
5257
5258 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5259
5260 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5261 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5262 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5263
5264 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5265 T.start;
5266 alt {
5267 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5268 setverdict(pass);
5269 }
5270 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5271 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5272 }
5273 [] PCU.receive {
5274 repeat;
5275 }
5276 [] T.timeout {
5277 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5278 }
5279 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005280
5281 /* release the channel */
5282 f_rsl_chan_deact();
5283 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5284 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005285}
5286testcase TC_pcu_rr_suspend() runs on test_CT {
5287 var ConnHdlrPars pars;
5288 var ConnHdlr vc_conn;
5289
5290 f_init();
5291
5292 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5293 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5294 vc_conn.done;
5295}
Harald Welte07bd2d22019-05-25 11:03:30 +02005296
Harald Weltea2e0e942019-05-27 18:12:53 +02005297/* Ensure that PCUIF socket can accept only a single connection */
5298testcase TC_pcu_socket_connect_multi() runs on test_CT {
5299 timer T := 5.0;
5300
5301 /* this (among other things) establishes the first connection to the PCUIF socket */
5302 f_init();
5303
5304 /* try to establish a second connection, expect it to fail */
5305 PCU.send(UD_connect:{mp_pcu_socket, -1});
5306 T.start;
5307 alt {
5308 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5309 setverdict(pass);
5310 }
5311 [] PCU.receive(UD_connect_result:?) {
5312 setverdict(fail, "Unexpected unix domain connect result");
5313 }
5314 [] T.timeout {
5315 setverdict(pass);
5316 }
5317 }
5318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5319}
5320
Harald Weltec8effb72019-05-27 18:23:04 +02005321/* Ensure that PCUIF socket can disconnect + reconnect */
5322testcase TC_pcu_socket_reconnect() runs on test_CT {
5323 /* this (among other things) establishes the first connection to the PCUIF socket */
5324 f_init();
5325
5326 f_sleep(1.0);
5327
5328 f_pcuif_close(PCU, g_pcu_conn_id);
5329 g_pcu_conn_id := -1;
5330
5331 f_sleep(1.0);
5332
5333 /* re-connect */
5334 PCU.clear;
5335 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5336 setverdict(pass);
5337
5338 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5339}
5340
Harald Weltebe030482019-05-27 22:29:35 +02005341/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005342private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5343runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005344 var L1ctlDlMessage l1_dl;
5345 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005346 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005347 timer T := 5.0;
5348 T.start;
5349 alt {
5350 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005351 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5352 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005353 repeat;
5354 }
5355 }
5356 [] pt.receive {
5357 repeat;
5358 }
5359 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5361 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005362 }
5363 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005364 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005365}
5366
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005367/* Check if GPRS Indicator is present in RR System Information of a given type */
5368private function f_si_has_gprs_indicator(RrMessageType si_type)
5369runs on test_CT return boolean {
5370 var SystemInformation si := f_get_si(L1CTL, si_type);
5371
5372 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005373 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005374 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005375 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005376 }
5377
5378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5379 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005380}
5381
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005382/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5383private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5384runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005385 /* don't call f_init() as this would connect PCU socket */
5386 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005387
5388 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005389 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005390 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005391
5392 f_init_l1ctl();
5393 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005394 f_sleep(2.0);
5395 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005396
5397 if (f_si_has_gprs_indicator(si_type)) {
5398 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005399 } else {
5400 setverdict(pass);
5401 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005402
Harald Weltebe030482019-05-27 22:29:35 +02005403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5404}
5405
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005406testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5407 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5408}
Harald Weltebe030482019-05-27 22:29:35 +02005409
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005410testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5411 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5412}
5413
5414/* Ensure that GPRS capability is advertised after PCU socket connect */
5415private function f_TC_pcu_socket_connect(RrMessageType si_type)
5416runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005417 /* this (among other things) establishes the first connection to the PCUIF socket */
5418 f_init();
5419 f_init_l1ctl();
5420 f_l1_tune(L1CTL);
5421
5422 f_sleep(2.0);
5423 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005424
5425 if (not f_si_has_gprs_indicator(si_type)) {
5426 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005427 } else {
5428 setverdict(pass);
5429 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005430
Harald Weltebe030482019-05-27 22:29:35 +02005431 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5432}
5433
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005434testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5435 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5436}
Harald Weltebe030482019-05-27 22:29:35 +02005437
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005438testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5439 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5440}
5441
5442/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5443private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5444runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005445 /* this (among other things) establishes the first connection to the PCUIF socket */
5446 f_init();
5447 f_init_l1ctl();
5448 f_l1_tune(L1CTL);
5449
5450 f_pcuif_close(PCU, g_pcu_conn_id);
5451 g_pcu_conn_id := -1;
5452
5453 f_sleep(1.0);
5454
5455 /* re-connect */
5456 PCU.clear;
5457 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5458
5459 f_sleep(2.0);
5460 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005461
5462 if (f_si_has_gprs_indicator(si_type)) {
5463 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005464 } else {
5465 setverdict(pass);
5466 }
5467
5468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5469}
5470
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005471testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5472 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5473}
5474
5475testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5476 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5477}
5478
Oliver Smithf5239c72019-08-28 10:01:25 +02005479/* 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) */
5480testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5481 var SystemInformation si3 := valueof(ts_SI3_default);
5482
5483 f_init();
5484
Harald Welte76220222020-10-11 20:32:44 +02005485 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5486 * information */
5487 timer T := 2.0;
5488 T.start;
5489 alt {
5490 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5491 [] T.timeout {}
5492 }
5493
Oliver Smithf5239c72019-08-28 10:01:25 +02005494 /* Verify cell_id */
5495 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5496 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5497 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005498 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5499 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5500 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005501 }
5502
5503 /* Verify LAC */
5504 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5505 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5506 if (lac_si3 != lac_pcu) {
5507 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5508 }
5509
5510 setverdict(pass);
5511}
Harald Welted66c9b82019-05-25 09:03:15 +02005512
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005513/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5514testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5515 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005516 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005517
5518 f_init();
5519
5520 info_ind := g_pcu_last_info.u.info_ind;
5521
5522 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5523 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5524 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5525 /* Skip inactive timeslots */
5526 continue;
5527 }
5528
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005529 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005530 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005531 else
5532 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005533
5534 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005535 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005536 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005537 hsn := fhp.maio_hsn.hsn,
5538 maio := fhp.maio_hsn.maio,
5539 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005540 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005541 } else {
5542 tr_ts := tr_PCUIF_InfoTrxTsH0;
5543 }
5544
5545 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5546 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5547 if (not match(ts, tr_ts)) {
5548 setverdict(fail, "Hopping parameters do not match: ",
5549 "received ", ts, " vs expected ", tr_ts);
5550 } else {
5551 setverdict(pass);
5552 }
5553 }
5554 }
5555}
5556
Alexander Couzens5283f552020-07-28 15:39:04 +02005557/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5558testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5559 f_init_vty_bsc();
5560 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5561 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5562
5563 f_init();
5564
5565 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5566 if (not ischosen(remote_addr.v10)) {
5567 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5568 log2str("Unexpected remote_addr: ", remote_addr));
5569 }
5570
5571 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5572 setverdict(fail, "Received address family is not IPv4");
5573 }
5574
5575 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5576 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5577 }
5578
5579 setverdict(pass);
5580}
5581
5582/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5583testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5584 f_init_vty_bsc();
5585 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5586
5587 f_init();
5588
5589 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5590 if (not ischosen(remote_addr.v10)) {
5591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5592 log2str("Unexpected remote_addr: ", remote_addr));
5593 }
5594
5595 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5596 setverdict(fail, "Received address family is not IPv6");
5597 }
5598
5599 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5600 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5601 }
5602
5603 setverdict(pass);
5604}
5605
Harald Welte3d04ae62018-04-04 20:29:05 +02005606/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005607 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005608 ***********************************************************************/
5609
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005610private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5611 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005612runs on ConnHdlr {
5613 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005614
5615 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005616 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005617 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5618 repeat;
5619 }
5620 }
5621}
5622
5623private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5624runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005625 /* Expect BTS to immediately acknowledge activation as PDCH */
5626 PCU.clear;
5627 f_rsl_chan_act(g_pars.chan_mode);
5628 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005629 timer T_wait := 2.0;
5630 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005631 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005632 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005633 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005634 [] T_wait.timeout {
5635 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5636 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5637 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005638 }
5639 /* try to activate this PDCH from the PCU point of view */
5640 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5641 /* FIXME: is there a response? */
5642}
5643
5644private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5645runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005646 /* Send RSL CHAN REL (deactivate) */
5647 PCU.clear;
5648 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5649 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005650 timer T_wait := 2.0;
5651 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005652 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005653 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005654 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005655 [] T_wait.timeout {
5656 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5657 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5658 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005659 }
5660 /* Emulate PCU asking BTS to deactivate PDCH */
5661 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5662 alt {
5663 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5664 setverdict(pass);
5665 }
5666 [] RSL.receive { repeat; }
5667 }
5668}
5669
5670/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005671private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005672 var PCUIF_Message first_info;
5673 var integer ts_nr := g_chan_nr.tn;
5674 var integer trx_nr := 0;
5675 var integer bts_nr := 0;
5676 var integer pcu_conn_id := -1;
5677
5678 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5679
5680 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5681 f_sleep(3.0);
5682 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5683 setverdict(pass);
5684}
5685testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5686 var ConnHdlrPars pars;
5687 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005688 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005689
5690 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5691 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5692 vc_conn.done;
5693}
5694
5695/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005696private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005697 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005698 var integer pcu_conn_id := -1;
5699
5700 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5701
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005702 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5703 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5704 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005705 setverdict(pass);
5706}
5707testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5708 var ConnHdlrPars pars;
5709 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005710 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005711
5712 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5713 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5714 vc_conn.done;
5715}
5716
5717/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005718private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005719 var PCUIF_Message first_info;
5720 var integer ts_nr := g_chan_nr.tn;
5721 var integer trx_nr := 0;
5722 var integer bts_nr := 0;
5723 var integer pcu_conn_id := -1;
5724
5725 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5726
5727 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005728 /* Send a second Chan Activ and expect it to be NACKed */
5729 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5730 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005731 setverdict(pass);
5732}
5733testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5734 var ConnHdlrPars pars;
5735 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005736 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005737
5738 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5739 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5740 vc_conn.done;
5741}
5742
5743/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005744private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005745 var PCUIF_Message first_info;
5746 var integer ts_nr := g_chan_nr.tn;
5747 var integer trx_nr := 0;
5748 var integer bts_nr := 0;
5749 var integer pcu_conn_id := -1;
5750 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5751
5752 /* register for the TCH/F channel number */
5753 f_rslem_register(0, chan_nr);
5754
5755 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5756
5757 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5758 "RSL CHAN ACT");
5759 setverdict(pass);
5760}
5761testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5762 var ConnHdlrPars pars;
5763 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005764 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005765
5766 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5767 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5768 vc_conn.done;
5769}
5770
5771/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005772private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005773 var PCUIF_Message first_info;
5774 var integer ts_nr := g_chan_nr.tn;
5775 var integer trx_nr := 0;
5776 var integer bts_nr := 0;
5777 var integer pcu_conn_id := -1;
5778 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5779 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5780
5781 /* register for the TCH/H channel numbers */
5782 f_rslem_register(0, chan_nr[0]);
5783 f_rslem_register(0, chan_nr[1]);
5784
5785 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5786
5787 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5788 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5789 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5790 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5791 setverdict(pass);
5792}
5793testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5794 var ConnHdlrPars pars;
5795 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005796 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005797
5798 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5799 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5800 vc_conn.done;
5801}
5802
Harald Welte9bbbfb52018-04-05 09:33:19 +02005803/***********************************************************************
5804 * IPA Style Dynamic Timeslot Support
5805 ***********************************************************************/
5806
5807private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5808runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005809 /* Expect BTS to immediately acknowledge activation as PDCH */
5810 PCU.clear;
5811 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5812 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005813 timer T_wait := 2.0;
5814 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005815 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005816 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005817 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005818 [] T_wait.timeout {
5819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5820 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5821 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005822 }
5823 /* try to activate this PDCH from the PCU point of view */
5824 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5825 /* FIXME: is there a response? */
5826
5827 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5828}
5829
5830private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5831runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005832 /* Send RSL CHAN REL (deactivate) */
5833 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5834 PCU.clear;
5835 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005836 timer T_wait := 2.0;
5837 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005838 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005839 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005840 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005841 [] T_wait.timeout {
5842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5843 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5844 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005845 }
5846 /* Emulate PCU asking BTS to deactivate PDCH */
5847 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5848 alt {
5849 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5850 setverdict(pass);
5851 }
5852 [] RSL.receive { repeat; }
5853 }
5854}
5855
5856/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005857private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005858 var PCUIF_Message first_info;
5859 var integer ts_nr := g_chan_nr.tn;
5860 var integer trx_nr := 0;
5861 var integer bts_nr := 0;
5862 var integer pcu_conn_id := -1;
5863
5864 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5865
5866 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5867 f_sleep(3.0);
5868 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5869
5870 setverdict(pass);
5871
5872}
5873testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5874 var ConnHdlrPars pars;
5875 var ConnHdlr vc_conn;
5876 f_init();
5877
5878 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5879 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5880 vc_conn.done;
5881}
5882
5883/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005884private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005885 var PCUIF_Message first_info;
5886 var integer ts_nr := g_chan_nr.tn;
5887 var integer trx_nr := 0;
5888 var integer bts_nr := 0;
5889 var integer pcu_conn_id := -1;
5890
5891 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5892
5893 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5894 "RSL CHAN ACT");
5895 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5896 "RF CHAN REL", true);
5897 setverdict(pass);
5898}
5899testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5900 var ConnHdlrPars pars;
5901 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005902 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005903
5904 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5905 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5906 vc_conn.done;
5907}
5908
5909/* 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 +07005910private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005911 var PCUIF_Message first_info;
5912 var integer ts_nr := g_chan_nr.tn;
5913 var integer trx_nr := 0;
5914 var integer bts_nr := 0;
5915 var integer pcu_conn_id := -1;
5916
5917 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5918
5919 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5920 "RSL CHAN ACT");
5921
5922 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5923 alt {
5924 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5925 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005926 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005927 }
5928 [] RSL.receive { repeat; }
5929 }
5930
5931 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5932 "RF CHAN REL", true);
5933 setverdict(pass);
5934}
5935testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5936 var ConnHdlrPars pars;
5937 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005938 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005939
5940 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5941 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5942 vc_conn.done;
5943}
5944
5945/* 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 +07005946private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005947 var PCUIF_Message first_info;
5948 var integer ts_nr := g_chan_nr.tn;
5949 var integer trx_nr := 0;
5950 var integer bts_nr := 0;
5951 var integer pcu_conn_id := -1;
5952
5953 /* register for the TCH/F channel number */
5954 f_rslem_register(0, g_chan_nr);
5955
5956 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5957
5958 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5959
5960 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5961 "RSL CHAN ACT");
5962
5963 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5964
5965 setverdict(pass);
5966}
5967testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5968 var ConnHdlrPars pars;
5969 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005970 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005971
5972 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5973 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5974 vc_conn.done;
5975}
5976
5977
Harald Welte0472ab42018-03-12 15:02:26 +01005978/***********************************************************************
5979 * LAPDm / RLL related
5980 ***********************************************************************/
5981
5982private function f_tx_lapdm(template (value) LapdmFrame l,
5983 template (value) RslLinkId link_id) runs on ConnHdlr {
5984 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005985 var template (value) SacchL1Header l1h;
5986
5987 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005988 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005989 /* Compose dummy L1 header */
5990 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5991 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 +02005992 } else {
5993 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005994 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 +01005995 }
Harald Welte0472ab42018-03-12 15:02:26 +01005996}
5997
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005998private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005999 uint3_t sapi,
6000 RslLinkId link_id,
6001 octetstring l3,
6002 boolean exp
6003}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006004private type record of RllTestCase RllTestCases;
6005private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
6006 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006007 sapi := sapi,
6008 link_id := id,
6009 l3 := l3,
6010 exp := exp
6011}
6012
6013/* execute the same callback function with a set of different parameters (tcs) on a
6014 * variety of logical channels */
6015private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6016 var ConnHdlrPars pars;
6017 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006018 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006019
6020 /* test on each of the channels we have */
6021 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6022 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6023
6024 /* test each of the test cases on the current channel */
6025 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6026 pars.spec.rll := tcs[j];
6027 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6028 vc_conn := f_start_handler(fn, pars);
6029 vc_conn.done;
6030 }
6031 }
6032
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006033 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006034}
6035
6036/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6037private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6038 var RllTestCase tc := g_pars.spec.rll;
6039 timer T := 3.0;
6040
6041 f_l1_tune(L1CTL);
6042 RSL.clear;
6043
6044 /* activate the logical channel */
6045 f_est_dchan();
6046 L1CTL.clear;
6047
6048 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6049 T.start;
6050 alt {
6051 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6052 if (tc.exp) {
6053 setverdict(pass);
6054 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006056 }
6057 }
6058 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6059 if (tc.exp) {
6060 setverdict(pass);
6061 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006063 }
6064 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006065 /* We also expect to receive the measurements */
6066 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006067 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006069 }
6070 [not tc.exp] T.timeout {
6071 setverdict(pass);
6072 }
6073 }
6074
6075 f_rsl_chan_deact();
6076 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6077 f_rslem_unregister(0, g_chan_nr);
6078}
6079testcase TC_rll_est_ind() runs on test_CT {
6080 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006081 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006082 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006083 /* normal SAPI0 establishment */
6084 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006085 /* SAPI 3 doesn't support contention resolution */
6086 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6087 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6088 /* normal SAPI3 establishment on main DCCH */
6089 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6090 /* normal SAPI3 establishment on SACCH */
6091 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6092 };
6093 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6094}
6095
6096/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6097private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6098 var RllTestCase tc := g_pars.spec.rll;
6099 var L1ctlDlMessage dl;
6100 timer T := 3.0;
6101
6102 f_l1_tune(L1CTL);
6103 RSL.clear;
6104
6105 /* activate the logical channel */
6106 f_est_dchan();
6107 L1CTL.clear;
6108
6109 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6110 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6111 T.start;
6112 alt {
6113 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6114 var LapdmFrame lapdm;
6115 var octetstring l2 := dl.payload.data_ind.payload;
6116 if (dl.dl_info.link_id.c == SACCH) {
6117 /* remove L1 header */
6118 l2 := substr(l2, 2, lengthof(l2)-2);
6119 }
6120 lapdm.ab := dec_LapdmFrameAB(l2);
6121 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6122 setverdict(pass);
6123 } else {
6124 repeat;
6125 }
6126 }
6127 [] L1CTL.receive { repeat; }
6128 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006130 }
6131 }
6132
6133 f_rsl_chan_deact();
6134 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6135 f_rslem_unregister(0, g_chan_nr);
6136}
6137testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6138 var RllTestCases tcs := {
6139 /* normal SAPI3 establishment on main DCCH */
6140 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6141 };
6142 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6143}
6144testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6145 var RllTestCases tcs := {
6146 /* normal SAPI3 establishment on SACCH */
6147 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6148 }
6149 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6150}
6151
6152/* altstep to receive a LAPDm frame matching the given template */
6153private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6154 var L1ctlDlMessage dl;
6155 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6156 var LapdmFrame lapdm;
6157 var octetstring l2 := dl.payload.data_ind.payload;
6158 if (dl.dl_info.link_id.c == SACCH) {
6159 /* remove L1 header */
6160 l2 := substr(l2, 2, lengthof(l2)-2);
6161 }
6162 if (ischosen(exp.ab)) {
6163 lapdm.ab := dec_LapdmFrameAB(l2);
6164 } else if (ischosen(exp.b4)) {
6165 lapdm.b4 := dec_LapdmFrameB4(l2);
6166 } else if (ischosen(exp.bbis)) {
6167 lapdm.bbis := dec_LapdmFrameBbis(l2);
6168 }
6169 log("Rx LAPDm ", lapdm);
6170 if (match(lapdm, exp)) {
6171 setverdict(pass);
6172 } else {
6173 repeat;
6174 }
6175 }
6176 [] L1CTL.receive { repeat; }
6177}
6178private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6179 timer T := t;
6180 T.start;
6181 alt {
6182 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006183 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006184 }
6185 [] as_l1_exp_lapdm(exp);
6186 }
6187}
6188
6189/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6190private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6191 /* send SABM from MS -> BTS */
6192 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6193 /* expect RLL EST IND on Abis */
6194 alt {
6195 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6196 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6197 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006199 }
6200 [] RSL.receive { repeat; }
6201 }
6202 /* expect UA from BTS -> MS */
6203 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6204}
6205
6206/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6207private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6208 var RllTestCase tc := g_pars.spec.rll;
6209
6210 f_l1_tune(L1CTL);
6211 RSL.clear;
6212
6213 /* activate the logical channel */
6214 f_est_dchan();
6215 L1CTL.clear;
6216
6217 /* first establish the link-layer */
6218 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6219
6220 /* then send the DISC */
6221 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6222 /* ... and expect the REL IND on the RSL side */
6223 alt {
6224 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6225 setverdict(pass);
6226 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006227 /* We also expect to receive the measurements */
6228 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006229 }
6230
6231 /* release the channel */
6232 f_rsl_chan_deact();
6233 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6234 f_rslem_unregister(0, g_chan_nr);
6235}
6236testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6237 var RllTestCases tcs := {
6238 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6239 };
6240 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6241}
6242
6243testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6244 var RllTestCases tcs := {
6245 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6246 };
6247 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6248}
6249testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6250 var RllTestCases tcs := {
6251 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6252 };
6253 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6254}
6255testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6256 var RllTestCases tcs := {
6257 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6258 };
6259 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6260}
6261
6262/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6263private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6264 var RllTestCase tc := g_pars.spec.rll;
6265 f_l1_tune(L1CTL);
6266 RSL.clear;
6267
6268 /* activate the logical channel */
6269 f_est_dchan();
6270 L1CTL.clear;
6271
6272 /* first establish the link-layer */
6273 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6274
6275 /* then send the REL REQ via RSL */
6276 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6277 /* ... and expect the DISC on the Um side */
6278 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006279 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006280 /* FIXME: send a UA in resposne to the DISC */
6281 }
6282 }
6283
6284 /* release the channel */
6285 f_rsl_chan_deact();
6286 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6287 f_rslem_unregister(0, g_chan_nr);
6288}
6289testcase TC_rll_rel_req() runs on test_CT {
6290 var RllTestCases tcs := {
6291 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6292 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6293 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6294 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6295 };
6296 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6297}
6298
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006299/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006300testcase TC_rll_data_req() runs on test_CT {
6301}
6302
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006303/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006304testcase TC_rll_data_ind() runs on test_CT {
6305}
6306
6307/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6308private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6309 var RllTestCase tc := g_pars.spec.rll;
6310
6311 f_l1_tune(L1CTL);
6312 RSL.clear;
6313
6314 f_est_dchan();
6315 L1CTL.clear;
6316
6317 /* Send UNITDATA REQ on RSL side */
6318 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6319 /* Expect it to arrive on the other side */
6320 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006321 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006322 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006323 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006324 }
6325
6326 /* release the channel */
6327 f_rsl_chan_deact();
6328 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6329 f_rslem_unregister(0, g_chan_nr);
6330}
6331testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6332 var octetstring l3 := f_rnd_octstring(15);
6333 var RllTestCases tcs := {
6334 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6335 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6336 };
6337 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6338}
6339testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6340 var octetstring l3 := f_rnd_octstring(19);
6341 var RllTestCases tcs := {
6342 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6343 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6344 };
6345 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6346}
6347
6348/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6349private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6350 var RllTestCase tc := g_pars.spec.rll;
6351
6352 f_l1_tune(L1CTL);
6353 RSL.clear;
6354
6355 f_est_dchan();
6356 L1CTL.clear;
6357
6358 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006359 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006360 /* Expdct RLL UNITDATA IND on RSL side */
6361 alt {
6362 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6363 setverdict(pass);
6364 }
6365 [] RSL.receive { repeat; }
6366 }
6367
6368 /* release the channel */
6369 f_rsl_chan_deact();
6370 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6371 f_rslem_unregister(0, g_chan_nr);
6372}
6373testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006374 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006375 var RllTestCases tcs := {
6376 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6377 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6378 };
6379 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6380}
6381testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6382 var octetstring l3 := f_rnd_octstring(18);
6383 var RllTestCases tcs := {
6384 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6385 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6386 };
6387 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6388}
6389
Harald Weltee613f962018-04-18 22:38:16 +02006390/***********************************************************************
6391 * Encryption Related
6392 ***********************************************************************/
6393
6394/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006395private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006396 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6397 if (link_id.c == SACCH) {
6398 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6399 } else {
6400 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6401 }
6402}
6403
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006404/* Expect (or not expect) other kinds of messages */
6405private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6406 [exp_any] RSL.receive { repeat; }
6407 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006409 }
6410}
6411
Harald Weltee613f962018-04-18 22:38:16 +02006412/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006413private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006414 RslLinkId link_id,
6415 octetstring l3,
6416 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006417 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006418) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006419 timer T := 3.0;
6420 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6421 T.start;
6422 /* Expect RLL UNITDATA IND on RSL side */
6423 alt {
6424 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6425 setverdict(pass);
6426 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006427 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006428 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006429 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006431 }
Harald Weltee613f962018-04-18 22:38:16 +02006432 }
6433}
6434
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006435/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6436private function f_data_mo(
6437 RslLinkId link_id,
6438 boolean p, uint3_t nr, uint3_t ns,
6439 octetstring l3,
6440 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006441 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006442) runs on ConnHdlr {
6443 timer T := 3.0;
6444 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6445 T.start;
6446 /* Expect RLL DATA IND on RSL side */
6447 alt {
6448 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6449 setverdict(pass);
6450 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006451 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006452 [] as_rsl_any_ind(exp_any);
6453 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006455 }
6456 }
6457}
6458
Harald Weltee613f962018-04-18 22:38:16 +02006459/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006460private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006461 f_l1_tune(L1CTL);
6462 f_est_dchan(true);
6463
6464 /* now we actually need to transmit some data both ways to check if the encryption works */
6465 var L1ctlDlMessage dl;
6466
Stefan Sperling603d98e2018-07-25 16:47:28 +02006467 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006468 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6469
6470 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6471 f_unitdata_mt(link_id, l3);
6472
6473 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6474 f_unitdata_mo(link_id, l3);
6475
6476 /* release the channel */
6477 f_rsl_chan_deact();
6478 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6479 f_rslem_unregister(0, g_chan_nr);
6480}
6481testcase TC_chan_act_a51() runs on test_CT {
6482 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6483 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6484 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6485}
6486testcase TC_chan_act_a52() runs on test_CT {
6487 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6488 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6489 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6490}
6491testcase TC_chan_act_a53() runs on test_CT {
6492 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6493 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6494 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6495}
6496
Eric Wildf1827a72019-05-28 17:37:35 +02006497/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6498 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 +07006499private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006500 f_l1_tune(L1CTL);
6501 f_est_dchan(true);
6502
6503 /* now we actually need to transmit some data both ways to check if the encryption works */
6504 var L1ctlDlMessage dl;
6505
6506 var octetstring l3 := f_rnd_octstring(20);
6507 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6508
6509 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6510 f_unitdata_mt(link_id, l3);
6511
6512 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6513 f_unitdata_mo(link_id, l3);
6514
6515 var RSL_Message rsl;
6516 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6517
6518 /* modify key to break proper encryption */
6519 g_pars.encr.key := f_rnd_octstring(8);
6520 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6521 rsl.ies := rsl.ies & { ei };
6522 RSL.send(rsl);
6523
6524 timer T0 := 1.0;
6525 T0.start;
6526 /* Expect RSL MODIFY ACK */
6527 alt {
6528 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6529 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6530 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6531 }
6532 [] T0.timeout {
6533 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6534 }
6535 }
6536
6537 var octetstring l3msg := f_rnd_octstring(15);
6538 timer T1 := 3.0;
6539 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6540 due to broken encryption */
6541 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6542 T1.start;
6543 alt {
6544 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6546 }
6547 [] T1.timeout {
6548 setverdict(pass);
6549 }
6550 }
6551
6552 /* release the channel */
6553 f_rsl_chan_deact();
6554 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6555 f_rslem_unregister(0, g_chan_nr);
6556}
6557testcase TC_rsl_modify_encr() runs on test_CT {
6558 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6559 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6560 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6561}
Harald Weltee613f962018-04-18 22:38:16 +02006562
6563/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006564private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006565 /* L3 payload doesn't matter, as it is passed transparently */
6566 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6567 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6568 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6569
6570 f_l1_tune(L1CTL);
6571
6572 /* first establish a dedicated channel in the clear */
6573 f_est_dchan(false);
6574
6575 /* Establish ABM */
6576 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6577
6578 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6579 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6580 /* expect the L3 to arrive still unencrypted on the MS side */
6581 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6582
6583 /* configure L1 to apply ciphering */
6584 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6585 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6586
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006587 /* send first ciphered I-frame in response and expect it on RSL */
6588 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006589
6590 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6591 * and hence enable encryption also on the downlink */
6592
6593 /* expect bi-directional communication work in encrypted mode */
6594 f_unitdata_mo(link_id, f_rnd_octstring(15));
6595 f_unitdata_mt(link_id, f_rnd_octstring(15));
6596
6597 /* release the channel */
6598 f_rsl_chan_deact();
6599 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6600 f_rslem_unregister(0, g_chan_nr);
6601}
6602testcase TC_encr_cmd_a51() runs on test_CT {
6603 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6604 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6605 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6606}
6607testcase TC_encr_cmd_a52() runs on test_CT {
6608 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6609 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6610 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6611}
6612testcase TC_encr_cmd_a53() runs on test_CT {
6613 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6614 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6615 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6616}
6617
6618private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6619 var LapdmFrame lf;
6620 var octetstring reenc;
6621
6622 /* decode the LAPDm frame */
6623 if (ischosen(exp_match.ab)) {
6624 lf.ab := dec_LapdmFrameAB(enc);
6625 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006626 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006627 }
6628
6629 /* check if decoder result matches expectation */
6630 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006632 } else {
6633 log(name, ": matched");
6634 setverdict(pass);
6635 }
6636
6637 /* test if re-encoded frame equals original input */
6638 reenc := enc_LapdmFrame(lf);
6639 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006640 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006641 } else {
6642 setverdict(pass);
6643 }
6644}
6645
6646testcase TC_lapdm_selftest() runs on test_CT {
6647 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6648 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6649 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6650 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6651 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6652 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6653 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6654}
6655
Stefan Sperling4880be42018-08-07 18:12:59 +02006656/***********************************************************************
6657 * DTX Related (see GSM 05.08, section 8.3)
6658 ***********************************************************************/
6659
6660/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006661private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006662 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6663 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6664 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6665 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6666}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006667private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006668 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6669 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6670}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006671private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006672 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6673 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6674 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6675 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6676}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006677private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006678 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6679 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6680 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6681 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6682 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6683 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6684 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6685 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6686}
6687
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006688private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006689 var L1ctlDlMessage dl;
6690 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6691 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6692 var GsmFrameNumber first_fn;
6693 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006694 var integer nfill_frames_sacch := 0;
6695 var integer nfill_frames_nonsacch := 0;
6696 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006697 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6698 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006699 const integer frame_dtx_tchf_mod := 104;
6700 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6701 * which operates in terms of blocks rather than frames. */
6702 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6703 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006704 timer T := 5.0;
6705
6706 f_l1_tune(L1CTL);
6707 RSL.clear;
6708 L1CTL.clear;
6709
6710 /* activate TCHF signalling channel */
6711 f_est_dchan(false);
6712
6713 T.start;
6714 alt {
6715 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6716 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6717 var octetstring l2 := dl.payload.data_ind.payload;
6718
6719 if (is_first_frame) {
6720 is_first_frame := false;
6721 first_fn := dl.dl_info.frame_nr;
6722 }
6723
6724 if (dl.dl_info.link_id.c == SACCH) {
6725 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6726 if (not match(l2_fill_frame_sacch, l2)) {
6727 repeat;
6728 }
6729 } else if (not match(l2_fill_frame, l2)) {
6730 repeat;
6731 }
6732
6733 if (dtxd) {
6734 if (not f_g_chan_is_tchf()) {
6735 T.stop;
6736 f_rsl_chan_deact();
6737 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006738 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 +02006739 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006740 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006741 T.stop;
6742 f_rsl_chan_deact();
6743 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006744
6745 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6746 * 2 SACCH, 1 TCH/F */
6747 expected_fill_frames := 3;
6748
6749 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6750 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6751 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006753 } else {
6754 setverdict(pass);
6755 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006756 } else {
6757 if (dl.dl_info.link_id.c == SACCH) {
6758 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006759 repeat;
6760 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006761 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6762 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6763 * we should only see the subset of frames numbers which correspond to a block boundary.
6764 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6765 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6766 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6767 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6768 repeat;
6769 }
6770 }
6771 log("Received DTX TCH fill frame with bad frame number: ", fn,
6772 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6773 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6774 f_rsl_chan_deact();
6775 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006777 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006778 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006779 if (dl.dl_info.link_id.c == SACCH) {
6780 nfill_frames_sacch := nfill_frames_sacch + 1;
6781 } else {
6782 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6783 }
6784 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006785 T.stop;
6786 if (f_g_chan_is_tchf()) {
6787 /* Without DTX we can expect 25 fill frames for every 104 frames.
6788 * (24 FACCH + 1 SACCH filling) */
6789 expected_fill_frames := 25;
6790 } else if (f_g_chan_is_tchh()) {
6791 /* We can expect 2 fill frames for every 104 frames. */
6792 expected_fill_frames := 2;
6793 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6794 /* We can expect 5 fill frames for every 104 frames. */
6795 expected_fill_frames := 5;
6796 } else {
6797 f_rsl_chan_deact();
6798 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006800 }
6801
6802 f_rsl_chan_deact();
6803 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006804
6805 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006806 setverdict(pass);
6807 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006808 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6809 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006810 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006811 }
6812 } else {
6813 repeat;
6814 }
6815 }
6816 }
6817 [] L1CTL.receive { repeat; }
6818 [] T.timeout {
6819 f_rsl_chan_deact();
6820 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006821 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006822 }
6823 }
6824}
6825
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006826private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006827 f_test_l2_fill_frames(false);
6828}
6829
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006830private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006831 f_test_l2_fill_frames(true);
6832}
6833
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006834private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006835 var ConnHdlr vc_conn;
6836 var ConnHdlrPars pars;
6837 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006838 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006839 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6840 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6841 if (dtxd) {
6842 if (i >= 4) { /* DTX is only allowed on TCH/F */
6843 break;
6844 }
6845 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6846 } else {
6847 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6848 }
6849 vc_conn.done;
6850 }
6851}
6852
6853/* Verify that L2 fill frames are sent on TCH in signaling mode if
6854 * there is nothing to transmit while DTX is disabled on downlink. */
6855testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6856 f_tch_sign_l2_fill_frame(false);
6857}
6858
6859/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6860 * there is nothing to transmit while DTX is enabled on downlink. */
6861testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6862 f_tch_sign_l2_fill_frame(true);
6863}
Harald Welte0472ab42018-03-12 15:02:26 +01006864
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006865testcase TC_chopped_ipa_ping() runs on test_CT {
6866 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6867}
6868
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006869testcase TC_chopped_ipa_payload() runs on test_CT {
6870 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6871}
6872
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006873
6874/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6875 * Return value: Measurement Report to be sent (encoded octetstring). */
6876type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6877 runs on ConnHdlr return octetstring;
6878
6879private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6880runs on ConnHdlr {
6881 var L1ctlDlMessage l1_dl;
6882 var SacchL1Header l1h;
6883 var octetstring l2;
6884
6885 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6886 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6887 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6888 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6889
6890 /* Pass it to the user specified call-back function */
6891 l2 := cb.apply(l1h, num_blocks);
6892 /* Send a Measurement Report generated by the call-back */
6893 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6894 l1_dl.dl_info.link_id,
6895 l1h, l2));
6896
6897 /* Shall we keep going? */
6898 num_blocks := num_blocks - 1;
6899 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6900 if (num_blocks > 0) { repeat; }
6901 }
6902 [] L1CTL.receive { repeat; }
6903}
6904
6905private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6906runs on ConnHdlr return octetstring {
6907 /* Command the L1 to apply received parameters */
6908 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6909
6910 /* Dummy measurement report (the results are invalid) */
6911 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6912}
6913
6914private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6915runs on ConnHdlr return octetstring {
6916 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6917 setverdict(fail, "Unexpected MS Power level change: ",
6918 g_pars.l1_pars.ms_power_level, " -> ",
6919 l1h.ms_power_lvl);
6920 }
6921
6922 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6923}
6924
6925/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6926private function f_TC_ms_pwr_ctrl_constant(charstring id)
6927runs on ConnHdlr {
6928 var integer num_blocks := 8;
6929 timer T := int2float(num_blocks);
6930
6931 f_l1_tune(L1CTL);
6932 RSL.clear;
6933
6934 /* These IEs are needed for autonomous MS power control */
6935 var template (value) RSL_IE_List ies := {
6936 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6937 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6938 }),
6939 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6940 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6941 })
6942 };
6943
6944 /* Ensure that 'rx-current' equals 'rx-target' */
6945 f_trxc_fake_rssi(mp_uplink_power_target);
6946
6947 /* Establish a dedicated channel */
6948 f_est_dchan(more_ies := valueof(ies));
6949
6950 L1CTL.clear;
6951 T.start;
6952 alt {
6953 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
6954 [] T.timeout {
6955 setverdict(fail, "Not all SACCH blocks were processed in time, ",
6956 num_blocks, " were not handled");
6957 }
6958 }
6959}
6960testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
6961 var ConnHdlr vc_conn;
6962 var ConnHdlrPars pars;
6963
6964 f_init();
6965
6966 /* Explicitly configure the Uplink power target (in dBm) */
6967 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
6968
6969 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
6970 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6971 log(testcasename(), ": starting on ", pars.chan_nr);
6972
6973 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
6974 pars, trxc_comp := true);
6975 vc_conn.done;
6976 }
6977
6978 /* No need to reset Uplink power parameters - the IUT restarts anyway */
6979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6980}
6981
Harald Welte0472ab42018-03-12 15:02:26 +01006982/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6983/* protocol error as per 44.006 */
6984/* link layer failure (repetition of I-frame N200 times without ACK */
6985/* repetition of SABM or DISC N200 times without ACK */
6986/* receptiom of SABM in multi-frame established state */
6987
6988
Harald Welte68e495b2018-02-25 00:05:57 +01006989/* TODO Areas:
6990
6991* channel activation
6992** with BS_Power / MS_Power, bypassing power control loop
6993** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006994** with timing advance from initial activation on
6995* mode modify
6996** encryption
6997** multirate
6998* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006999** unsupported algorithm
7000* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007001* BS Power Control
7002* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007003* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007004* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007005** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007006* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007007** DATA_IND from BTS->PCU
7008** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007009
7010*/
Harald Welte70767382018-02-21 12:16:40 +01007011
7012control {
7013 execute( TC_chan_act_stress() );
7014 execute( TC_chan_act_react() );
7015 execute( TC_chan_deact_not_active() );
7016 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007017 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007018 execute( TC_sacch_filling() );
7019 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007020 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007021 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007022 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007023 execute( TC_sacch_chan_act_ho_async() );
7024 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007025 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007026 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007027 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007028 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007029 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007030 execute( TC_rach_load_idle_thresh0() );
7031 execute( TC_rach_load_idle_below_thresh() );
7032 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007033 execute( TC_meas_res_speech_tchf() );
7034 execute( TC_meas_res_speech_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007035 execute( TC_meas_res_sign_tchf() );
7036 execute( TC_meas_res_sign_tchh() );
7037 execute( TC_meas_res_sign_sdcch4() );
7038 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007039 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007040 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007041 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007042 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007043 execute( TC_rsl_bs_pwr_static_ass() );
7044 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007045 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007046 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007047 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007048 execute( TC_rsl_ms_pwr_dyn_up() );
7049 execute( TC_rsl_ms_pwr_dyn_down() );
7050 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7051 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007052 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007053 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007054 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007055 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007056 execute( TC_paging_imsi_80percent() );
7057 execute( TC_paging_tmsi_80percent() );
7058 execute( TC_paging_imsi_200percent() );
7059 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007060 execute( TC_rsl_protocol_error() );
7061 execute( TC_rsl_mand_ie_error() );
7062 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007063 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007064 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007065 execute( TC_si_sched_2bis() );
7066 execute( TC_si_sched_2ter() );
7067 execute( TC_si_sched_2ter_2bis() );
7068 execute( TC_si_sched_2quater() );
7069 execute( TC_si_sched_13() );
7070 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007071 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007072 execute( TC_ipa_crcx_twice_not_active() );
7073 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007074 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007075 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007076
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007077 if (mp_pcu_socket != "") {
7078 execute( TC_pcu_act_req() );
7079 execute( TC_pcu_act_req_wrong_ts() );
7080 execute( TC_pcu_act_req_wrong_bts() );
7081 execute( TC_pcu_act_req_wrong_trx() );
7082 execute( TC_pcu_deact_req() );
7083 execute( TC_pcu_deact_req_wrong_ts() );
7084 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007085 if (mp_l1_supports_gprs) {
7086 execute( TC_pcu_data_req_pdtch() );
7087 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007088 execute( TC_pcu_data_req_wrong_bts() );
7089 execute( TC_pcu_data_req_wrong_trx() );
7090 execute( TC_pcu_data_req_wrong_ts() );
7091 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007092 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007093 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007094 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007095 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007096 execute( TC_pcu_data_req_imm_ass_pch() );
7097 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007098 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007099 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007100 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007101 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007102 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007103 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007104 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007105 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007106 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007107 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007108 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007109 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007110 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007111 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007112 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007113 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007114 execute( TC_dyn_osmo_pdch_act_deact() );
7115 execute( TC_dyn_osmo_pdch_double_act() );
7116 execute( TC_dyn_ipa_pdch_act_deact() );
7117 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7118
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007119 if (PCUIF_Types.mp_pcuif_version >= 10) {
7120 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007121 execute( TC_pcu_socket_nsvc_ipv4() );
7122 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007123 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007124 } else {
7125 log("PCU socket path not available, skipping PCU tests");
7126 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007127
Harald Welte3d04ae62018-04-04 20:29:05 +02007128 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007129 execute( TC_dyn_osmo_pdch_tchf_act() );
7130 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007131 execute( TC_dyn_ipa_pdch_tchf_act() );
7132 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007133
7134 execute( TC_rll_est_ind() );
7135 execute( TC_rll_est_req_DCCH_3() );
7136 execute( TC_rll_est_req_ACCH_3() );
7137 execute( TC_rll_rel_ind_DCCH_0() );
7138 execute( TC_rll_rel_ind_DCCH_3() );
7139 execute( TC_rll_rel_ind_ACCH_0() );
7140 execute( TC_rll_rel_ind_ACCH_3() );
7141 execute( TC_rll_rel_req() );
7142 execute( TC_rll_unit_data_req_DCCH() );
7143 execute( TC_rll_unit_data_req_ACCH() );
7144 execute( TC_rll_unit_data_ind_DCCH() );
7145 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007146
7147 execute( TC_chan_act_a51() );
7148 execute( TC_chan_act_a52() );
7149 execute( TC_chan_act_a53() );
7150 execute( TC_encr_cmd_a51() );
7151 execute( TC_encr_cmd_a52() );
7152 execute( TC_encr_cmd_a53() );
7153
Harald Welteee25aae2019-05-19 14:32:37 +02007154 execute( TC_err_rep_wrong_mdisc() );
7155 execute( TC_err_rep_wrong_msg_type() );
7156 execute( TC_err_rep_wrong_sequence() );
7157
Harald Weltee613f962018-04-18 22:38:16 +02007158 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007159
7160 execute( TC_tch_sign_l2_fill_frame() );
7161 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007162
7163 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007164 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007165
7166 execute( TC_ms_pwr_ctrl_constant() );
Harald Welte70767382018-02-21 12:16:40 +01007167}
7168
7169
7170}