blob: aa0618028d4279ed9c9d0240191d8765f8b36b64 [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;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100108 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200109 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200110 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200111 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
112 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700113 /* how many transceivers do we expect to connect */
114 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700115 /* frequency hopping status */
116 boolean mp_freq_hop_enabled := false;
117 /* frequency hopping parameters */
118 FreqHopConfig mp_fh_config;
Harald Welte70767382018-02-21 12:16:40 +0100119}
120
Harald Welte629cc6b2018-03-11 17:19:05 +0100121type record of RslChannelNr ChannelNrs;
122
Harald Welte70767382018-02-21 12:16:40 +0100123type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100124 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100125 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100126 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100127 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100128 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100129 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100130
131 /* L1CTL port (for classic tests) */
132 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100133
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700134 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700135 port TRXC_CODEC_PT BTS_TRXC;
136 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100137
Harald Weltef50e3ae2018-09-10 10:27:56 +0200138 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100139 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200140 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100141
Harald Welte883340c2018-02-28 18:59:29 +0100142 /* PCU Interface of BTS */
143 port PCUIF_CODEC_PT PCU;
144 var integer g_pcu_conn_id;
145 /* Last PCU INFO IND we received */
146 var PCUIF_Message g_pcu_last_info;
147
Harald Welte48494ca2018-02-25 16:59:50 +0100148 /* SI configuration */
149 var SystemInformationConfig si_cfg := {
150 bcch_extended := false,
151 si1_present := false,
152 si2bis_present := false,
153 si2ter_present := false,
154 si2quater_present := false,
155 si7_present := false,
156 si8_present := false,
157 si9_present := false,
158 si13_present := false,
159 si13alt_present := false,
160 si15_present := false,
161 si16_present := false,
162 si17_present := false,
163 si2n_present := false,
164 si21_present := false,
165 si22_present := false
166 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100167
168 /* all logical channels available on the BTS */
169 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100170 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100171}
172
173/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200174type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100175 port L1CTL_PT L1CTL;
176
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700177 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700178 port TRXC_CODEC_PT BTS_TRXC;
179 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100180
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200181 /* port to be initialized optionally to access BSC VTY */
182 port TELNETasp_PT BSCVTY;
183
Harald Welte70767382018-02-21 12:16:40 +0100184 timer g_Tguard;
185 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
186
187 var ConnHdlrPars g_pars;
188 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100189 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200190
191 /* PCU Interface of BTS */
192 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100193}
194
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700195private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700196 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200197 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700198 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200199 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700200 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200201 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700202 timer T;
203
Harald Welte70767382018-02-21 12:16:40 +0100204 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
205 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
206
207 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
208 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
209 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
210
211 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
212 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700213
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700214 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700215 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700216 T.start(mp_ipa_up_timeout);
217 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700218 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700219 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
220 /* Make sure that all transceivers use unique stream ID */
221 if (trx_mask[enum2int(ev.sid)] == '1'B) {
222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
223 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
224 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700225
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700226 trx_mask[enum2int(ev.sid)] := '1'B;
227 trx_count := trx_count + 1;
228
229 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200230 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700231 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200232 /* This message (RF RESource INDication) is sent by the IUT itself */
233 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
234 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
235 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
236 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
237 }
238 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
240 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
241 }
242
243 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
244 rfind_count := rfind_count + 1;
245 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
246 if (rfind_count < mp_transceiver_num) { repeat; }
247 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700248 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
249 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
250 [] T.timeout {
251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
252 "Timeout waiting for RSL bring up");
253 }
254 }
Harald Welte70767382018-02-21 12:16:40 +0100255}
256
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700257friend type record FreqHopPars {
258 /* Whether frequency hopping is in use */
259 boolean enabled,
260 /* Mobile Allocation Index Offset / Hopping Sequence Number */
261 MaioHsn maio_hsn,
262 /* MA bitmap to be indicated in RR Immediate Assignment */
263 MobileAllocationLV ma_map,
264 /* The actual Mobile Allocation (ARFCN list) to be used */
265 L1ctlMA ma
266};
267
Harald Welte70767382018-02-21 12:16:40 +0100268type record ConnHdlrPars {
269 RslChannelNr chan_nr,
270 RSL_IE_ChannelMode chan_mode,
271 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100272 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200273 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200274 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700275 BtsBand bts0_band optional,
276
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700277 /* Frequency hopping parameters */
278 FreqHopPars fhp
279};
Harald Welte0472ab42018-03-12 15:02:26 +0100280
281/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700282private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100283 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100284}
285
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700286private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100287 max_retrans := RACH_MAX_RETRANS_7,
288 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100289 cell_barr_access := false,
290 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100291 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100292};
293
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700294private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100295 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200296 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100297 acs := '0'B,
298 neci := true,
299 rxlev_access_min := 0
300}
301
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700302private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100303 mcc_mnc := '262F42'H,
304 lac := 42
305}
306
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700307private template (value) GPRSIndicator ts_GPRSIndicator_def := {
308 ra_colour := 0,
309 si13_pos := '0'B
310}
311
312private template (value) SI3RestOctets ts_SI3RestOctets_def
313modifies ts_SI3RestOctets := {
314 gprs_ind := {
315 presence := CSN1_H,
316 ind := ts_GPRSIndicator_def
317 }
318}
319
320private template (value) SI4RestOctets ts_SI4RestOctets_def
321modifies ts_SI4RestOctets := {
322 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700323 presence := CSN1_H,
324 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700325 }
326}
327
Harald Welte7484fc42018-02-24 14:09:45 +0100328/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700329private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100330 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100331 payload := {
332 si3 := {
333 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100334 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100335 ctrl_chan_desc := {
336 msc_r99 := true,
337 att := true,
338 bs_ag_blks_res := 1,
339 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100340 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100341 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
342 spare := '00'B,
343 bs_pa_mfrms := 0, /* 2 multiframes */
344 t3212 := 1 /* 6 minutes */
345 },
Harald Welte82ccef72018-02-25 16:17:33 +0100346 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100347 dn_ind := false,
348 pwrc := false,
349 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100350 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100351 },
Harald Weltef10153f2018-02-25 16:34:05 +0100352 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100353 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200354 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100355 }
356 }
357}
Harald Welte70767382018-02-21 12:16:40 +0100358
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700359private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100360 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100361 payload := {
362 si2 := {
363 bcch_freq_list := '00000000000000000000000000000000'O,
364 ncc_permitted := '11111111'B,
365 rach_control := ts_RachCtrl_default
366 }
367 }
368}
369
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700370private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100371 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100372 payload := {
373 si4 := {
374 lai := ts_LAI_default,
375 cell_sel_par := ts_CellSelPar_default,
376 rach_control := ts_RachCtrl_default,
377 cbch_chan_desc := omit,
378 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200379 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100380 }
381 }
382}
383
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700384private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100385runs on test_CT {
386 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700387 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100388}
389
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700390private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100391runs on test_CT {
392 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
393 log("Setting ", rsl_si_type, ": ", si_dec);
394 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
395}
396
Harald Welte505cf9b2018-09-15 17:47:23 +0300397friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100398 map(self:BTSVTY, system:BTSVTY);
399 f_vty_set_prompts(BTSVTY);
400 f_vty_transceive(BTSVTY, "enable");
401}
402
Harald Welte505cf9b2018-09-15 17:47:23 +0300403friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200404 map(self:BSCVTY, system:BSCVTY);
405 f_vty_set_prompts(BSCVTY, "OsmoBSC");
406 f_vty_transceive(BSCVTY, "enable");
407}
408
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200409friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
410 map(self:BSCVTY, system:BSCVTY);
411 f_vty_set_prompts(BSCVTY, "OsmoBSC");
412 f_vty_transceive(BSCVTY, "enable");
413}
414
Harald Welte883340c2018-02-28 18:59:29 +0100415/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200416private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
417 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100418 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200419 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
420 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100421 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200422 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100424 }
425}
426
Harald Weltef26de0b2018-04-04 20:28:05 +0200427private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
428 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100429 timer T := 2.0;
430 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100431 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200432 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100433 return;
434 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200435 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100436
437 T.start;
438 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200439 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100440 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200441 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100442 }
443 }
444}
445
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700446private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
447 out integer trxc_conn_id) {
448 var Result res;
449
450 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
451 "", -1, -1, { udp := {} }, {});
452 if (not ispresent(res.connId)) {
453 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
454 "Could not connect to the control (TRXC) interface " &
455 "of FakeTRX, check your configuration");
456 }
457 trxc_conn_id := res.connId;
458}
459
Harald Welte70767382018-02-21 12:16:40 +0100460/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700461friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200462 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100463 g_AllChannels := {
464 /* TS 1..4: TCH/F */
465 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
466 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
467 /* TS 5: TCH/H */
468 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
469 /* TS 0: SDCCH/4 */
470 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
471 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
472 /* TS 6: SDCCH/8 */
473 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
474 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
475 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
476 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
477 };
478
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200479 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700480 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200481 g_AllChanTypes := {
482 /* TS 1..4: TCH/F */
483 valueof(ts_RslChanNr_Bm(1)),
484 /* TS 5: TCH/H */
485 valueof(ts_RslChanNr_Lm(5,1)),
486 /* TS 0: SDCCH/4 */
487 valueof(ts_RslChanNr_SDCCH4(0,2)),
488 /* TS 6: SDCCH/8 */
489 valueof(ts_RslChanNr_SDCCH8(6,4))
490 };
491 } else {
492 g_AllChanTypes := {
493 /* TS 1..4: TCH/F */
494 valueof(ts_RslChanNr_Bm(1)),
495 /* TS 0: SDCCH/4 */
496 valueof(ts_RslChanNr_SDCCH4(0,2)),
497 /* TS 6: SDCCH/8 */
498 valueof(ts_RslChanNr_SDCCH8(6,4))
499 };
500 }
Harald Welte70767382018-02-21 12:16:40 +0100501 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100502 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100503 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200504 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100505
506 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100507 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
508 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
509 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
510 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100511
Harald Weltef26de0b2018-04-04 20:28:05 +0200512 map(self:PCU, system:PCU);
513 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100514
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700515 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100516 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700517
518 /* Init TRXC interface to FakeTRX */
519 map(self:BTS_TRXC, system:BTS_TRXC);
520 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
521
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700522 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700523 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 +0700524 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700525 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
526 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100527 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200528
529 /* Wait some extra time to make sure the BTS emits a stable carrier.
530 * (this is only relevant when running the tests with a physical BTS.) */
531 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100532}
533
Harald Welte68e495b2018-02-25 00:05:57 +0100534/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700535friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100536 map(self:L1CTL, system:L1CTL);
537 f_connect_reset(L1CTL);
538}
539
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700540private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100541
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700542private type record length(8) of FreqHopGroups FreqHopConfig;
543
544private type record of FreqHopGroup FreqHopGroups;
545private type record FreqHopGroup {
546 uint6_t hsn,
547 FreqHopGroupItems trx_maio
548};
549
550private type record of FreqHopGroupItem FreqHopGroupItems;
551private type record FreqHopGroupItem {
552 uint8_t trx_nr,
553 uint6_t maio
554};
555
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700556friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
557 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700558{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700559 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700560 var integer i, j;
561
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700562 fhp.enabled := false;
563
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700564 for (i := 0; i < lengthof(groups); i := i + 1) {
565 var FreqHopGroup g := groups[i];
566 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
567 var FreqHopGroupItem gi := g.trx_maio[j];
568 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700569 fhp.maio_hsn.maio := gi.maio;
570 fhp.maio_hsn.hsn := g.hsn;
571 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700572 break;
573 }
574 }
575
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700576 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700577 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700578 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
579 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
580 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700581
582 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700583 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
584 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700585 fhp.ma := fhp.ma & { l1ctl_ma_def[gi.trx_nr] };
586 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700587 }
588
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700589 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700590 break; /* We're done */
591 }
592 }
593}
594
Harald Welte70767382018-02-21 12:16:40 +0100595/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700596friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
597 boolean pcu_comp := false,
598 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100599runs on test_CT return ConnHdlr {
600 var charstring id := testcasename();
601 var ConnHdlr vc_conn;
602
603 vc_conn := ConnHdlr.create(id);
604 /* connect to RSL Emulation main component */
605 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
606 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700607
608 /* The ConnHdlr component may want to talk to some ports directly,
609 * so we disconnect it from the test_CT and connect it to the component.
610 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200611 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200612 unmap(self:PCU, system:PCU);
613 map(vc_conn:PCU, system:PCU);
614 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700615 if (trxc_comp) {
616 unmap(self:BTS_TRXC, system:BTS_TRXC);
617 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
618 }
Harald Welte70767382018-02-21 12:16:40 +0100619
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700620 /* Obtain frequency hopping parameters for a given timeslot */
621 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700622 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700623 }
624
Harald Welte70767382018-02-21 12:16:40 +0100625 vc_conn.start(f_handler_init(fn, id, pars));
626 return vc_conn;
627}
628
Harald Welte70767382018-02-21 12:16:40 +0100629private altstep as_Tguard() runs on ConnHdlr {
630 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100632 }
633}
634
Harald Welte990a3612019-05-27 14:02:13 +0200635friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
636 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100637}
638
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700639private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100640 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700641 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100642}
643
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700644private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100645 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700646 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100647}
648
649/* first function started in ConnHdlr component */
650private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
651runs on ConnHdlr {
652 g_pars := pars;
653 g_chan_nr := pars.chan_nr;
654
655 map(self:L1CTL, system:L1CTL);
656 f_connect_reset(L1CTL);
657
Harald Welted48c0c72019-06-05 10:01:15 +0200658 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700659 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100660 }
Harald Welte70767382018-02-21 12:16:40 +0100661
662 g_Tguard.start(pars.t_guard);
663 activate(as_Tguard());
664
665 f_rslem_register(0, pars.chan_nr);
666
667 /* call the user-supplied test case function */
668 fn.apply(id);
669}
670
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700671private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
672 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200673runs on ConnHdlr return RSL_Message {
674 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100675 timer T := 3.0;
676 RSL.send(tx);
677 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100678 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200679 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100680 T.stop;
681 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100682 }
Harald Welte1eba3742018-02-25 12:48:14 +0100683 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200684 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100685 }
Harald Welte21240e62018-03-11 21:43:35 +0100686 [not ignore_other] as_l1_sacch();
687 [not ignore_other] as_meas_res();
688 [not ignore_other] as_l1_dcch();
689 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200690 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100691 }
Harald Welte21240e62018-03-11 21:43:35 +0100692 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100693 }
Harald Welteb1726c92018-03-30 11:56:38 +0200694 return rx;
695}
696
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700697friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
698 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200699runs on ConnHdlr {
700 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100701}
702
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700703friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
704 boolean encr_enable := false,
705 RSL_IE_List more_ies := {},
706 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
707runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200708 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200709 if (encr_enable) {
710 /* append encryption related IEs, if requested */
711 var RSL_IE_EncryptionInfo encr_info;
712 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
713 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
714encr_info})) };
715 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200716 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200717 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100718}
719
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700720friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100721 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 +0100722 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100723}
724
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700725/* Default Mobile Allocation to be used for frequency hopping */
726private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
727 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
728
Harald Welte2f2b2b72019-05-31 22:24:57 +0200729friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100730 template RSL_IE_ChannelMode chan_mode,
731 float t_guard := 20.0) := {
732 chan_nr := valueof(chan_nr),
733 chan_mode := valueof(chan_mode),
734 t_guard := t_guard,
735 l1_pars := {
736 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100737 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100738 meas_ul := {
739 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200740 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100741 rxqual := 0
742 },
743 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200744 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100745 rxqual := 0
746 }
747 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200748 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100749 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200750 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200751 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100752 },
Harald Weltee613f962018-04-18 22:38:16 +0200753 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200754 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700755 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700756 fhp := {
757 enabled := false,
758 maio_hsn := ts_HsnMaio(0, 0),
759 ma_map := c_MA_null,
760 ma := l1ctl_ma_def
761 }
Harald Welte70767382018-02-21 12:16:40 +0100762}
763
Harald Welte93640c62018-02-25 16:59:33 +0100764/***********************************************************************
765 * Channel Activation / Deactivation
766 ***********************************************************************/
767
Harald Welte70767382018-02-21 12:16:40 +0100768/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700769private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100770 for (var integer i := 0; i < 500; i := i+1) {
771 f_rsl_chan_act(g_pars.chan_mode);
772 f_rsl_chan_deact();
773 }
774 setverdict(pass);
775}
776testcase TC_chan_act_stress() runs on test_CT {
777 var ConnHdlr vc_conn;
778 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200779 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100780 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
781 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100783}
784
785/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700786private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100787 f_rsl_chan_act(g_pars.chan_mode);
788 /* attempt to activate the same lchan again -> expect reject */
789 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
790 alt {
791 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200792 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100793 }
794 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
795 setverdict(pass);
796 }
797 }
798 f_rsl_chan_deact();
799}
800testcase TC_chan_act_react() runs on test_CT {
801 var ConnHdlr vc_conn;
802 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100803 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100804 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
805 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200806 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100807}
808
809/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700810private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100811 timer T := 3.0;
812 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
813 T.start;
814 alt {
815 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
816 setverdict(pass);
817 }
818 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100820 }
821 }
822}
823testcase TC_chan_deact_not_active() runs on test_CT {
824 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100825 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100826 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
827 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100829}
830
831/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700832private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100833 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
834 alt {
835 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200836 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100837 }
838 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
839 setverdict(pass);
840 }
841 }
842}
843private type record WrongChanNrCase {
844 RslChannelNr chan_nr,
845 charstring description
846}
847private type record of WrongChanNrCase WrongChanNrCases;
848private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
849 chan_nr := chan_nr,
850 description := desc
851}
852
853testcase TC_chan_act_wrong_nr() runs on test_CT {
854 var ConnHdlr vc_conn;
855 var ConnHdlrPars pars;
856
Harald Welte294b0a22018-03-10 23:26:48 +0100857 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100858
859 var WrongChanNrCases wrong := {
860 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
861 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
862 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
863 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
864 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
865 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
866 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
867 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
868 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
869 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
870 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
871 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
872 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
873 };
874
875 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
876 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
877 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
878 vc_conn.done;
879 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100881}
882
Harald Weltee613f962018-04-18 22:38:16 +0200883/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200884friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200885 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200886 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200887
888 /* test on each of the channels we have */
889 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
890 pars.chan_nr := valueof(g_AllChanTypes[i]);
891
892 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
893 vc_conn := f_start_handler(fn, pars);
894 vc_conn.done;
895 }
896
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200897 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200898}
899
Harald Welte93640c62018-02-25 16:59:33 +0100900/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100901 * SACCH handling
902 ***********************************************************************/
903
904private function f_exp_sacch(boolean exp) runs on ConnHdlr {
905 timer T_sacch := 3.0;
906 T_sacch.start;
907 alt {
908 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100910 }
911 [not exp] T_sacch.timeout {
912 setverdict(pass);
913 }
914 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
915 setverdict(pass);
916 }
917 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100919 }
920 [] L1CTL.receive { repeat; }
921 [] RSL.receive { repeat; }
922 }
923}
924
925/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
926private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
927 f_l1_tune(L1CTL);
928 RSL.clear;
929
930 /* activate the logical channel */
931 f_est_dchan();
932 L1CTL.clear;
933
934 /* check that SACCH actually are received as expected */
935 f_exp_sacch(true);
936
937 /* deactivate SACCH on the logical channel */
938 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
939 f_sleep(1.0);
940 L1CTL.clear;
941
942 /* check that no SACCH are received anymore */
943 f_exp_sacch(false);
944
945 /* release the channel */
946 f_rsl_chan_deact();
947 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
948}
949testcase TC_deact_sacch() runs on test_CT {
950 var ConnHdlr vc_conn;
951 var ConnHdlrPars pars;
952 f_init();
953 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
954 //for (var integer i := 0; i < 1; i := i+1) {
955 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
956 log(testcasename(), ": Starting for ", g_AllChannels[i]);
957 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
958 vc_conn.done;
959 }
960 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100962}
963
Harald Welte55700662018-03-12 13:15:43 +0100964/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100965private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
966 var L1ctlDlMessage dl;
967 /* check that the specified SI5 value is actually sent */
968 timer T_sacch := 3.0;
969 L1CTL.clear;
970 T_sacch.start;
971 alt {
972 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
973 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
974 if (match(l3, l3_exp)) {
975 setverdict(pass);
976 } else {
977 repeat;
978 }
979 }
980 [] L1CTL.receive { repeat; }
981 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100983 }
984 }
985}
986
Harald Welte55700662018-03-12 13:15:43 +0100987/* verify that given SACCH payload is not present */
988private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
989 var L1ctlDlMessage dl;
990 /* check that the specified SI5 value is actually sent */
991 timer T_sacch := 3.0;
992 L1CTL.clear;
993 T_sacch.start;
994 alt {
995 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
996 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
997 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200998 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100999 } else {
1000 repeat;
1001 }
1002 }
1003 [] L1CTL.receive { repeat; }
1004 [] T_sacch.timeout {
1005 setverdict(pass);
1006 }
1007 }
1008}
1009
Harald Welte629cc6b2018-03-11 17:19:05 +01001010/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001011private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1012 /* Set a known default SACCH filling for SI5 */
1013 var octetstring si5 := f_rnd_octstring(19);
1014 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1015
1016 f_l1_tune(L1CTL);
1017 RSL.clear;
1018
1019 /* activate the logical channel */
1020 f_est_dchan();
1021
1022 /* check that the specified SI5 value is actually sent */
1023 f_sacch_present(si5);
1024
1025 /* release the channel */
1026 RSL.clear;
1027 f_rsl_chan_deact();
1028 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1029}
1030testcase TC_sacch_filling() runs on test_CT {
1031 var ConnHdlr vc_conn;
1032 var ConnHdlrPars pars;
1033 f_init();
1034 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1035 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1036 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1037 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1038 vc_conn.done;
1039 }
1040 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001041 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001042}
1043
Harald Welte629cc6b2018-03-11 17:19:05 +01001044/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001045private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1046 /* Set a known default SACCH filling for SI5 */
1047 var octetstring si5 := f_rnd_octstring(19);
1048 var octetstring si5_diff := f_rnd_octstring(19);
1049 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1050
1051 f_l1_tune(L1CTL);
1052 RSL.clear;
1053
1054 log("Activating channel, expecting standard SI5");
1055 /* activate the logical channel */
1056 f_est_dchan();
1057 /* check that the specified SI5 value is actually sent */
1058 f_sacch_present(si5);
1059
1060 /* set channel-specific different SI5 */
1061 log("Setting channel specific SACCH INFO, expecting it");
1062 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1063 /* check that the specified lchan-specific value is now used */
1064 f_sacch_present(si5_diff);
1065
1066 /* deactivate the channel and re-activate it, this should result in default SI5 */
1067 log("De-activating and re-activating channel, expecting standard SI5");
1068 f_rsl_chan_deact();
1069 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1070 /* Verify that the TRX-wide default SACCH filling is present again */
1071 f_sacch_present(si5);
1072
1073 /* release the channel */
1074 RSL.clear;
1075 f_rsl_chan_deact();
1076 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1077}
1078testcase TC_sacch_info_mod() runs on test_CT {
1079 var ConnHdlr vc_conn;
1080 var ConnHdlrPars pars;
1081 f_init();
1082 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1083 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1084 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1085 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1086 vc_conn.done;
1087 }
1088 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001090}
1091
Harald Welte075d84c2018-03-12 13:07:24 +01001092/* Test SACCH scheduling of multiple different SI message types */
1093private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1094 var octetstring si5 := f_rnd_octstring(19);
1095 var octetstring si5bis := f_rnd_octstring(19);
1096 var octetstring si5ter := f_rnd_octstring(19);
1097 var octetstring si6 := f_rnd_octstring(19);
1098
1099 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1100 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1101 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1102 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1103
1104 f_l1_tune(L1CTL);
1105 RSL.clear;
1106
1107 /* activate the logical channel */
1108 f_est_dchan();
1109 L1CTL.clear;
1110
1111 /* check that SACCH actually are received as expected */
1112 f_sacch_present(si5);
1113 f_sacch_present(si5bis);
1114 f_sacch_present(si5ter);
1115 f_sacch_present(si6);
1116
1117 /* release the channel */
1118 f_rsl_chan_deact();
1119 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1120}
1121testcase TC_sacch_multi() runs on test_CT {
1122 var ConnHdlr vc_conn;
1123 var ConnHdlrPars pars;
1124 f_init();
1125 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1126 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1127 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1128 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1129 vc_conn.done;
1130 }
1131 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001133}
1134
Harald Welte55700662018-03-12 13:15:43 +01001135/* Test if SACH information is modified as expected */
1136private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1137 var octetstring si5 := f_rnd_octstring(19);
1138 var octetstring si6 := f_rnd_octstring(19);
1139
1140 /* First, configure both SI5 and SI6 to be transmitted */
1141 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1142 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1143
1144 f_l1_tune(L1CTL);
1145 RSL.clear;
1146
1147 /* activate the logical channel */
1148 f_est_dchan();
1149 L1CTL.clear;
1150
1151 /* check that SACCH actually are received as expected */
1152 f_sacch_present(si5);
1153 f_sacch_present(si6);
1154
1155 /* disable SI6 */
1156 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1157
1158 /* check that SI5 is still transmitted */
1159 f_sacch_present(si5);
1160 /* check if SI6 is now gone */
1161 f_sacch_missing(si6);
1162
1163 /* release the channel */
1164 f_rsl_chan_deact();
1165 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1166}
1167testcase TC_sacch_multi_chg() runs on test_CT {
1168 var ConnHdlr vc_conn;
1169 var ConnHdlrPars pars;
1170 f_init();
1171 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1172 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1173 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1174 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1175 vc_conn.done;
1176 }
1177 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001178 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001179}
1180
Harald Weltec8d363c2019-05-19 20:36:48 +02001181/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1182private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1183 var octetstring si5 := f_rnd_octstring(19);
1184 var octetstring si6 := f_rnd_octstring(19);
1185 var octetstring si5_specific := f_rnd_octstring(19);
1186 var octetstring si6_specific := f_rnd_octstring(19);
1187
1188 /* First, configure both SI5 and SI6 to be transmitted */
1189 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1190 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1191
1192 f_l1_tune(L1CTL);
1193 RSL.clear;
1194
1195 /* activate channel with different SACCH filling */
1196 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1197 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1198 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1199 }));
1200 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1201 RSL_IE_Body:{sacch_info := sacch_info})) };
1202 f_est_dchan(more_ies := addl_ies);
1203
1204 /* check that SACCH actually are received as expected */
1205 f_sacch_present(si5_specific);
1206 f_sacch_present(si6_specific);
1207
1208 /* release the channel */
1209 f_rsl_chan_deact();
1210 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1211}
1212testcase TC_sacch_chan_act() runs on test_CT {
1213 var ConnHdlr vc_conn;
1214 var ConnHdlrPars pars;
1215 f_init();
1216
1217 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1218 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1219 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1220 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1221 vc_conn.done;
1222 }
1223 /* TODO: do the above in parallel, rather than sequentially? */
1224 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1225}
1226
Harald Welte8b01c792019-05-19 22:51:25 +02001227/* verify that SACCH DL transmission is started only if MS power IE present
1228 * see section 4.1.3 of 3GPP TS 48.058 */
1229private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1230 var octetstring si5 := f_rnd_octstring(19);
1231
1232 f_l1_tune(L1CTL);
1233 RSL.clear;
1234
1235 /* Step 1: Activate ASYNC HO channel without MS power IE */
1236
1237 /* Activate channel on BTS side */
1238 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1239 /* don't perform immediate assignment here, as we're testing non-IA case */
1240 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001241 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001242
1243 /* Verify that no DL SACCH is being received */
1244 f_sacch_missing(?);
1245
1246 f_rsl_chan_deact();
1247 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1248
1249
1250 /* Step 2: Activate ASYNC HO channel with MS power IE */
1251
1252 /* Activate channel on BTS side */
1253 var RSL_IE_List addl_ies := {
1254 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1255 };
1256 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1257 /* don't perform immediate assignment here, as we're testing non-IA case */
1258 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001259 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001260
1261 /* Verify that DL SACCH is being received */
1262 f_sacch_present(si5);
1263
1264 f_rsl_chan_deact();
1265 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1266}
1267testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1268 var ConnHdlr vc_conn;
1269 var ConnHdlrPars pars;
1270 f_init();
1271
1272 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1273 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1274 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1275 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1276 vc_conn.done;
1277 }
1278 /* TODO: do the above in parallel, rather than sequentially? */
1279 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1280}
1281
1282/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1283 * see section 4.1.4 of 3GPP TS 48.058 */
1284private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1285 var octetstring si5 := f_rnd_octstring(19);
1286 var RSL_IE_List addl_ies;
1287
1288 f_l1_tune(L1CTL);
1289 RSL.clear;
1290
1291 /* Step 1: Activate SYNC HO channel without MS power IE */
1292
1293 /* Activate channel on BTS side */
1294 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1295 /* don't perform immediate assignment here, as we're testing non-IA case */
1296 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001297 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001298
1299 /* Verify that no DL SACCH is being received */
1300 f_sacch_missing(?);
1301
1302 f_rsl_chan_deact();
1303 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1304
1305
1306 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1307
1308 /* Activate channel on BTS side */
1309 addl_ies := {
1310 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1311 };
1312 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1313 /* don't perform immediate assignment here, as we're testing non-IA case */
1314 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001315 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001316
1317 /* Verify that no DL SACCH is being received */
1318 f_sacch_missing(?);
1319
1320 f_rsl_chan_deact();
1321 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1322
1323
1324 /* Step 2b: Activate SYNC HO channel with TA IE */
1325
1326 /* Activate channel on BTS side */
1327 addl_ies := {
1328 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1329 };
1330 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1331 /* don't perform immediate assignment here, as we're testing non-IA case */
1332 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001333 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001334
1335 /* Verify that no DL SACCH is being received */
1336 f_sacch_missing(?);
1337
1338 f_rsl_chan_deact();
1339 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1340
1341
1342 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1343
1344 /* Activate channel on BTS side */
1345 addl_ies := {
1346 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1347 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1348 };
1349 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1350 /* don't perform immediate assignment here, as we're testing non-IA case */
1351 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001352 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001353
1354 /* Verify that DL SACCH is being received */
1355 f_sacch_present(si5);
1356
1357 f_rsl_chan_deact();
1358 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1359}
1360testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1361 var ConnHdlr vc_conn;
1362 var ConnHdlrPars pars;
1363 f_init();
1364
1365 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1366 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1367 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1368 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1369 vc_conn.done;
1370 }
1371 /* TODO: do the above in parallel, rather than sequentially? */
1372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1373}
Harald Welte629cc6b2018-03-11 17:19:05 +01001374
1375
1376/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001377 * RACH Handling
1378 ***********************************************************************/
1379
Harald Welte8c24c2b2018-02-26 08:31:31 +01001380/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001381private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001382 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001383 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001384 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001385
Harald Welte8c24c2b2018-02-26 08:31:31 +01001386 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001387 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001388 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001389 var OCT1 ra := f_rnd_ra_emerg();
1390 if (emerg == true) {
1391 ra := f_rnd_ra_emerg();
1392 } else {
1393 ra := f_rnd_ra_cs();
1394 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001395 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1396 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001397 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001398 }
1399 fn_last := fn;
1400
1401 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001402 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001403 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001404 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001405 T.stop;
1406 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001407 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001409 }
1410 [] RSL_CCHAN.receive { repeat; }
1411 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001412 test_failed := true;
1413 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001414 }
1415 }
1416 }
Maxba06feb2019-03-05 10:52:46 +01001417 if (test_failed) {
1418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001419 }
Maxba06feb2019-03-05 10:52:46 +01001420 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001422}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001423
Philipp Maier16ade782020-07-08 21:36:00 +02001424/* Normal variant */
1425testcase TC_rach_content() runs on test_CT {
1426 f_TC_rach_content(emerg := false);
1427}
1428
1429/* Emergency call variant */
1430testcase TC_rach_content_emerg() runs on test_CT {
1431 f_TC_rach_content(emerg := true);
1432}
1433
Harald Welte8c24c2b2018-02-26 08:31:31 +01001434/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1435testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001436 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001437 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001438 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001439 f_l1_tune(L1CTL);
1440
1441 var GsmFrameNumber fn_last := 0;
1442 for (var integer i := 0; i < 1000; i := i+1) {
1443 var OCT1 ra := f_rnd_ra_cs();
1444 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1445 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001446 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001447 }
1448 fn_last := fn;
1449 }
1450 var integer rsl_chrqd := 0;
1451 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001452 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001453 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001454 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001455 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001456 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001457 repeat;
1458 }
1459 [] RSL_CCHAN.receive { repeat; }
1460 [] T.timeout { }
1461 }
1462 if (rsl_chrqd == 1000) {
1463 setverdict(pass);
1464 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001465 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001466 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001468}
1469
Harald Welte3453ab42019-05-24 21:19:58 +02001470private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1471 var charstring bts_str := "bts " & int2str(bts_nr);
1472 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1473}
1474
1475/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1476private template integer tr_rach_slots_per_interval := (90 .. 130);
1477
1478/* Expect 0 RACH load on an idle BTS that has just started up */
1479testcase TC_rach_load_idle_thresh0() runs on test_CT {
1480 var ASP_RSL_Unitdata rx_ud;
1481
1482 f_init_vty_bsc();
1483 /* send load indications even at 0% load */
1484 f_vty_load_ind_thresh(0);
1485 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1486 f_sleep(2.0);
1487
1488 f_init();
1489
Harald Weltee37f9a52020-10-11 20:45:23 +02001490 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1491 alt {
1492 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1493 [] RSL_CCHAN.receive { repeat }
1494 }
1495
Harald Welte3453ab42019-05-24 21:19:58 +02001496 timer T := 5.0;
1497 T.start;
1498 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001499 [] 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 +02001500 setverdict(pass);
1501 repeat;
1502 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001503 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001504 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1505 repeat;
1506 }
1507 [] RSL_CCHAN.receive {
1508 repeat;
1509 }
1510 [] T.timeout { }
1511 }
1512
1513 f_vty_load_ind_thresh(10);
1514 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1515}
1516
1517/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1518testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1519 var ASP_RSL_Unitdata rx_ud;
1520
1521 f_init_vty_bsc();
1522 f_init();
1523
1524 timer T := 5.0;
1525 T.start;
1526 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001527 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001528 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1529 repeat;
1530 }
1531 [] RSL_CCHAN.receive {
1532 repeat;
1533 }
1534 [] T.timeout {
1535 setverdict(pass);
1536 }
1537 }
1538
1539 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1540}
1541
1542/* Expect 0 RACH load on an idle BTS that has just started up */
1543testcase TC_rach_load_count() runs on test_CT {
1544 var ASP_RSL_Unitdata rx_ud;
1545 var integer load_access_count := 0;
1546
1547 f_init_vty_bsc();
1548 /* send load indications even at 0% load */
1549 f_vty_load_ind_thresh(0);
1550 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1551 f_sleep(2.0);
1552 f_init();
1553
1554 f_init_l1ctl();
1555 f_sleep(1.0);
1556 f_l1_tune(L1CTL);
1557
Harald Welte52ae1682020-10-11 20:45:55 +02001558 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1559 alt {
1560 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1561 [] RSL_CCHAN.receive { repeat }
1562 }
1563
Harald Welte3453ab42019-05-24 21:19:58 +02001564 var GsmFrameNumber fn_last := 0;
1565 for (var integer i := 0; i < 1000; i := i+1) {
1566 var OCT1 ra := f_rnd_ra_cs();
1567 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1568 if (fn == fn_last) {
1569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1570 }
1571 fn_last := fn;
1572 }
1573
1574 timer T := 5.0;
1575 T.start;
1576 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001577 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001578 -> value rx_ud {
1579 var RSL_IE_Body ie;
1580 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1581 load_access_count := load_access_count + ie.rach_load.access_count;
1582 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1583 setverdict(fail, "Access count cannot be < Busy count");
1584 }
1585 repeat;
1586 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001587 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001588 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1589 repeat;
1590 }
1591 [] RSL_CCHAN.receive {
1592 repeat;
1593 }
1594 [] T.timeout { }
1595 }
1596 if (load_access_count == 1000) {
1597 setverdict(pass);
1598 } else {
1599 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1600 }
1601
1602 f_vty_load_ind_thresh(10);
1603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1604}
1605
Harald Welte54a2a2d2018-02-26 09:14:05 +01001606private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001607 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001608 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001609 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001610 f_sleep(0.5);
1611
1612 /* Transmit RACH request + wait for confirmation */
1613 var OCT1 ra := f_rnd_ra_cs();
1614 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1615
1616 /* Check for expected result */
1617 timer T := 1.5;
1618 T.start;
1619 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001620 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001621 setverdict(pass);
1622 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001623 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001624 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001625 }
1626 [] RSL_CCHAN.receive { repeat; }
1627 [not expect_pass] T.timeout {
1628 setverdict(pass);
1629 }
1630 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001632 }
1633 }
1634}
1635
1636/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1637testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001638 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001639 f_init_l1ctl();
1640 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001641 f_sleep(1.0);
1642
1643 /* default max-ta is 63 (full range of GSM timing advance */
1644
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001645 /* We allow early arrival up to 2 symbols */
1646 f_rach_toffs(-1*256, true);
1647 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001648 f_rach_toffs(-10*256, false);
1649
1650 /* 0 / 32 / 63 bits is legal / permitted */
1651 f_rach_toffs(0, true);
1652 f_rach_toffs(32*256, true);
1653 f_rach_toffs(63*256, true);
1654
1655 /* more than 63 bits is not legal / permitted */
1656 f_rach_toffs(64*256, false);
1657 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001659}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001660
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001661private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001662 var GsmFrameNumber fn;
1663 var RSL_Message rm;
1664
1665 f_l1_tune(L1CTL);
1666 RSL.clear;
1667
1668 /* Generate a random Handover Reference */
1669 var integer ho_ref := oct2int(f_rnd_octstring(1));
1670
1671 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1672 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1673 RSL_IE_Body:{ handover_ref := ho_ref }));
1674
1675 /* Activate a channel on the BTS side (no encryption) */
1676 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1677 act_type := t_RSL_IE_ActType_HO_SYNC);
1678
1679 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1680 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001681 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001682
1683 /* Send handover Access Burst */
1684 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1685
1686 /* TODO: test mismatching Handover Reference, and missing IE */
1687
1688 /* Wait for handover detection */
1689 timer T := 3.0;
1690 T.start;
1691 alt {
1692 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1693 log("Handover RACH has been detected: ", rm);
1694 setverdict(pass);
1695 }
1696 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1698 log2str("RSL_CHAN_RQD was not expected: ", rm));
1699 }
1700 [] RSL.receive { repeat; }
1701 [] T.timeout {
1702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1703 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1704 }
1705 }
1706
1707 /* Release the channel */
1708 f_rsl_chan_deact();
1709 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1710}
1711
1712/* Test handover RACH detection */
1713testcase TC_ho_rach() runs on test_CT {
1714 var ConnHdlrPars pars;
1715 var ConnHdlr vc_conn;
1716
1717 f_init();
1718
1719 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1720 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1721 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1722 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1723 vc_conn.done;
1724 }
1725
1726 /* TODO: do the above in parallel, rather than sequentially? */
1727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1728}
1729
Harald Welte93640c62018-02-25 16:59:33 +01001730/***********************************************************************
1731 * Measurement Processing / Reporting
1732 ***********************************************************************/
1733
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001734private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001735 spare := '0'B,
1736 lpd := 0,
1737 sapi := sapi,
1738 c_r := c_r,
1739 ea := true
1740}
1741
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001742private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001743 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001744 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001745 len := 0, /* overwritten */
1746 m := false,
1747 el := 1,
1748 payload := pl
1749}
1750
1751/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001752private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001753 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001754 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001755 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001756 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 +01001757 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001758 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001759
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001760 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1761 g_pars.l1_pars.ms_power_level, false,
1762 g_pars.l1_pars.ms_actual_ta);
1763
1764 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1765 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1766
1767 log("Sending Measurement Report: ", l1h, l2);
1768 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001769 repeat;
1770 }
1771}
1772
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001773private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001774 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001775 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001776 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1777 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001778 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1779 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001780 repeat;
1781 }
1782}
1783
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001784private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001785 uint6_t rxlev,
1786 uint3_t rxqual
1787}
1788
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001789private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001790 MeasElem full,
1791 MeasElem sub
1792}
1793
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001794private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001795 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001796 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001797 MeasElemFS meas_ul,
1798 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001799 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001800 uint5_t ms_power_level,
1801 uint8_t ms_actual_ta
1802}
1803
1804/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1805private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1806 return 63 + (toffs256s/256);
1807}
1808
Harald Welted5684392018-03-10 18:22:04 +01001809private function f_max(integer a, integer b) return integer {
1810 if (a > b) {
1811 return a;
1812 } else {
1813 return b;
1814 }
1815}
1816
1817private function f_min(integer a, integer b) return integer {
1818 if (a < b) {
1819 return a;
1820 } else {
1821 return b;
1822 }
1823}
1824
1825/* compute negative tolerance val-tolerance, ensure >= min */
1826private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1827 val := val - tolerance;
1828 return f_max(val, min);
1829}
1830
1831/* compute positive tolerance val+tolerance, ensure <= max */
1832private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1833 val := val + tolerance;
1834 return f_min(val, max);
1835}
1836
1837/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1838private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1839return template integer {
1840 var template integer ret;
1841 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1842 return ret;
1843}
1844
1845
Harald Welte70767382018-02-21 12:16:40 +01001846/* build a template for matching measurement results against */
1847private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1848 var ConnL1Pars l1p := g_pars.l1_pars;
1849 var template RSL_IE_UplinkMeas ul_meas := {
1850 len := 3,
1851 rfu := '0'B,
1852 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001853 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001854 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001855 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001856 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001857 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1858 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001859 supp_meas_info := omit
1860 };
Harald Welte685d5982018-02-27 20:42:05 +01001861 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001862 ul_meas.len := (3+8);
1863 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001864 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001865 toa256_min := ?,
1866 toa256_max := ?,
1867 toa256_std_dev := ?
1868 }
Harald Welte685d5982018-02-27 20:42:05 +01001869 }
Harald Welte70767382018-02-21 12:16:40 +01001870 var template RSL_IE_BS_Power bs_power := {
1871 reserved := 0,
1872 epc := false,
1873 fpc := false,
1874 power_level := l1p.bs_power_level
1875 };
1876 var template RSL_IE_L1Info l1_info := {
1877 ms_power_lvl := l1p.ms_power_level,
1878 fpc := false,
1879 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001880 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001881 };
1882 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001883 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001884 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1885 ?, t_toffs);
1886}
1887
Philipp Maierdd841d32019-12-17 14:44:54 +01001888/* build a template for matching measurement results that do not contain any
1889 * MS related measurement (l1_info, l3_info and ms timing offset). */
1890private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1891 var ConnL1Pars l1p := g_pars.l1_pars;
1892 var template RSL_IE_UplinkMeas ul_meas := {
1893 len := 3,
1894 rfu := '0'B,
1895 dtx_d := l1p.dtx_enabled,
1896 rxlev_f_u := ?,
1897 reserved1 := '00'B,
1898 rxlev_s_u := ?,
1899 reserved2 := '00'B,
1900 rxq_f_u := ?,
1901 rxq_s_u := ?,
1902 supp_meas_info := omit
1903 };
1904 if (l1p.toa256_enabled) {
1905 ul_meas.len := (3+8);
1906 ul_meas.supp_meas_info := {
1907 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1908 toa256_min := ?,
1909 toa256_max := ?,
1910 toa256_std_dev := ?
1911 }
1912 }
1913 var template RSL_IE_BS_Power bs_power := {
1914 reserved := 0,
1915 epc := false,
1916 fpc := false,
1917 power_level := l1p.bs_power_level
1918 };
1919
1920 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1921}
1922
Harald Welte70767382018-02-21 12:16:40 +01001923/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001924private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001925 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001926 var boolean chan_est := false;
1927
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001928 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001929
1930 /* Receive osmocom specific measurement reports. This is the normal
1931 * case. Here we verify that the measurement reports we sent are
1932 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001933 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1934 /* increment counter of next to-be-expected meas rep */
1935 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1936 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001937 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001938
1939 /* The following two cases may only happen in the beginning
1940 * of the channel establishment phase. Once we have received
1941 * the "our" measurement report the first time, the channel
1942 * is established and empty or hardcoded TRXCON reports must
1943 * not occur anymore. */
1944 chan_est := true;
1945
1946 repeat;
1947 }
1948
1949 /* When the BTS has established the channel, the MS might need slightly
1950 * more time to establish the channel and actually start sending. The
1951 * result is then a measurement report that just lacks the measurement
1952 * information of the MS. This is normal and we tolerate this behavior. */
1953 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1954 /* increment counter of next to-be-expected meas rep */
1955 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1956 /* Re-start the timer expecting the next MEAS RES */
1957 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001958 repeat;
1959 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001960
1961 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1962 * measurements if the TTCN3 side does not supply measurement input in
1963 * time. In those cases TRXCON will either use a cached measurement
1964 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1965 * report the templates above will not match. We tolerate this
1966 * behavior, but only once. */
1967 [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 +01001968 /* increment counter of next to-be-expected meas rep */
1969 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1970 if (g_first_meas_res) {
1971 g_first_meas_res := false;
1972 repeat;
1973 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001975 }
Harald Welte70767382018-02-21 12:16:40 +01001976 }
1977 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001979 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001980 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001982 }
1983}
1984
Harald Weltee613f962018-04-18 22:38:16 +02001985private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1986 select (rsl_alg_id) {
1987 case (RSL_ALG_ID_A5_0) { return 0; }
1988 case (RSL_ALG_ID_A5_1) { return 1; }
1989 case (RSL_ALG_ID_A5_2) { return 2; }
1990 case (RSL_ALG_ID_A5_3) { return 3; }
1991 case (RSL_ALG_ID_A5_4) { return 4; }
1992 case (RSL_ALG_ID_A5_5) { return 5; }
1993 case (RSL_ALG_ID_A5_6) { return 6; }
1994 case (RSL_ALG_ID_A5_7) { return 7; }
1995 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001996 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1997 /* Make compiler happy by calling mtc.stop here. It is already
1998 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001999 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002000 }
2001 }
2002}
2003
2004private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2005 select (rsl_alg_id) {
2006 case (RSL_ALG_ID_A5_1) { return '000'B; }
2007 case (RSL_ALG_ID_A5_2) { return '001'B; }
2008 case (RSL_ALG_ID_A5_3) { return '010'B; }
2009 case (RSL_ALG_ID_A5_4) { return '011'B; }
2010 case (RSL_ALG_ID_A5_5) { return '100'B; }
2011 case (RSL_ALG_ID_A5_6) { return '101'B; }
2012 case (RSL_ALG_ID_A5_7) { return '110'B; }
2013 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2015 /* Make compiler happy by calling mtc.stop here. It is already
2016 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002017 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002018 }
2019 }
2020}
2021
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002022/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2023private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2024 var GsmFrameNumber fn;
2025 timer T := 8.0;
2026
2027 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2028 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2029
2030 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2031 /* Send the actual RACH */
2032 fn := f_L1CTL_RACH(L1CTL, ra);
2033
2034 T.start;
2035 alt {
2036 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2037 [] T.timeout {
2038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2039 }
2040 }
2041 T.stop
2042 return fn;
2043}
Harald Weltee613f962018-04-18 22:38:16 +02002044
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002045/* Tune to a dedicated channel: L1CTL only */
2046private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002047 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002048 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2049 7 /* TODO: mp_tsc */,
2050 mp_trx0_arfcn));
2051 } else {
2052 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2053 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002054 pars.fhp.maio_hsn.hsn,
2055 pars.fhp.maio_hsn.maio,
2056 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002057 }
2058}
2059
Harald Welte70767382018-02-21 12:16:40 +01002060/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002061private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002062 var GsmFrameNumber fn;
2063 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002064 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002065 var integer ra := 23;
2066
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002067 /* Send RACH request and wait for ChanReq */
2068 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002069
2070 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002071 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002072
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002073 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002074 if (g_pars.fhp.enabled) {
2075 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002076 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002077 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002078 }
2079
Harald Welte70767382018-02-21 12:16:40 +01002080 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002081 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 +01002082 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2083
2084 /* receive IMM.ASS on MS side */
2085 var ImmediateAssignment ia_um;
2086 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002087
2088 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2089 if (ch_desc.h != ia_um.chan_desc.h) {
2090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2091 }
2092
Harald Welte70767382018-02-21 12:16:40 +01002093 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002094 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002095 /* enable encryption, if requested */
2096 if (encr_enable) {
2097 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2098 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2099 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002100
2101 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002102}
2103
2104/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002105private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002106 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002107 RSL.clear;
2108
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002109 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002110 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002111 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002112 }
Harald Welte70767382018-02-21 12:16:40 +01002113
2114 f_est_dchan();
2115
2116 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2117 * RSL measurement reports on Abis side */
2118 timer T := 8.0;
2119 T.start;
2120 alt {
2121 [] as_l1_sacch();
2122 [] as_meas_res();
2123 [] as_l1_dcch();
2124 [] L1CTL.receive { repeat; }
2125 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002126 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002127 * of any earlier errors, so if we reach this timeout, we're good */
2128 setverdict(pass);
2129 }
2130 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002132 }
2133 }
2134 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002135 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002136}
Harald Welte0472ab42018-03-12 15:02:26 +01002137
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002138/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2139private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002140 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002141 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2142 timer Tup := 10.0;
2143 Tup.start;
2144 alt {
2145 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2146 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2147 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002148
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002149 if (rx_lvl != max_rx_lvl) {
2150 repeat;
2151 }
2152 Tup.stop;
2153 }
2154 [] L1CTL.receive { repeat; }
2155 [] Tup.timeout {
2156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2157 log2str("Didn't reach full power ", max_rx_lvl));
2158 }
2159 }
2160 return max_rx_lvl;
2161}
2162
2163/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2164private function f_verify_ramp_up() runs on ConnHdlr {
2165 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002166 var integer initial_rx_lvl := -1;
2167 var integer last_rx_lvl := -1;
2168 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2169
2170 timer T := 2.0;
2171 alt {
2172 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2173 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2174 log("Received rx_level=", rx_lvl);
2175 if (initial_rx_lvl == -1) {
2176 initial_rx_lvl := rx_lvl;
2177 last_rx_lvl := rx_lvl;
2178
2179 /* Expect a somehow low value during first received messages */
2180 if (initial_rx_lvl >= max_rx_lvl / 2) {
2181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2182 log2str("Detected high initial tx power during ramp up: ",
2183 initial_rx_lvl , ", full power is", max_rx_lvl));
2184 }
2185 }
2186
2187 /* received Rx level bigger than maximum allowed power by CN */
2188 if (rx_lvl > max_rx_lvl) {
2189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2190 log2str("Detected Tx power higher than full power: ",
2191 rx_lvl , " > ", max_rx_lvl));
2192 }
2193
2194 /* Make sure it never decreases, since we are rumping up */
2195 if (last_rx_lvl > rx_lvl) {
2196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2197 log2str("Detected Tx power decrease during ramp up: ",
2198 last_rx_lvl , " -> ", rx_lvl));
2199 }
2200
2201 if (rx_lvl == max_rx_lvl and not T.running) {
2202 /* We reached the maximum power, start timer and receive
2203 /* a few more to make sure we don't surpass it */
2204 log("Reached full power, wating a bit more until success");
2205 T.start;
2206 }
2207
2208 last_rx_lvl := rx_lvl;
2209 repeat;
2210 }
2211 [] L1CTL.receive { repeat; }
2212 [] T.timeout { }
2213 }
2214
2215 /* We didn't increase tx power during ramp up */
2216 if (initial_rx_lvl < last_rx_lvl) {
2217 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2218 } else {
2219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2220 log2str("No Tx power increase during whole ramp up: ",
2221 initial_rx_lvl , " -> ", last_rx_lvl));
2222 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002223}
2224
2225/* verify BTS ramps power down to rx_level 0 */
2226private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2227 var L1ctlDlMessage l1_dl;
2228 var integer last_rx_lvl := max_rx_lvl;
2229
2230 timer Tdown := 5.0;
2231 Tdown.start;
2232 alt {
2233 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2234 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2235 log("Received rx_level=", rx_lvl);
2236
2237 /* received Rx level bigger than maximum allowed power by CN */
2238 if (rx_lvl > max_rx_lvl) {
2239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2240 log2str("Detected Tx power higher than full power: ",
2241 rx_lvl , " > ", max_rx_lvl));
2242 }
2243
2244 /* Make sure it never increases, since we are rumping down */
2245 if (last_rx_lvl < rx_lvl) {
2246 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2247 log2str("Detected Tx power increase during ramp up: ",
2248 last_rx_lvl , " -> ", rx_lvl));
2249 }
2250
2251 last_rx_lvl := rx_lvl;
2252 if (last_rx_lvl != 0) {
2253 repeat;
2254 }
2255 /* we reached power level 0, we are done */
2256 Tdown.stop;
2257 }
2258 [] L1CTL.receive { repeat; }
2259 [] Tdown.timeout { }
2260 }
2261
2262 /* We didn't increase tx power during ramp down */
2263 if (max_rx_lvl > last_rx_lvl) {
2264 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2265 } else {
2266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2267 log2str("No Tx power decrease during whole ramp down: ",
2268 max_rx_lvl , " -> ", last_rx_lvl));
2269 }
2270}
2271
2272/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002273private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002274 f_l1_tune(L1CTL);
2275 RSL.clear;
2276
2277 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002278
2279 setverdict(pass);
2280}
2281testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2282 var ConnHdlr vc_conn;
2283 var ConnHdlrPars pars;
2284 f_init();
2285 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2286 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2287 pcu_comp := false, trxc_comp := true);
2288 vc_conn.done;
2289 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2290}
2291
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002292/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002293private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002294 f_connhdlr_init_vty_bsc();
2295
2296 f_l1_tune(L1CTL);
2297 RSL.clear;
2298
2299 /* Wait until BTS is started and at full power */
2300 var integer max_rx_lvl := f_wait_ramp_up();
2301 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2302
2303 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2304 f_verify_ramp_down(max_rx_lvl);
2305
2306 setverdict(pass);
2307}
2308testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2309 var ConnHdlr vc_conn;
2310 var ConnHdlrPars pars;
2311 f_init();
2312 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2313 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2314 pcu_comp := false, trxc_comp := true);
2315 vc_conn.done;
2316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2317}
2318
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002319/* Verify Tx power:
2320 * + ramping down during ADM state UNLOCKED->LOCKED
2321 * + ramping up during ADM state LOCKED->UNLOCKED
2322 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002323private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002324 var L1ctlDlMessage l1_dl;
2325 var integer last_rx_lvl;
2326
2327 f_connhdlr_init_vty_bsc();
2328
2329 f_l1_tune(L1CTL);
2330 RSL.clear;
2331
2332 /* Wait until BTS is started and at full power */
2333 var integer max_rx_lvl := f_wait_ramp_up();
2334 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2335
2336 log("ADM STATE UNLOCKED->LOCKED");
2337 f_vty_enter_cfg_trx(BSCVTY);
2338 f_vty_transceive(BSCVTY, "rf_locked 1");
2339 last_rx_lvl := max_rx_lvl;
2340 f_verify_ramp_down(max_rx_lvl);
2341
2342 /* Let some time after we received 0dBm, then check we don't receive BCCH
2343 * anymore because scheduler has stopped after ramping down */
2344 f_sleep(2.0);
2345 L1CTL.clear;
2346 timer Tlocked := 2.0;
2347 Tlocked.start;
2348 alt {
2349 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2350 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2351 log2str("Received data_ind during rf_locked: ", l1_dl));
2352 }
2353 [] L1CTL.receive { repeat; }
2354 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2355 }
2356
2357 log("ADM STATE LOCKED->UNLOCKED");
2358 f_vty_transceive(BSCVTY, "rf_locked 0");
2359 f_verify_ramp_up();
2360 setverdict(pass);
2361}
2362testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2363 var ConnHdlr vc_conn;
2364 var ConnHdlrPars pars;
2365 f_init();
2366 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2367 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2368 pcu_comp := false, trxc_comp := true);
2369 vc_conn.done;
2370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2371}
2372
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002373private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002374 timer T := 8.0;
2375 T.start;
2376 var RSL_Message rsl;
2377 alt {
2378 [] as_l1_sacch();
2379 [] L1CTL.receive { repeat; }
2380 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2381 if (rsl.ies[3].body.bs_power.power_level == level) {
2382 setverdict(pass)
2383 } else {
2384 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2385 }
2386 }
2387 [] T.timeout {
2388 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2389 }
2390 }
2391}
2392
2393/* see if the rsl meas res contains our expeced bs power level
2394bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002395private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002396 f_l1_tune(L1CTL);
2397 RSL.clear;
2398
2399 if (mp_bts_trxc_port != -1) {
2400 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2401 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2402 }
2403
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002404 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002405 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2406 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2407
2408 f_est_dchan(more_ies :={valueof(pwr)});
2409
2410 f_check_meas_bs_power_level(pwr_var);
2411
2412 f_rsl_chan_deact();
2413 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2414}
2415
2416/* see if the rsl meas res contains our expeced bs power level
2417bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002418private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002419 f_l1_tune(L1CTL);
2420 RSL.clear;
2421
2422 if (mp_bts_trxc_port != -1) {
2423 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2424 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2425 }
2426
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002427 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002428 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2429
2430 f_est_dchan();
2431
2432 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2433
2434 f_check_meas_bs_power_level(pwr_var);
2435
2436 f_rsl_chan_deact();
2437 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2438}
2439
2440testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2441 var ConnHdlr vc_conn;
2442 var ConnHdlrPars pars;
2443 f_init();
2444 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2445 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2446 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2447 pcu_comp := false, trxc_comp := true);
2448 vc_conn.done;
2449 }
2450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2451}
2452
2453testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2454 var ConnHdlr vc_conn;
2455 var ConnHdlrPars pars;
2456 f_init();
2457 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2458 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2459 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2460 pcu_comp := false, trxc_comp := true);
2461 vc_conn.done;
2462 }
2463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2464}
2465
Eric Wild61edb7e2019-06-03 12:38:31 +02002466/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2467second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2468These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002469private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002470 var uint5_t pwr_var := 7;
2471 var L1ctlDlMessage l1_dl;
2472
2473 f_trxc_fake_rssi(rxlev2dbm(10));
2474 f_l1_tune(L1CTL);
2475 RSL.clear;
2476
2477 var RSL_IE_List addl_ies;
2478 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2479
2480 addl_ies := {
2481 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2482 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2483 };
2484
2485 /* establish with power parameters */
2486 f_est_dchan(more_ies := addl_ies);
2487
2488 /* set a high value to ensure L1 power control level increases */
2489 f_trxc_fake_rssi(rxlev2dbm(20));
2490
2491 timer T2 := 6.0;
2492 T2.start;
2493 alt {
2494 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002495 /* Update sent MS power to follow what BTS requests */
2496 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2497 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002498 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002499 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002500 T2.stop;
2501 }
2502 [] L1CTL.receive { repeat; }
2503 [] T2.timeout {
2504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2505 "Power Level in L1 header has not increased sufficiently");
2506 }
2507 }
2508
2509 /* set a low value to ensure L1 power control level decreases */
2510 f_trxc_fake_rssi(rxlev2dbm(0));
2511
2512 timer T4 := 6.0;
2513 T4.start;
2514 alt {
2515 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002516 /* Update sent MS power to follow what BTS requests */
2517 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2518 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002519 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002520 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002521 T4.stop;
2522 setverdict(pass, "Power level in L1 decreased/increased as expected");
2523 }
2524 [] L1CTL.receive { repeat; }
2525 [] T4.timeout {
2526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2527 "Power Level in L1 header has not decreased sufficiently");
2528 }
2529 }
2530
2531 f_rsl_chan_deact();
2532 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2533
2534}
2535
2536/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002537private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002538 var uint5_t pwr_var := 7;
2539 var L1ctlDlMessage l1_dl;
2540
2541 /* set a low value to ensure power increases */
2542 f_trxc_fake_rssi(rxlev2dbm(10));
2543 f_l1_tune(L1CTL);
2544 RSL.clear;
2545
2546 var RSL_IE_List addl_ies;
2547 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2548
2549 addl_ies := {
2550 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2551 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2552 };
2553
2554 /* establish with power parameters */
2555 f_est_dchan(more_ies := addl_ies);
2556
2557 timer T1 := 10.0;
2558 T1.start;
2559 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002560 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2561 /* Update sent MS power to follow what BTS requests */
2562 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2563 repeat;
2564 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002565 [] L1CTL.receive { repeat; }
2566 [] T1.timeout {
2567 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2568 setverdict(fail, "Power level in L1 header should not have changed");
2569 }
2570 }
2571 }
2572
2573 f_rsl_chan_deact();
2574 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2575
2576}
2577
2578/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002579private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002580 var L1ctlDlMessage l1_dl;
2581 var uint5_t pwr_var := 15;
2582 var uint5_t pwr_max_var := f_get_max_power_from_band();
2583
2584 /* set a low value to ensure power increases */
2585 f_trxc_fake_rssi(rxlev2dbm(10));
2586 f_l1_tune(L1CTL);
2587 RSL.clear;
2588
2589 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2590 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2591
2592 /* establish with fixed power level */
2593 f_est_dchan(more_ies :={valueof(pwr)});
2594
2595 /* check our initial power level */
2596 f_wait_for_l1_power_level(pwr_var);
2597
2598 /* update power param to enable power loop
2599 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2600 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2601
2602 /* wait, then check that our power level was reduced */
2603 timer T1 := 10.0;
2604 T1.start;
2605 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002606 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2607 /* Update sent MS power to follow what BTS requests */
2608 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2609 repeat;
2610 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002611 [] L1CTL.receive { repeat; }
2612 [] T1.timeout {
2613 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2614 if( f_power_level_is_highest_dbm(rcv) ){
2615 setverdict(pass, "Power level in L1 header reduced as expected");
2616 } else {
2617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2618 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2619 }
2620 }
2621 }
2622
2623 f_rsl_chan_deact();
2624 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2625
2626}
2627
2628/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002629private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002630 var L1ctlDlMessage l1_dl;
2631
2632 /* set a high value to ensure power decreases */
2633 f_trxc_fake_rssi(rxlev2dbm(50));
2634 f_l1_tune(L1CTL);
2635 RSL.clear;
2636
2637 var uint5_t pwr_var := 5;
2638 var uint5_t pwr_target_val := 15;
2639
2640 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2641 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2642
2643 /* establish with fixed power level */
2644 f_est_dchan(more_ies :={valueof(pwr)});
2645
2646 /* check our initial power level */
2647 f_wait_for_l1_power_level(pwr_var);
2648
2649 /* update power param to enable power loop
2650 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002651 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002652
2653 /* wait, then check that our power level was increased */
2654 timer T1 := 10.0;
2655 T1.start;
2656 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002657 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2658 /* Update sent MS power to follow what BTS requests */
2659 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2660 repeat;
2661 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002662 [] L1CTL.receive { repeat; }
2663 [] T1.timeout {
2664 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2665 setverdict(pass, "Power level in L1 header increased to lowest power value");
2666 } else {
2667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2668 "Power level in L1 header NOT increased to lowest power value");
2669 }
2670 }
2671 }
2672
2673 f_rsl_chan_deact();
2674 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2675
2676}
2677
Eric Wild095024b2019-06-17 15:08:57 +02002678/* see if we change the power level without receiving power parameters, which should not happen
2679rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002680private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002681 var L1ctlDlMessage l1_dl;
2682
2683 /* set a high value to ensure power decreases */
2684 f_trxc_fake_rssi(rxlev2dbm(50));
2685 f_l1_tune(L1CTL);
2686 RSL.clear;
2687
2688 var uint5_t pwr_var := 5;
2689
2690 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2691 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2692
2693 /* establish with fixed power level */
2694 f_est_dchan(more_ies :={valueof(pwr)});
2695
2696 /* check our initial power level */
2697 f_wait_for_l1_power_level(pwr_var);
2698
2699 /* wait, then check that our power level did not change */
2700 timer T1 := 10.0;
2701 T1.start;
2702 alt {
2703 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2704 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2706 "BS power control should not be active unless we receive a power parameters IE!");
2707 }
2708 repeat;
2709 }
2710 [] L1CTL.receive { repeat; }
2711 [] T1.timeout { setverdict(pass); }
2712 }
2713
2714 f_rsl_chan_deact();
2715 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2716
2717}
2718
Eric Wild095024b2019-06-17 15:08:57 +02002719/* see if we change the power level without receiving power parameters, which should not happen
2720ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002721private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002722 var L1ctlDlMessage l1_dl;
2723
2724 /* set a high value to ensure power decreases */
2725 f_trxc_fake_rssi(rxlev2dbm(50));
2726 f_l1_tune(L1CTL);
2727 RSL.clear;
2728
2729 var uint5_t pwr_var := 5;
2730
2731 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2732 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2733
2734 /* establish with fixed power level */
2735 f_est_dchan(more_ies :={valueof(pwr)});
2736
2737 /* check our initial power level */
2738 f_wait_for_l1_power_level(pwr_var);
2739
2740 /* pwr control without power params IE, should NOT activate MS power control*/
2741 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2742
2743 /* wait, then check that our power level did not change */
2744 timer T1 := 10.0;
2745 T1.start;
2746 alt {
2747 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2748 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2750 "BS power control should not be active unless we receive a power parameters IE!");
2751 }
2752 repeat;
2753 }
2754 [] L1CTL.receive { repeat; }
2755 [] T1.timeout { setverdict(pass); }
2756 }
2757
2758 f_rsl_chan_deact();
2759 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2760
2761}
2762
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002763private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002764 var L1ctlDlMessage l1_dl;
2765 timer T0 := 10.0;
2766 T0.start;
2767 alt {
2768 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2769 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2771 "Power level in L1 header != signaled (RSL) power level.");
2772 }
2773 }
2774 [] L1CTL.receive { repeat; }
2775 [] T0.timeout {
2776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2777 "Timeout waiting for initial power level");
2778 }
2779 }
2780 T0.stop;
2781}
2782
2783private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2784 var IntegerRecord min_dbm_level;
2785 var IntegerRecord max_dbm_level;
2786 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2787
2788 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2789 if (min_dbm_level[i] == level) {
2790 return true;
2791 }
2792 }
2793 return false;
2794}
2795
2796private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2797 var IntegerRecord min_dbm_level;
2798 var IntegerRecord max_dbm_level;
2799 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2800
2801 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2802 if (max_dbm_level[i] == level) {
2803 return true;
2804 }
2805 }
2806 return false;
2807}
2808
2809private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2810 var IntegerRecord min_dbm_level;
2811 var IntegerRecord max_dbm_level;
2812 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2813 return max_dbm_level[0];
2814}
2815
2816type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002817private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002818private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2819 // 45.005 4.1.1
2820 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2821 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2822 2, 1, 0};
2823 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2824 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2825 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2826 var IntegerRecord rv;
2827
2828 select(band){
2829 case (BtsBand_allGSM){
2830 rv := gsm_power;
2831 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2832 max_dbm_level := {2, 1, 0};
2833 }
2834 case("DCS1800"){
2835 rv := dcs_power;
2836 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2837 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2838 }
2839 case("PCS1900"){
2840 rv := pcs_power;
2841 min_dbm_level := {15};
2842 max_dbm_level := {30};
2843 }
Harald Welte194b6912020-10-11 21:01:55 +02002844 case else {
2845 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2846 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002847 }
2848
2849 return rv;
2850}
2851
2852private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002853 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 +02002854}
2855
2856testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2857 var ConnHdlr vc_conn;
2858 var ConnHdlrPars pars;
2859 f_init();
2860 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2861 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2862 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2863 pars.bts0_band := f_vty_get_bts0_band();
2864 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2865 vc_conn.done;
2866 }
2867 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2868 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2869}
2870
2871testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2872 var ConnHdlr vc_conn;
2873 var ConnHdlrPars pars;
2874 f_init();
2875 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2876 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2877 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2878 pars.bts0_band := f_vty_get_bts0_band();
2879 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2880 vc_conn.done;
2881 }
2882 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2883 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2884}
2885
2886testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2887 var ConnHdlr vc_conn;
2888 var ConnHdlrPars pars;
2889 f_init();
2890 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2891 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2892 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2893 pars.bts0_band := f_vty_get_bts0_band();
2894 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2895 vc_conn.done;
2896 }
2897 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2899}
2900
2901testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2902 var ConnHdlr vc_conn;
2903 var ConnHdlrPars pars;
2904 f_init();
2905 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2906 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2907 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2908 pars.bts0_band := f_vty_get_bts0_band();
2909 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2910 vc_conn.done;
2911 }
2912 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2914}
2915
Eric Wild280ccb82019-06-17 11:11:52 +02002916testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2917 var ConnHdlr vc_conn;
2918 var ConnHdlrPars pars;
2919 f_init();
2920 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2921 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2922 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2923 pars.bts0_band := f_vty_get_bts0_band();
2924 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2925 vc_conn.done;
2926 }
2927 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2928 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2929}
2930
Eric Wild095024b2019-06-17 15:08:57 +02002931testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2932 var ConnHdlr vc_conn;
2933 var ConnHdlrPars pars;
2934 f_init();
2935 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2936 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2937 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2938 pars.bts0_band := f_vty_get_bts0_band();
2939 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2940 vc_conn.done;
2941 }
2942 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2943 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2944}
2945
Harald Welte70767382018-02-21 12:16:40 +01002946testcase TC_meas_res_sign_tchf() runs on test_CT {
2947 var ConnHdlr vc_conn;
2948 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002949 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002950 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2951 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002952 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2953 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002954 vc_conn.done;
2955 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002956 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002957}
2958testcase TC_meas_res_sign_tchh() runs on test_CT {
2959 var ConnHdlr vc_conn;
2960 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002961 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002962 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2963 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002964 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2965 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002966 vc_conn.done;
2967 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002968 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002969}
2970testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2971 var ConnHdlr vc_conn;
2972 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002973 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002974 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2975 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002976 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2977 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002978 vc_conn.done;
2979 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002980 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002981}
2982testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2983 var ConnHdlr vc_conn;
2984 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002985 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002986 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2987 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002988 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2989 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002990 vc_conn.done;
2991 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002992 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002993}
Harald Welte685d5982018-02-27 20:42:05 +01002994testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2995 var ConnHdlr vc_conn;
2996 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002997 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002998 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2999 for (var integer ss := 0; ss <= 1; ss := ss+1) {
3000 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
3001 pars.l1_pars.toa256_enabled := true;
3002 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
3003 vc_conn.done;
3004 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003005 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003006}
3007
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003008/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3009 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003010private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003011 var L1ctlDlMessage l1_dl;
3012 var RSL_IE_MS_Power ms_power;
3013 var RSL_Message rsl;
3014 var uint5_t power_level := 0;
3015
3016 f_l1_tune(L1CTL);
3017 RSL.clear;
3018
3019 f_est_dchan();
3020
3021 ms_power.reserved := 0;
3022 ms_power.fpc_epc := false;
3023
3024 /* Send the first power control command. This will disable any BTS/TRX
3025 * internal power control and switch the MS (which is not in scope of
3026 * this test) to a constant power level. We start with a power level
3027 * of 0 */
3028 ms_power.power_level := power_level;
3029 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3030 RSL.send(rsl);
3031
3032 alt {
3033
3034 /* Pick all SACCH blocks for checking */
3035 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3036
3037 /* The first byte of the L1 header contains the power level.
3038 * The reserved bits and the fpc bit is set to 0, so we may
3039 * compare directly. */
3040 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3041 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3042 }
3043
3044 /* Signal a new power level via RSL for the next turn. */
3045 if (power_level < 31) {
3046 power_level := power_level + 1;
3047 ms_power.power_level := power_level;
3048 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3049 RSL.send(rsl);
3050 repeat;
3051 }
3052
3053 }
3054
3055 /* Ignore all other blocks */
3056 [] L1CTL.receive { repeat; }
3057
3058 }
3059
3060 f_rsl_chan_deact();
3061 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3062
3063 setverdict(pass);
3064}
3065
3066testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3067 var ConnHdlr vc_conn;
3068 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003069 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003070
3071 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3072 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3073 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3074 vc_conn.done;
3075 }
3076 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3077}
Harald Welte70767382018-02-21 12:16:40 +01003078
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003079/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003080TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003081private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003082 var L1ctlDlMessage l1_dl;
3083 var uint5_t ta_to_test := 16;
3084
3085
3086 f_l1_tune(L1CTL);
3087 RSL.clear;
3088
3089 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003090 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003091
3092 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3093
3094
3095 alt {
3096
3097 /* Pick all SACCH blocks for checking */
3098 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3099
3100 /* The second byte of the L1 header contains the TA. */
3101 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3102 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3103 }
3104
3105 }
3106
3107 /* Ignore all other blocks */
3108 [] L1CTL.receive { repeat; }
3109
3110 }
3111
3112 f_rsl_chan_deact();
3113 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3114
3115 setverdict(pass);
3116}
3117
3118testcase TC_rsl_chan_initial_ta() runs on test_CT {
3119 var ConnHdlr vc_conn;
3120 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003121 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003122 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003123 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3124 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003125 vc_conn.done;
3126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3127}
3128
Eric Wilde57e1a62019-05-28 13:30:55 +02003129/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003130private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003131 var L1ctlDlMessage l1_dl;
3132 var uint5_t ms_power_level := 7;
3133
3134 var RSL_IE_MS_Power ms_power;
3135 ms_power.reserved := 0;
3136 ms_power.fpc_epc := false;
3137 ms_power.power_level := ms_power_level;
3138
3139 f_l1_tune(L1CTL);
3140 RSL.clear;
3141
3142 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3143
3144 timer T := 1.0;
3145 T.start;
3146 alt {
3147 /* Pick all SACCH blocks for checking */
3148 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3149 /* The first byte of the L1 header contains the power level.. */
3150 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3151 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3152 }
3153 }
3154 /* Ignore all other blocks */
3155 [] L1CTL.receive { repeat; }
3156 [] T.timeout {
3157 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3158 }
3159 }
3160
3161 f_rsl_chan_deact();
3162 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3163 setverdict(pass);
3164}
3165
3166testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3167 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3168 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3169}
3170
Harald Welte0472ab42018-03-12 15:02:26 +01003171/* 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 +01003172private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003173 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003174 RSL.clear;
3175
3176 f_est_dchan();
3177 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003178 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003179
3180 timer T := 40.0;
3181 T.start;
3182 alt {
3183 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3184 setverdict(pass)
3185 }
3186 [] RSL.receive { repeat };
3187 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003189 }
3190 }
3191 f_rsl_chan_deact();
3192}
3193testcase TC_conn_fail_crit() runs on test_CT {
3194 var ConnHdlr vc_conn;
3195 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003196 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003197 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3198 pars.t_guard := 60.0;
3199 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3200 vc_conn.done;
3201}
3202
Harald Welte93640c62018-02-25 16:59:33 +01003203/***********************************************************************
3204 * Paging
3205 ***********************************************************************/
3206
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003207private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003208 if (tmsi == 'FFFFFFFF'O) {
3209 return true;
3210 } else {
3211 return false;
3212 }
3213}
Harald Welte70767382018-02-21 12:16:40 +01003214
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003215private type record allowedFn { integer frame_nr }
3216private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3217private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3218private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3219private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3220private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3221private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3222private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3223private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3224private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003225{
3226 var integer frame_nr_51;
3227 frame_nr_51 := frame_nr mod 51
3228
3229 var allowedFn fn_check;
3230 fn_check.frame_nr := frame_nr_51;
3231
3232 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003234 return;
3235 }
3236
3237 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3238 return;
3239 }
3240 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3241 return;
3242 }
3243 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3244 return;
3245 }
3246 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3247 return;
3248 }
3249 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3250 return;
3251 }
3252 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3253 return;
3254 }
3255 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3256 return;
3257 }
3258 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3259 return;
3260 }
3261
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003263 return;
3264}
3265
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003266private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3267 inout integer num_paging_rcv_ids,
3268 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003269runs on test_CT {
3270 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003271 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003272 repeat;
3273 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003274 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003275 var octetstring without_plen :=
3276 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3277 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003278
3279 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3280
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003281 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3282 /* Ignore empty RR Paging Request (PCH filling) messages.
3283 * TODO: does it make sense to count them? */
3284 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003285 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3286 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003287 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003288 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3289 }
3290 } else if (match(rr, tr_PAGING_REQ2)) {
3291 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3292 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3293 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3294 }
3295 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3296 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3297 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003298 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003299 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3300 }
3301 } else if (match(rr, tr_PAGING_REQ3)) {
3302 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3303 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3304 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3305 }
3306 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3307 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3308 }
3309 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3310 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3311 }
3312 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3313 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3314 }
3315 }
3316 repeat;
3317 }
3318}
3319
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003320private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003321 boolean combined_ccch,
3322 integer bs_ag_blks_res,
3323 float load_factor,
3324 boolean exp_load_ind,
3325 boolean exp_overload,
3326 boolean use_tmsi
3327}
3328
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003329private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003330 integer num_paging_sent,
3331 integer num_paging_rcv_msgs,
3332 integer num_paging_rcv_ids,
3333 integer num_overload
3334}
3335
Harald Welte68e495b2018-02-25 00:05:57 +01003336/* Helper function for paging related testing */
3337private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003338 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003339 f_init_l1ctl();
3340 f_l1_tune(L1CTL);
3341
3342 var PagingTestState st := {
3343 num_paging_sent := 0,
3344 num_paging_rcv_msgs := 0,
3345 num_paging_rcv_ids := 0,
3346 num_overload := 0
3347 };
3348
3349 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3350 var float max_pch_imsi_per_sec;
3351 if (cfg.use_tmsi) {
3352 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3353 } else {
3354 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3355 }
3356 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3357 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003358 var float time_total := 20.0;
3359 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3360 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003361
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003362 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3363 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003364
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003365 timer T_itv := 0.0;
3366 T_itv.start;
3367 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003368 alt {
3369 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003370 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003371 st.num_overload := st.num_overload + 1;
3372 repeat;
3373 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003374 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003375 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003376 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003377 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003378 log("Rx LOAD_IND");
3379 /* FIXME: analyze/verify interval + contents */
3380 repeat;
3381 }
3382 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003383 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003384 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003385 [] T_itv.timeout {
3386 /* Send paging cmds based on elapsed time */
3387 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3388 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003389 var MobileIdentityV mi;
3390
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003391 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003392 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003393 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003394 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003395 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003396 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003397
3398 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003399 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 +02003400
3401 st.num_paging_sent := st.num_paging_sent + 1;
3402 }
3403 if (st.num_paging_sent < pkt_total) {
3404 /* Wait for interval to next PAGING COMMAND */
3405 var float time_now := T_total.read;
3406 var float next_sched := int2float(st.num_paging_sent)*interval;
3407 if (next_sched > time_now) {
3408 T_itv.start(next_sched - time_now);
3409 } else {
3410 T_itv.start(0.0);
3411 }
3412 } else {
3413 /* We are done, no need to keep counting */
3414 T_total.stop;
3415 }
3416 }
3417 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003418 }
3419 }
3420
3421 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3422 timer T_wait := 18.0;
3423 T_wait.start;
3424 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003425 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003426 [] L1CTL.receive { repeat; }
3427 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003428 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3429 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003430 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003431 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003432 }
Harald Welte68e495b2018-02-25 00:05:57 +01003433 }
3434
3435 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3436 " rcvd_ids=", st.num_paging_rcv_ids);
3437 return st;
3438}
3439
3440/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3441 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3442 * - that CCCH LOAD IND (PCH) are being generated
3443 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3444testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003445 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003446 var PagingTestCfg cfg := {
3447 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003448 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003449 load_factor := 0.8,
3450 exp_load_ind := true,
3451 exp_overload := false,
3452 use_tmsi := false
3453 };
3454 var PagingTestState st := f_TC_paging(cfg);
3455 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003456 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3457 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003458 } else {
3459 setverdict(pass);
3460 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003462}
3463
3464/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3465 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3466 * - that CCCH LOAD IND (PCH) are being generated
3467 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3468testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003469 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003470 var PagingTestCfg cfg := {
3471 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003472 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003473 load_factor := 0.8,
3474 exp_load_ind := true,
3475 exp_overload := false,
3476 use_tmsi := true
3477 };
3478 var PagingTestState st := f_TC_paging(cfg);
3479 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3481 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003482 } else {
3483 setverdict(pass);
3484 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003486}
3487
3488/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3489 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3490 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3491 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3492testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003493 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003494 var PagingTestCfg cfg := {
3495 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003496 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003497 load_factor := 2.0,
3498 exp_load_ind := true,
3499 exp_overload := true,
3500 use_tmsi := false
3501 };
3502 var PagingTestState st := f_TC_paging(cfg);
3503 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3504 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003505 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003506 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003507 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 +01003508 } else {
3509 setverdict(pass);
3510 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003511 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003512}
3513
3514/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3515 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3516 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3517 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3518testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003519 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003520 var PagingTestCfg cfg := {
3521 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003522 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003523 load_factor := 2.0,
3524 exp_load_ind := true,
3525 exp_overload := true,
3526 use_tmsi := true
3527 };
3528 var PagingTestState st := f_TC_paging(cfg);
3529 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3530 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003531 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003532 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003533 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 +01003534 } else {
3535 setverdict(pass);
3536 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003538}
3539
3540
Harald Welte93640c62018-02-25 16:59:33 +01003541/***********************************************************************
3542 * Immediate Assignment / AGCH
3543 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003544private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003545 len := 0,
3546 ma := ''B
3547}
Harald Welte93640c62018-02-25 16:59:33 +01003548
Harald Weltee8d750e2018-06-10 21:41:35 +02003549private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3550 return int2str(num_tx) & " sent, "
3551 & int2str(num_rx) & " received, "
3552 & int2str(num_del) & " deleted";
3553}
3554
3555private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3556 var L1ctlDlMessage l1_dl;
3557 timer T := 10.0;
3558 var integer num_tx := 0;
3559 var integer num_rx := 0;
3560 var integer num_del := 0;
3561 var charstring res_str;
3562 var float rx_ratio;
3563
Harald Welte10474062019-05-30 16:48:17 +02003564 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003565 f_init_l1ctl();
3566 f_l1_tune(L1CTL);
3567
3568 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003569 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003570 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3571 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003572 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003573 num_tx := num_tx+1;
3574 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003575 }
3576 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003577 T.start;
3578 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003579 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003580 num_del := num_del+1;
3581 repeat;
3582 }
3583 [] RSL_CCHAN.receive {
3584 repeat;
3585 }
3586 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003587 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3588 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3589 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003590 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003591 } else {
3592 num_rx := num_rx+1;
3593 }
3594 repeat;
3595 }
3596 [] L1CTL.receive { repeat; }
3597 [] T.timeout { }
3598 }
3599 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3600 log("AGCH test: " & res_str);
3601 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003603 }
3604 rx_ratio := int2float(num_rx) / int2float(num_tx);
3605 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003606 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 +02003607 } else {
3608 setverdict(pass);
3609 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003610 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003611}
3612
Harald Weltee8d750e2018-06-10 21:41:35 +02003613/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3614testcase TC_imm_ass_1000_20ms() runs on test_CT {
3615 f_TC_imm_ass(1000, 0.02, 0.25);
3616}
3617
3618/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3619testcase TC_imm_ass_200_0ms() runs on test_CT {
3620 f_TC_imm_ass(200, 0.0, 0.05);
3621}
3622
3623/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3624testcase TC_imm_ass_200_76ms() runs on test_CT {
3625 f_TC_imm_ass(150, 0.076, 1.00);
3626}
3627
3628
3629
Harald Welte48494ca2018-02-25 16:59:50 +01003630/***********************************************************************
3631 * BCCH
3632 ***********************************************************************/
3633
3634/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003635private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003636 GsmFrameNumber frame_number,
3637 SystemInformation si
3638}
3639
3640/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003641private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003642
3643/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003644private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003645
3646/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003647private function f_si_vecslot_contains(SystemInformationVector arr,
3648 RrMessageType key,
3649 boolean bcch_ext := false)
3650return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003651 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3652 var integer fn_mod51 := arr[i].frame_number mod 51;
3653 if (not bcch_ext and fn_mod51 == 2 or
3654 bcch_ext and fn_mod51 == 6) {
3655 if (arr[i].si.header.message_type == key) {
3656 return true;
3657 }
3658 }
3659 }
3660 return false;
3661}
3662
3663/* 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 +07003664private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3665 integer tc, RrMessageType key,
3666 boolean ext_bcch := false)
3667{
Harald Welte48494ca2018-02-25 16:59:50 +01003668 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003669 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003670 }
3671}
3672
3673/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003674private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3675 RrMessageType key)
3676return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003677 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3678 if (f_si_vecslot_contains(arr[tc], key) or
3679 f_si_vecslot_contains(arr[tc], key, true)) {
3680 return true;
3681 }
3682 }
3683 return false;
3684}
3685
3686/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003687private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3688 RrMessageType key,
3689 boolean bcch_ext := false,
3690 integer n := 1, integer m := 4)
3691return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003692 var integer count := 0;
3693 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003694 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3695 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003696 }
3697 for (var integer i:= 0; i < m; i := i + 1) {
3698 var integer fn_mod51 := arr[i].frame_number mod 51;
3699 if (not bcch_ext and fn_mod51 == 2 or
3700 bcch_ext and fn_mod51 == 6) {
3701 if (arr[i].si.header.message_type == key) {
3702 count := count + 1;
3703 }
3704 }
3705 }
3706 if (count >= n) {
3707 return true;
3708 } else {
3709 return false;
3710 }
3711}
3712
3713/* 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 +07003714private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3715 integer tc, RrMessageType key,
3716 boolean ext_bcch := false,
3717 integer n, integer m)
3718{
Harald Welte48494ca2018-02-25 16:59:50 +01003719 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003720 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003721 }
3722}
3723
3724/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003725private function f_si_vecslot_contains_only(SystemInformationVector arr,
3726 RrMessageType key,
3727 boolean bcch_ext := false)
3728return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003729 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3730 var integer fn_mod51 := arr[i].frame_number mod 51;
3731 if (not bcch_ext and fn_mod51 == 2 or
3732 bcch_ext and fn_mod51 == 6) {
3733 if (arr[i].si.header.message_type != key) {
3734 return false;
3735 }
3736 }
3737 }
3738 return true;
3739}
3740
3741/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003742private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3743 integer tc, RrMessageType key,
3744 boolean ext_bcch := false)
3745{
Harald Welte48494ca2018-02-25 16:59:50 +01003746 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003748 }
3749}
3750
3751/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003752private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003753 boolean bcch_extended,
3754 boolean si1_present,
3755 boolean si2bis_present,
3756 boolean si2ter_present,
3757 boolean si2quater_present,
3758 boolean si7_present,
3759 boolean si8_present,
3760 boolean si9_present,
3761 boolean si13_present,
3762 boolean si13alt_present,
3763 boolean si15_present,
3764 boolean si16_present,
3765 boolean si17_present,
3766 boolean si2n_present,
3767 boolean si21_present,
3768 boolean si22_present
3769}
3770
3771/* 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 +07003772private function f_validate_si_scheduling(SystemInformationConfig cfg,
3773 SystemInformationVectorPerTc si_per_tc)
3774{
Harald Welte48494ca2018-02-25 16:59:50 +01003775 var integer i;
3776 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3777 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003778 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003779 }
3780 }
3781 if (cfg.si1_present) {
3782 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3783 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3784 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3785 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3786 /* make sure *ALL* contain SI1 */
3787 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3788 }
3789 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3790 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3791 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3792 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3793 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3794 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3795
3796 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3797 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3798 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3799 * consecutive occurrences of TC = 4. */
3800 if (cfg.si2bis_present and not cfg.si2ter_present) {
3801 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3802 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3803 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3804 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3805 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3806 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3807 }
3808
3809 if (cfg.si7_present or cfg.si8_present) {
3810 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3811 * if System Information type 4 does not contain all information needed for cell
3812 * selection and reselection. */
3813 if (not cfg.bcch_extended) {
3814 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3815 }
3816 if (cfg.si7_present) {
3817 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3818 }
3819 if (cfg.si8_present) {
3820 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3821 }
3822 }
3823
3824 if (cfg.si2quater_present) {
3825 /* iii) System information type 2 quater is sent if needed, as determined by the system
3826 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3827 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3828 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3829 * within any of 4 consecutive occurrences of TC = 5. */
3830 if (not (cfg.bcch_extended)) {
3831 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3832 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3833 } else {
3834 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3835 }
3836 } else {
3837 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3838 }
3839 }
3840 if (cfg.si9_present) {
3841 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3842 * in system information type 3 as defined in 3GPP TS 44.018. */
3843 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3844 }
3845 if (cfg.si13_present) {
3846 /* vii) System Information type 13 is only related to the GPRS service. System Information
3847 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3848 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3849 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3850 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3851 * within any of 4 consecutive occurrences of TC=4. */
3852 if (not cfg.bcch_extended) {
3853 log("not-bccch-extended");
3854 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3855 } else {
3856 log("bccch-extended");
3857 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3858 }
3859 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003861 }
3862 }
3863 if (cfg.si16_present or cfg.si17_present) {
3864 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3865 * should not be sent in a cell where network sharing is used (see rule xv). */
3866 if (cfg.si22_present) {
3867 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3868 }
3869 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003871 }
3872 if (not cfg.bcch_extended) {
3873 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3874 }
3875 if (cfg.si16_present) {
3876 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3877 }
3878 if (cfg.si17_present) {
3879 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3880 }
3881 }
3882
3883 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3884 * broadcast information. The frequency with which they are sent is determined by the
3885 * system operator. System Information type 9 identifies the scheduling of System
3886 * Information type 18 and 20 messages. */
3887
3888 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3889 * Information Type 19 is present, then its scheduling shall be indicated in System
3890 * Information Type 9. */
3891
3892 if (cfg.si15_present) {
3893 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3894 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3895 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3896 * 4 consecutive occurrences of TC = 1. */
3897 if (not cfg.bcch_extended) {
3898 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3899 } else {
3900 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3901 }
3902 }
3903 if (cfg.si13alt_present) {
3904 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3905 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3906 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3907 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3908 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3909 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3910 * of TC = 4. */
3911 if (cfg.si13_present) {
3912 testcase.stop("Error: Cannot have SI13alt and SI13");
3913 }
3914 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003916 }
3917 if (not cfg.bcch_extended) {
3918 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3919 } else {
3920 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3921 }
3922 }
3923 if (cfg.si2n_present) {
3924 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3925 * as determined by the system operator. In the case that the message is sent on the
3926 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3927 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3928 * consecutive occurrences of TC = 4. */
3929 if (not cfg.bcch_extended) {
3930 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3931 } else {
3932 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3933 }
3934 }
3935 if (cfg.si21_present) {
3936 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3937 * determined by the system operator. If Extended Access Barring is in use in the cell
3938 * then this message is sent at least once within any of 4 consecutive occurrences of
3939 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3940 * cell then this message shall only be sent on BCCH Ext. */
3941 if (not cfg.bcch_extended) {
3942 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3943 } else {
3944 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3945 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003946 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003947 }
3948 }
3949 }
3950 if (cfg.si22_present) {
3951 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3952 * should not be sent in a cell where SoLSA is used (see rule viii). System
3953 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3954 * =2 and TC=6. */
3955 if (cfg.si16_present or cfg.si17_present) {
3956 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3957 }
3958 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3959 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003961 }
3962 if (not cfg.bcch_extended) {
3963 testcase.stop("Error: SI22 requires BCCH Extd!");
3964 } else {
3965 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3966 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3967 }
3968 }
3969}
3970
3971/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003972private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3973return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003974 timer T := duration;
3975 var SystemInformationVectorPerTc si_per_tc;
3976 var L1ctlDlMessage l1_dl;
3977
3978 /* initialize all per-TC vectors empty */
3979 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3980 si_per_tc[i] := {};
3981 }
3982
3983 /* flush all previous L1 queued msgs */
3984 pt.clear;
3985
3986 T.start;
3987 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003988 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003989 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3990 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3991 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003992 repeat;
3993 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003994
Harald Welte48494ca2018-02-25 16:59:50 +01003995 var integer tc := f_gsm_compute_tc(sig.frame_number);
3996 log("SI received at TC=", tc, ": ", sig.si);
3997 /* append to the per-TC bucket */
3998 si_per_tc[tc] := si_per_tc[tc] & { sig };
3999 repeat;
4000 }
4001 [] pt.receive { repeat; }
4002 [] T.timeout { }
4003 }
4004
4005 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4006 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4007 }
4008 log("si_per_tc=", si_per_tc);
4009 return si_per_tc;
4010}
4011
4012/* helper function: Set given SI via RSL + validate scheduling.
4013 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004014private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004015 var SystemInformationVectorPerTc si_per_tc;
4016 f_init_l1ctl();
4017 f_l1_tune(L1CTL);
4018
4019 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004020 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004021 f_validate_si_scheduling(si_cfg, si_per_tc);
4022
4023 setverdict(pass);
4024}
4025
4026testcase TC_si_sched_default() runs on test_CT {
4027 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004028 /* 2+3+4 are mandatory and set in f_init() */
4029 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004031}
4032
4033testcase TC_si_sched_1() runs on test_CT {
4034 f_init();
4035 si_cfg.si1_present := true;
4036 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004037 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004039}
4040
4041testcase TC_si_sched_2bis() runs on test_CT {
4042 f_init();
4043 si_cfg.si2bis_present := true;
4044 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4045 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004046 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004047}
4048
4049testcase TC_si_sched_2ter() runs on test_CT {
4050 f_init();
4051 si_cfg.si2ter_present := true;
4052 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4053 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004055}
4056
4057testcase TC_si_sched_2ter_2bis() runs on test_CT {
4058 f_init();
4059 si_cfg.si2bis_present := true;
4060 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4061 si_cfg.si2ter_present := true;
4062 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4063 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004064 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004065}
4066
4067testcase TC_si_sched_2quater() runs on test_CT {
4068 f_init();
4069 si_cfg.si2quater_present := true;
4070 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004071 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004073}
4074
4075testcase TC_si_sched_13() runs on test_CT {
4076 f_init();
4077 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004078 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004079 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004081}
4082
4083testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4084 f_init();
4085 si_cfg.si2bis_present := true;
4086 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4087 si_cfg.si2ter_present := true;
4088 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4089 si_cfg.si2quater_present := true;
4090 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4091 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004092 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004093 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004094 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004095}
4096
4097
Harald Welte68e495b2018-02-25 00:05:57 +01004098testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004099 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004100 /* FIXME: enable / disable individual BCCH info */
4101 //ts_RSL_BCCH_INFO(si_type, info);
4102 /* expect no ERROR REPORT after either of them *
4103 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004105}
4106
Harald Welte93640c62018-02-25 16:59:33 +01004107/***********************************************************************
4108 * Low-Level Protocol Errors / ERROR REPORT
4109 ***********************************************************************/
4110
Harald Welte01d982c2018-02-25 01:31:40 +01004111private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4112 timer T := 5.0;
4113 T.start;
4114 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004115 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004116 setverdict(pass);
4117 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004118 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004120 }
4121 [] RSL_CCHAN.receive {
4122 repeat;
4123 }
4124 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004125 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004126 }
4127 }
4128}
4129
4130/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4131testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004132 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004133 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4134 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004135 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004136
4137 f_exp_err_rep(RSL_ERR_PROTO);
4138}
4139
4140/* Provoke a mandatory IE error and match on ERROR REPORT */
4141testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004142 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004143
4144 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4145 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004146 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004147
4148 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4149}
4150
4151/* Provoke an IE content error and match on ERROR REPORT */
4152testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004153 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004154 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4155 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004156 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004157
4158 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4159}
4160
Harald Welteee25aae2019-05-19 14:32:37 +02004161/* attempt to activate channel with wrong RSL Message Discriminator IE */
4162function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4163 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4164 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4165 RSL.send(rsl);
4166 f_rslem_unregister(0, g_chan_nr);
4167}
4168testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4169 var ConnHdlr vc_conn;
4170 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4171
Harald Welte10474062019-05-30 16:48:17 +02004172 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004173
4174 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4175 vc_conn.done;
4176 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4177
4178 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4179}
4180
4181/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004182private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004183 var template (value) RSL_Message rsl_tx;
4184 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4185 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4186 RSL.send(rsl_tx);
4187 f_rslem_unregister(0, g_chan_nr);
4188}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004189private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004190 var template (value) RSL_Message rsl_tx;
4191 /* we first have to activate the dedicated channel */
4192 f_rsl_chan_act(g_pars.chan_mode);
4193 /* ... to then send an invalid RLL message */
4194 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4195 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4196 RSL.send(rsl_tx);
4197 f_rslem_unregister(0, g_chan_nr);
4198}
4199testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4200 var ConnHdlr vc_conn;
4201 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4202 var template (value) RSL_Message rsl_tx;
4203
Harald Welte10474062019-05-30 16:48:17 +02004204 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004205
4206 /* Common Channel with wrong message type */
4207 RSL_CCHAN.clear;
4208 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4209 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004210 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004211 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4212
4213 /* TRX Management */
4214 RSL_CCHAN.clear;
4215 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4216 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004217 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004218 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4219
4220 /* Dedicated Channel */
4221 RSL_CCHAN.clear;
4222 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4223 vc_conn.done;
4224 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4225
4226 /* RLL */
4227 RSL_CCHAN.clear;
4228 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4229 vc_conn.done;
4230 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4231}
4232
4233/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004234private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004235 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4236 f_rslem_unregister(0, g_chan_nr);
4237}
4238testcase TC_err_rep_wrong_sequence() runs on test_CT {
4239 var ConnHdlr vc_conn;
4240 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4241
Harald Welte10474062019-05-30 16:48:17 +02004242 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004243
4244 RSL_CCHAN.clear;
4245 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4246 vc_conn.done;
4247 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4248}
4249
Harald Welte93640c62018-02-25 16:59:33 +01004250/***********************************************************************
4251 * IPA CRCX/MDCX/DLCS media stream handling
4252 ***********************************************************************/
4253
Harald Weltea871a382018-02-25 02:03:14 +01004254/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004255private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004256 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4257 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004258}
4259testcase TC_ipa_dlcx_not_active() runs on test_CT {
4260 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004261 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004262 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4263 vc_conn.done;
4264}
Harald Welte68e495b2018-02-25 00:05:57 +01004265
Harald Weltea3f1df92018-02-25 12:49:55 +01004266/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004267private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004268 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4269 "IPA CRCX ACK");
4270 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4271 "IPA CRCX NACK");
4272}
4273testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4274 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004275 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004276 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4277 vc_conn.done;
4278}
4279
4280/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004281private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004282 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4283 "IPA CRCX ACK");
4284 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4285 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4286 var uint7_t rtp_pt2 := f_rnd_int(127);
4287 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4288 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4289 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4290 "IPA MDCX ACK");
4291 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4292 "IPA DLCX ACK");
4293}
4294testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4295 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004296 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004297 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4298 vc_conn.done;
4299}
4300
Harald Welte3ae11da2018-02-25 13:36:06 +01004301/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004302private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004303 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4304 "IPA CRCX ACK");
4305 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4306 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4307 var uint7_t rtp_pt2 := f_rnd_int(127);
4308 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4309 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4310 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4311 "IPA MDCX ACK");
4312 /* Second MDCX */
4313 remote_ip := f_rnd_int(c_UINT32_MAX);
4314 remote_port := f_rnd_int(c_UINT16_MAX);
4315 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4316 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4317 "IPA MDCX ACK");
4318 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4319 "IPA DLCX ACK");
4320}
4321testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4322 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004323 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004324 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4325 vc_conn.done;
4326}
4327
Harald Welte9912eb52018-02-25 13:30:15 +01004328/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004329private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004330 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4331 "IPA CRCX NACK");
4332}
4333testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4334 var ConnHdlrPars pars;
4335 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004336 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004337
4338 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4339 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4340 vc_conn.done;
4341
4342 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4343 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4344 vc_conn.done;
4345}
4346
Harald Weltea3f1df92018-02-25 12:49:55 +01004347
Harald Welte883340c2018-02-28 18:59:29 +01004348/***********************************************************************
4349 * PCU Socket related tests
4350 ***********************************************************************/
4351
Harald Welte07bd2d22019-05-25 11:03:30 +02004352/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004353friend 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 +01004354runs on test_CT {
4355 timer T := 3.0;
4356
4357 /* we don't expect any RTS.req before PDCH are active */
4358 T.start;
4359 alt {
4360 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004362 }
4363 [] PCU.receive { repeat; }
4364 [] T.timeout { }
4365 }
4366
4367 /* Send PDCH activate request for known PDCH timeslot */
4368 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4369
4370 /* we now expect RTS.req for this timeslot (only) */
4371 T.start;
4372 alt {
4373 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4374 setverdict(pass);
4375 }
4376 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4377 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004379 }
4380 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004381 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004382 }
4383 [] PCU.receive { repeat; }
4384 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004386 }
4387 [not exp_success] T.timeout {
4388 setverdict(pass);
4389 }
4390 }
4391}
4392
Harald Welte07bd2d22019-05-25 11:03:30 +02004393/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004394friend 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 +01004395runs on test_CT {
4396 timer T := 3.0;
4397
4398 /* Send PDCH activate request for known PDCH timeslot */
4399 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 +02004400 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4401 * when it will actually have been executed in the BTS */
4402 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004403 PCU.clear;
4404 /* we now expect no RTS.req for this timeslot */
4405 T.start;
4406 alt {
4407 [] 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 +02004408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004409 }
4410 [] PCU.receive { repeat; }
4411 [] T.timeout {
4412 setverdict(pass);
4413 }
4414 }
4415}
4416
Harald Weltead033dc2019-05-25 17:28:16 +02004417friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004418 f_init();
4419 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4420}
4421
Harald Welte883340c2018-02-28 18:59:29 +01004422/* PDCH activation via PCU socket; check for presence of RTS.req */
4423testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004424 f_init_pcu_test();
4425
Harald Welte883340c2018-02-28 18:59:29 +01004426 f_TC_pcu_act_req(0, 0, 7, true);
4427}
4428
4429/* PDCH activation via PCU socket on non-PDCU timeslot */
4430testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004431 f_init_pcu_test();
4432
Harald Welte883340c2018-02-28 18:59:29 +01004433 f_TC_pcu_act_req(0, 0, 1, false);
4434}
4435
4436/* PDCH activation via PCU socket on wrong BTS */
4437testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004438 f_init_pcu_test();
4439
Harald Welte883340c2018-02-28 18:59:29 +01004440 f_TC_pcu_act_req(23, 0, 7, false);
4441}
4442
4443/* PDCH activation via PCU socket on wrong TRX */
4444testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004445 f_init_pcu_test();
4446
Harald Welte883340c2018-02-28 18:59:29 +01004447 f_TC_pcu_act_req(0, 23, 7, false);
4448}
4449
4450/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4451testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004452 f_init_pcu_test();
4453
Harald Welte883340c2018-02-28 18:59:29 +01004454 /* Activate PDCH */
4455 f_TC_pcu_act_req(0, 0, 7, true);
4456 f_sleep(1.0);
4457 /* and De-Activate again */
4458 f_TC_pcu_deact_req(0, 0, 7);
4459}
4460
4461/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4462testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004463 f_init_pcu_test();
4464
Harald Welte883340c2018-02-28 18:59:29 +01004465 f_TC_pcu_deact_req(0, 0, 1);
4466}
4467
4468/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4469testcase TC_pcu_ver_si13() runs on test_CT {
4470 const octetstring si13 := '00010203040506070909'O;
4471 var PCUIF_send_data sd;
4472 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004473 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004474
4475 /* Set SI13 via RSL */
4476 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004477
Harald Welte883340c2018-02-28 18:59:29 +01004478 T.start;
4479 alt {
4480 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4481 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4482 setverdict(pass);
4483 } else {
4484 repeat;
4485 }
4486 }
4487 [] PCU.receive { repeat; }
4488 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004490 }
4491 }
4492}
4493
4494private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4495
4496/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004497friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004498 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4499runs on test_CT
4500{
4501 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4502 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4503}
4504
4505/* 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 +02004506friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4507 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004508runs on test_CT
4509{
4510 var PCUIF_send_data sd;
4511
4512 timer T := 3.0;
4513 T.start;
4514 alt {
4515 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4516 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4517 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4518 sd.data.u.rts_req.fn, sapi, data);
4519 }
4520 [] PCU.receive { repeat; }
4521 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004522 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004523 }
4524 }
4525}
4526
4527/* Send DATA.req on invalid BTS */
4528testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004529 var TfiUsfArr tua := f_TfiUsfArrInit();
4530 var octetstring data := '0000'O & f_rnd_octstring(21);
4531
4532 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004533
Harald Welte883340c2018-02-28 18:59:29 +01004534 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004535 f_TfiUsfArrSet(tua, 7, 0);
4536 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4537 f_sleep(1.0);
4538
4539 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004540}
4541
4542/* Send DATA.req on invalid TRX */
4543testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004544 var TfiUsfArr tua := f_TfiUsfArrInit();
4545 var octetstring data := '0000'O & f_rnd_octstring(21);
4546
4547 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004548
Harald Welte883340c2018-02-28 18:59:29 +01004549 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004550 f_TfiUsfArrSet(tua, 7, 0);
4551 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4552 f_sleep(1.0);
4553
4554 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004555}
4556
4557/* Send DATA.req on invalid timeslot */
4558testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004559 var TfiUsfArr tua := f_TfiUsfArrInit();
4560 var octetstring data := '0000'O & f_rnd_octstring(21);
4561
4562 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004563
Harald Welte883340c2018-02-28 18:59:29 +01004564 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004565 f_TfiUsfArrSet(tua, 7, 0);
4566 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4567 f_sleep(1.0);
4568
4569 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004570}
4571
4572/* Send DATA.req on timeslot that hasn't been activated */
4573testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004574 var TfiUsfArr tua := f_TfiUsfArrInit();
4575 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004576
Harald Welte7162a612019-05-26 12:56:09 +02004577 f_virtphy_common();
4578
4579 f_TfiUsfArrSet(tua, 7, 0);
4580 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4581 f_sleep(1.0);
4582
4583 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004584}
4585
Harald Weltead033dc2019-05-25 17:28:16 +02004586private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004587 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4588 boolean wait_rts := true)
4589runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004590 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004591 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004592
4593 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004594 if (wait_rts) {
4595 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4596 } else {
4597 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4598 }
Harald Weltead033dc2019-05-25 17:28:16 +02004599
4600 T.start;
4601 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004602 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004603 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4604 setverdict(pass);
4605 }
Harald Welte7162a612019-05-26 12:56:09 +02004606 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4607 setverdict(fail, "Received unexpected ", rx_dl);
4608 }
Harald Weltead033dc2019-05-25 17:28:16 +02004609 [] L1CTL.receive {
4610 repeat;
4611 }
Harald Welte7162a612019-05-26 12:56:09 +02004612 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004613 setverdict(fail, "Timeout waiting for ", data);
4614 }
Harald Welte7162a612019-05-26 12:56:09 +02004615 [not expect_data] T.timeout {
4616 setverdict(pass);
4617 }
Harald Weltead033dc2019-05-25 17:28:16 +02004618 }
4619}
4620
4621private function f_disable_dynamic_ts() runs on test_CT
4622{
4623 f_init_vty_bsc();
4624 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4625 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4626 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4627 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004628 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004629}
4630
4631private function f_virtphy_common() runs on test_CT {
4632 f_disable_dynamic_ts();
4633 f_init_l1ctl();
4634 f_l1_tune(L1CTL);
4635}
4636
4637testcase TC_pcu_data_req_pdtch() runs on test_CT {
4638 var TfiUsfArr tua := f_TfiUsfArrInit();
4639 var octetstring data := '0000'O & f_rnd_octstring(21);
4640
4641 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004642
Harald Welte883340c2018-02-28 18:59:29 +01004643 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004644 f_TfiUsfArrSet(tua, 7, 0);
4645 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4646 f_sleep(1.0);
4647
4648 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004649}
4650
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004651/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004652testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004653 var TfiUsfArr tua := f_TfiUsfArrInit();
4654 var octetstring data := '0000'O & f_rnd_octstring(21);
4655
4656 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004657
Harald Welte883340c2018-02-28 18:59:29 +01004658 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004659 f_TfiUsfArrSet(tua, 7, 0);
4660 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4661 f_sleep(1.0);
4662
4663 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004664}
4665
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004666private function f_TC_pcu_ptcch_ul(uint16_t ra)
4667runs on test_CT {
4668 var template PCUIF_Message pcu_rach_ind;
4669 var PCUIF_send_data sd;
4670 var GsmFrameNumber fn;
4671 timer T;
4672
4673 /* Send an Access Burst on PTCCH/U over the Um-interface */
4674 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4675 chan_nr := ts_RslChanNr_PDCH(7),
4676 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4677
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004678 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4679 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004680
4681 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4682 T.start(52.0 * 4.615 / 1000.0);
4683 alt {
4684 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4685 log("Rx an Access Burst on the PCU interface: ", sd.data);
4686 setverdict(pass);
4687 T.stop;
4688 }
4689 [] PCU.receive { repeat; }
4690 [] T.timeout {
4691 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4692 /* Keep going, that's not the end of the world */
4693 }
4694 }
4695}
4696
4697testcase TC_pcu_ptcch() runs on test_CT {
4698 var L1ctlDlMessage dl;
4699 var octetstring data;
4700 timer T;
4701
4702 f_init_pcu_test();
4703 f_init_l1ctl();
4704 f_l1_tune(L1CTL);
4705
4706 /* Activate PDCH channel on TS7 */
4707 f_TC_pcu_act_req(0, 0, 7, true);
4708
4709 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004710 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004711 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004712 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004713 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004714
4715 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4716 for (var integer i := 0; i < 16; i := i + 1) {
4717 log("Sending an Access Burst towards the L1CTL interface");
4718 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4719 }
4720
4721 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4722 data := f_rnd_octstring(23);
4723
4724 /* Verify PTCCH/D: send a random data block, make sure it's received */
4725 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4726 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4727
4728 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4729 * let's give it more time in case if we miss the beginning. */
4730 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4731 alt {
4732 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4733 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4734 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4735 frame := data)) -> value dl {
4736 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4737 setverdict(pass);
4738 T.stop;
4739 }
4740 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4741 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4742 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4743 l2_data := data)) -> value dl {
4744 log("Rx PTCCH/D data block on L1CTL: ", dl);
4745 setverdict(pass);
4746 T.stop;
4747 }
4748 [] L1CTL.receive { repeat; }
4749 [] T.timeout {
4750 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4751 }
4752 }
4753}
4754
Harald Welte883340c2018-02-28 18:59:29 +01004755/* Send AGCH from PCU; check it appears on Um side */
4756testcase TC_pcu_data_req_agch() runs on test_CT {
4757 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004758 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004759 f_init_l1ctl();
4760 f_l1_tune(L1CTL);
4761
4762 f_TC_pcu_act_req(0, 0, 7, true);
4763 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4764
4765 T.start;
4766 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004767 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004768 setverdict(pass);
4769 }
4770 [] L1CTL.receive { repeat; }
4771 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004772 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004773 }
4774 }
4775}
4776
Harald Welte928622b2019-05-26 13:22:59 +02004777/* Send AGCH from PCU; check it appears on Um side */
4778testcase TC_pcu_data_req_pch() runs on test_CT {
4779 timer T := 3.0;
4780 f_init_pcu_test();
4781 f_init_l1ctl();
4782 f_l1_tune(L1CTL);
4783
4784 f_TC_pcu_act_req(0, 0, 7, true);
4785 /* three characters prefix: last 3 digits of IMSI as ASCII */
4786 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4787
4788 T.start;
4789 alt {
4790 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4791 setverdict(pass);
4792 }
4793 [] L1CTL.receive { repeat; }
4794 [] T.timeout {
4795 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4796 }
4797 }
4798}
4799
Harald Welte883340c2018-02-28 18:59:29 +01004800/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4801testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4802 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004803 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004804 f_init_l1ctl();
4805 f_l1_tune(L1CTL);
4806
4807 /* append 3 last imsi digits so BTS can compute pagng group */
4808 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4809
4810 timer T := 0.5;
4811 T.start;
4812 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004813 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004814 /* TODO: verify paging group */
4815 setverdict(pass);
4816 }
4817 [] L1CTL.receive { repeat; }
4818 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004819 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004820 }
4821 }
4822}
4823
4824/* Send RACH from Um side, expect it to show up on PCU socket */
4825testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004826 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004827 f_init_l1ctl();
4828 f_l1_tune(L1CTL);
4829
4830 var GsmFrameNumber fn_last := 0;
4831 for (var integer i := 0; i < 1000; i := i+1) {
4832 var OCT1 ra := f_rnd_ra_ps();
4833 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4834 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004836 }
4837 fn_last := fn;
4838
4839 timer T := 2.0;
4840 T.start;
4841 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004842 [] 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 +01004843 T.stop;
4844 }
4845 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004846 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004847 }
4848 [] PCU.receive { repeat; }
4849 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004850 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004851 }
4852 }
4853 }
4854 setverdict(pass);
4855}
4856
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004857/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4858 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4859testcase TC_pcu_ext_rach_content() runs on test_CT {
4860 var template PCUIF_Message pcu_rach_ind;
4861 var GsmFrameNumber fn_last := 0;
4862 var L1ctlRachSynchSeq synch_seq;
4863 var PCUIF_BurstType pcu_bt;
4864 var GsmFrameNumber fn;
4865 var BIT11 ra11;
4866
4867 f_init_pcu_test();
4868 f_init_l1ctl();
4869 f_l1_tune(L1CTL);
4870
4871 for (var integer i := 0; i < 1000; i := i+1) {
4872 /* We need to test both TS1 & TS2 */
4873 if (i rem 2 == 0) {
4874 synch_seq := RACH_SYNCH_SEQ_TS1;
4875 pcu_bt := BURST_TYPE_1;
4876 } else {
4877 synch_seq := RACH_SYNCH_SEQ_TS2;
4878 pcu_bt := BURST_TYPE_2;
4879 }
4880
4881 ra11 := f_rnd_ra11_ps();
4882 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4883 if (fn == fn_last) {
4884 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4885 "Two RACH in same FN?!?");
4886 }
4887 fn_last := fn;
4888
4889 /* Compose the expected message */
4890 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004891 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004892 ra := bit2int(ra11),
4893 is_11bit := 1,
4894 burst_type := pcu_bt,
4895 fn := fn);
4896
4897 timer T := 2.0;
4898 T.start;
4899 alt {
4900 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4901 T.stop;
4902 }
4903 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4904 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4905 }
4906 [] PCU.receive { repeat; }
4907 [] T.timeout {
4908 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4909 }
4910 }
4911 }
4912 setverdict(pass);
4913}
4914
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004915private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4916runs on test_CT {
4917 var template PCUIF_send_data sdt;
4918 var PCUIF_send_data sd;
4919 var int16_t lqual_cb;
4920 timer T := 1.0;
4921
4922 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4923 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4924
4925 /* Send a random PDTCH frame over Um */
4926 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4927 '0000'O & f_rnd_octstring(21)));
4928
4929 T.start;
4930 alt {
4931 /* If expected link quality is above the threshold */
4932 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4933 lqual_cb := sd.data.u.data_ind.lqual_cb;
4934 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4935
4936 /* Make sure the actual link quality matches the expected value */
4937 if (not match(lqual_cb, lqual_cb_exp)) {
4938 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4939 "expected value ", lqual_cb_exp));
4940 } else {
4941 setverdict(pass);
4942 }
4943 }
4944 /* If expected link quality is below the threshold */
4945 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4946 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4947 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4948 }
4949 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4950 [] PCU.receive { repeat; }
4951 [lqual_cb_exp < thresh] T.timeout {
4952 log("Rx nothing, as expected");
4953 setverdict(pass);
4954 }
4955 [lqual_cb_exp >= thresh] T.timeout {
4956 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4957 "Timeout waiting for PCUIF_DATA.ind");
4958 }
4959 }
4960}
4961
4962/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4963testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4964 f_init_pcu_test();
4965 PCU.clear;
4966
4967 f_init_l1ctl();
4968 f_l1_tune(L1CTL);
4969
4970 /* Activate a PDCH channel on TS7 */
4971 f_TC_pcu_act_req(0, 0, 7, true);
4972
4973 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004974 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004975 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004976 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004977 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004978
4979 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4980 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4981 var TrxcMessage ret;
4982
4983 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4984 valueof(ts_TRXC_FAKE_CI(i)));
4985
4986 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4987 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4988 }
4989}
4990
Harald Welte883340c2018-02-28 18:59:29 +01004991/* Send PAGING via RSL, expect it to shw up on PCU socket */
4992testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004993 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004994
4995 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004996 var MobileIdentityLV mi_lv;
4997 var octetstring mi_lv_enc;
4998 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004999 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005000
Harald Welte883340c2018-02-28 18:59:29 +01005001 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005002 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005003 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005004 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005005 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005006
5007 /* Fancy encoding for PCUIF */
5008 mi_lv := valueof(ts_MI_LV(mi));
5009 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5010 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005011
5012 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005013 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005014 T.start;
5015 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005016 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005017 }
5018 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005020 }
5021 [] PCU.receive { repeat; }
5022 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005023 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005024 }
5025 }
5026 }
5027 setverdict(pass);
5028}
5029
Harald Welted66c9b82019-05-25 09:03:15 +02005030/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5031testcase TC_pcu_time_ind() runs on test_CT {
5032 var PCUIF_send_data pcu_sd;
5033 var integer num_time_ind := 0;
5034 var integer first_fn, last_fn;
5035 var float test_duration := 5.0;
5036 timer T;
5037
5038 f_init_pcu_test();
5039 f_TC_pcu_act_req(0, 0, 7, true);
5040
5041 PCU.clear;
5042 T.start(test_duration);
5043 alt {
5044 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5045 num_time_ind := num_time_ind + 1;
5046 if (not isbound(first_fn)) {
5047 first_fn := pcu_sd.data.u.time_ind.fn;
5048 }
5049 last_fn := pcu_sd.data.u.time_ind.fn;
5050 repeat;
5051 }
5052 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5053 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5054 repeat;
5055 }
5056 [] PCU.receive {
5057 repeat;
5058 }
5059 [] T.timeout {}
5060 }
5061 var integer fn_expired := last_fn - first_fn;
5062 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5063
5064 /* verify the number of frames expired matches our expectation */
5065 const float c_GSM_FN_DURATION_MS := 4.61538;
5066 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005067 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005068 if (not match(fn_expired, t_fn_expected)) {
5069 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5070 }
5071
5072 /* There are three TIME.ind in every fn MOD 13 */
5073 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5074 /* Add some tolerance */
5075 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5076 if (not match(num_time_ind, t_time_ind_exp)) {
5077 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5078 }
5079
5080 setverdict(pass);
5081}
5082
Harald Welte4832c862019-05-25 14:57:18 +02005083/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5084testcase TC_pcu_rts_req() runs on test_CT {
5085 var PCUIF_send_data pcu_sd;
5086 var integer first_fn, last_fn;
5087 var integer num_rts_pdtch := 0;
5088 var integer num_rts_ptcch := 0;
5089 var float test_duration := 5.0;
5090 timer T;
5091
5092 f_init_pcu_test();
5093 f_TC_pcu_act_req(0, 0, 7, true);
5094
5095 PCU.clear;
5096 T.start(test_duration);
5097 alt {
5098 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5099 -> value pcu_sd {
5100 num_rts_pdtch := num_rts_pdtch + 1;
5101 if (not isbound(first_fn)) {
5102 first_fn := pcu_sd.data.u.rts_req.fn;
5103 }
5104 last_fn := pcu_sd.data.u.rts_req.fn;
5105 repeat;
5106 }
5107 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5108 -> value pcu_sd {
5109 num_rts_ptcch := num_rts_ptcch + 1;
5110 if (not isbound(first_fn)) {
5111 first_fn := pcu_sd.data.u.rts_req.fn;
5112 }
5113 last_fn := pcu_sd.data.u.rts_req.fn;
5114 repeat;
5115 }
5116 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5117 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5118 repeat;
5119 }
5120 [] PCU.receive {
5121 repeat;
5122 }
5123 [] T.timeout {}
5124 }
5125 var integer fn_expired := last_fn - first_fn;
5126 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5127 ", num_rts_ptcch=", num_rts_ptcch);
5128
5129 /* verify the number of frames expired matches our expectation */
5130 const float c_GSM_FN_DURATION_MS := 4.61538;
5131 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005132 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005133 if (not match(fn_expired, t_fn_expected)) {
5134 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5135 }
5136
5137 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5138 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5139 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5140 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5141 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5142 t_ptcch_exp);
5143 }
5144
5145 /* We have 12 PDTCH blocks every 52-multiframe */
5146 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5147 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5148 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5149 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5150 t_pdtch_exp);
5151 }
5152
5153 setverdict(pass);
5154}
5155
Harald Welte07bd2d22019-05-25 11:03:30 +02005156/* test for generating Abis side OML ALERT from the PCU */
5157testcase TC_pcu_oml_alert() runs on test_CT {
5158 var PCUIF_send_data pcu_sd;
5159 var integer num_time_ind := 0;
5160 var integer first_fn, last_fn;
5161 var float test_duration := 5.0;
5162 timer T;
5163
5164 f_init_pcu_test();
5165 f_TC_pcu_act_req(0, 0, 7, true);
5166
5167 /* re-connect CTRL port from BTS to BSC */
5168 f_ipa_ctrl_stop();
5169 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5170
5171 /* Send that OML Alert */
5172 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5173
5174 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5175 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5176 setverdict(pass);
5177}
5178
Harald Welteeaa9a862019-05-26 23:01:08 +02005179/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5180private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5181 var PCUIF_Message first_info;
5182 var integer pcu_conn_id := -1;
5183 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5184 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5185 var OCT4 tlli := '01020304'O;
5186 var OCT1 cause := '23'O;
5187 timer T := 5.0;
5188
5189 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5190
5191 f_l1_tune(L1CTL);
5192 RSL.clear;
5193
5194 f_est_dchan();
5195 L1CTL.clear;
5196
5197 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5198
5199 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5200 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5201 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5202
5203 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5204 T.start;
5205 alt {
5206 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5207 setverdict(pass);
5208 }
5209 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5210 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5211 }
5212 [] PCU.receive {
5213 repeat;
5214 }
5215 [] T.timeout {
5216 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5217 }
5218 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005219
5220 /* release the channel */
5221 f_rsl_chan_deact();
5222 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5223 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005224}
5225testcase TC_pcu_rr_suspend() runs on test_CT {
5226 var ConnHdlrPars pars;
5227 var ConnHdlr vc_conn;
5228
5229 f_init();
5230
5231 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5232 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5233 vc_conn.done;
5234}
Harald Welte07bd2d22019-05-25 11:03:30 +02005235
Harald Weltea2e0e942019-05-27 18:12:53 +02005236/* Ensure that PCUIF socket can accept only a single connection */
5237testcase TC_pcu_socket_connect_multi() runs on test_CT {
5238 timer T := 5.0;
5239
5240 /* this (among other things) establishes the first connection to the PCUIF socket */
5241 f_init();
5242
5243 /* try to establish a second connection, expect it to fail */
5244 PCU.send(UD_connect:{mp_pcu_socket, -1});
5245 T.start;
5246 alt {
5247 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5248 setverdict(pass);
5249 }
5250 [] PCU.receive(UD_connect_result:?) {
5251 setverdict(fail, "Unexpected unix domain connect result");
5252 }
5253 [] T.timeout {
5254 setverdict(pass);
5255 }
5256 }
5257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5258}
5259
Harald Weltec8effb72019-05-27 18:23:04 +02005260/* Ensure that PCUIF socket can disconnect + reconnect */
5261testcase TC_pcu_socket_reconnect() runs on test_CT {
5262 /* this (among other things) establishes the first connection to the PCUIF socket */
5263 f_init();
5264
5265 f_sleep(1.0);
5266
5267 f_pcuif_close(PCU, g_pcu_conn_id);
5268 g_pcu_conn_id := -1;
5269
5270 f_sleep(1.0);
5271
5272 /* re-connect */
5273 PCU.clear;
5274 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5275 setverdict(pass);
5276
5277 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5278}
5279
Harald Weltebe030482019-05-27 22:29:35 +02005280/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005281private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5282runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005283 var L1ctlDlMessage l1_dl;
5284 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005285 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005286 timer T := 5.0;
5287 T.start;
5288 alt {
5289 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005290 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5291 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005292 repeat;
5293 }
5294 }
5295 [] pt.receive {
5296 repeat;
5297 }
5298 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5300 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005301 }
5302 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005303 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005304}
5305
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005306/* Check if GPRS Indicator is present in RR System Information of a given type */
5307private function f_si_has_gprs_indicator(RrMessageType si_type)
5308runs on test_CT return boolean {
5309 var SystemInformation si := f_get_si(L1CTL, si_type);
5310
5311 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005312 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005313 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005314 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005315 }
5316
5317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5318 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005319}
5320
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005321/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5322private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5323runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005324 /* don't call f_init() as this would connect PCU socket */
5325 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005326
5327 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005328 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005329 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005330
5331 f_init_l1ctl();
5332 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005333 f_sleep(2.0);
5334 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005335
5336 if (f_si_has_gprs_indicator(si_type)) {
5337 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005338 } else {
5339 setverdict(pass);
5340 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005341
Harald Weltebe030482019-05-27 22:29:35 +02005342 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5343}
5344
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005345testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5346 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5347}
Harald Weltebe030482019-05-27 22:29:35 +02005348
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005349testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5350 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5351}
5352
5353/* Ensure that GPRS capability is advertised after PCU socket connect */
5354private function f_TC_pcu_socket_connect(RrMessageType si_type)
5355runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005356 /* this (among other things) establishes the first connection to the PCUIF socket */
5357 f_init();
5358 f_init_l1ctl();
5359 f_l1_tune(L1CTL);
5360
5361 f_sleep(2.0);
5362 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005363
5364 if (not f_si_has_gprs_indicator(si_type)) {
5365 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005366 } else {
5367 setverdict(pass);
5368 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005369
Harald Weltebe030482019-05-27 22:29:35 +02005370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5371}
5372
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005373testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5374 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5375}
Harald Weltebe030482019-05-27 22:29:35 +02005376
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005377testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5378 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5379}
5380
5381/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5382private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5383runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005384 /* this (among other things) establishes the first connection to the PCUIF socket */
5385 f_init();
5386 f_init_l1ctl();
5387 f_l1_tune(L1CTL);
5388
5389 f_pcuif_close(PCU, g_pcu_conn_id);
5390 g_pcu_conn_id := -1;
5391
5392 f_sleep(1.0);
5393
5394 /* re-connect */
5395 PCU.clear;
5396 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5397
5398 f_sleep(2.0);
5399 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005400
5401 if (f_si_has_gprs_indicator(si_type)) {
5402 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005403 } else {
5404 setverdict(pass);
5405 }
5406
5407 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5408}
5409
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005410testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5411 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5412}
5413
5414testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5415 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5416}
5417
Oliver Smithf5239c72019-08-28 10:01:25 +02005418/* 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) */
5419testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5420 var SystemInformation si3 := valueof(ts_SI3_default);
5421
5422 f_init();
5423
Harald Welte76220222020-10-11 20:32:44 +02005424 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5425 * information */
5426 timer T := 2.0;
5427 T.start;
5428 alt {
5429 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5430 [] T.timeout {}
5431 }
5432
Oliver Smithf5239c72019-08-28 10:01:25 +02005433 /* Verify cell_id */
5434 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5435 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5436 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005437 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5438 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5439 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005440 }
5441
5442 /* Verify LAC */
5443 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5444 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5445 if (lac_si3 != lac_pcu) {
5446 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5447 }
5448
5449 setverdict(pass);
5450}
Harald Welted66c9b82019-05-25 09:03:15 +02005451
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005452/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5453testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5454 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005455 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005456
5457 f_init();
5458
5459 info_ind := g_pcu_last_info.u.info_ind;
5460
5461 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5462 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5463 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5464 /* Skip inactive timeslots */
5465 continue;
5466 }
5467
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005468 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005469 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005470 else
5471 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005472
5473 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005474 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005475 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005476 hsn := fhp.maio_hsn.hsn,
5477 maio := fhp.maio_hsn.maio,
5478 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005479 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005480 } else {
5481 tr_ts := tr_PCUIF_InfoTrxTsH0;
5482 }
5483
5484 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5485 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5486 if (not match(ts, tr_ts)) {
5487 setverdict(fail, "Hopping parameters do not match: ",
5488 "received ", ts, " vs expected ", tr_ts);
5489 } else {
5490 setverdict(pass);
5491 }
5492 }
5493 }
5494}
5495
Alexander Couzens5283f552020-07-28 15:39:04 +02005496/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5497testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5498 f_init_vty_bsc();
5499 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5500 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5501
5502 f_init();
5503
5504 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5505 if (not ischosen(remote_addr.v10)) {
5506 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5507 log2str("Unexpected remote_addr: ", remote_addr));
5508 }
5509
5510 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5511 setverdict(fail, "Received address family is not IPv4");
5512 }
5513
5514 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5515 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5516 }
5517
5518 setverdict(pass);
5519}
5520
5521/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5522testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5523 f_init_vty_bsc();
5524 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5525
5526 f_init();
5527
5528 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5529 if (not ischosen(remote_addr.v10)) {
5530 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5531 log2str("Unexpected remote_addr: ", remote_addr));
5532 }
5533
5534 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5535 setverdict(fail, "Received address family is not IPv6");
5536 }
5537
5538 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5539 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5540 }
5541
5542 setverdict(pass);
5543}
5544
Harald Welte3d04ae62018-04-04 20:29:05 +02005545/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005546 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005547 ***********************************************************************/
5548
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005549private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5550 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005551runs on ConnHdlr {
5552 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005553
5554 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005555 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005556 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5557 repeat;
5558 }
5559 }
5560}
5561
5562private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5563runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005564 /* Expect BTS to immediately acknowledge activation as PDCH */
5565 PCU.clear;
5566 f_rsl_chan_act(g_pars.chan_mode);
5567 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005568 timer T_wait := 2.0;
5569 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005570 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005571 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005572 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005573 [] T_wait.timeout {
5574 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5575 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5576 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005577 }
5578 /* try to activate this PDCH from the PCU point of view */
5579 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5580 /* FIXME: is there a response? */
5581}
5582
5583private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5584runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005585 /* Send RSL CHAN REL (deactivate) */
5586 PCU.clear;
5587 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5588 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005589 timer T_wait := 2.0;
5590 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005591 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005592 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005593 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005594 [] T_wait.timeout {
5595 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5596 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5597 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005598 }
5599 /* Emulate PCU asking BTS to deactivate PDCH */
5600 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5601 alt {
5602 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5603 setverdict(pass);
5604 }
5605 [] RSL.receive { repeat; }
5606 }
5607}
5608
5609/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005610private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005611 var PCUIF_Message first_info;
5612 var integer ts_nr := g_chan_nr.tn;
5613 var integer trx_nr := 0;
5614 var integer bts_nr := 0;
5615 var integer pcu_conn_id := -1;
5616
5617 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5618
5619 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5620 f_sleep(3.0);
5621 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5622 setverdict(pass);
5623}
5624testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5625 var ConnHdlrPars pars;
5626 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005627 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005628
5629 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5630 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5631 vc_conn.done;
5632}
5633
5634/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005635private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005636 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005637 var integer pcu_conn_id := -1;
5638
5639 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5640
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005641 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5642 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5643 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005644 setverdict(pass);
5645}
5646testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5647 var ConnHdlrPars pars;
5648 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005649 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005650
5651 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5652 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5653 vc_conn.done;
5654}
5655
5656/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005657private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005658 var PCUIF_Message first_info;
5659 var integer ts_nr := g_chan_nr.tn;
5660 var integer trx_nr := 0;
5661 var integer bts_nr := 0;
5662 var integer pcu_conn_id := -1;
5663
5664 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5665
5666 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005667 /* Send a second Chan Activ and expect it to be NACKed */
5668 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5669 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005670 setverdict(pass);
5671}
5672testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5673 var ConnHdlrPars pars;
5674 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005675 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005676
5677 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5678 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5679 vc_conn.done;
5680}
5681
5682/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005683private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005684 var PCUIF_Message first_info;
5685 var integer ts_nr := g_chan_nr.tn;
5686 var integer trx_nr := 0;
5687 var integer bts_nr := 0;
5688 var integer pcu_conn_id := -1;
5689 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5690
5691 /* register for the TCH/F channel number */
5692 f_rslem_register(0, chan_nr);
5693
5694 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5695
5696 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5697 "RSL CHAN ACT");
5698 setverdict(pass);
5699}
5700testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5701 var ConnHdlrPars pars;
5702 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005703 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005704
5705 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5706 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5707 vc_conn.done;
5708}
5709
5710/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005711private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005712 var PCUIF_Message first_info;
5713 var integer ts_nr := g_chan_nr.tn;
5714 var integer trx_nr := 0;
5715 var integer bts_nr := 0;
5716 var integer pcu_conn_id := -1;
5717 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5718 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5719
5720 /* register for the TCH/H channel numbers */
5721 f_rslem_register(0, chan_nr[0]);
5722 f_rslem_register(0, chan_nr[1]);
5723
5724 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5725
5726 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5727 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5728 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5729 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5730 setverdict(pass);
5731}
5732testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5733 var ConnHdlrPars pars;
5734 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005735 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005736
5737 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5738 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5739 vc_conn.done;
5740}
5741
Harald Welte9bbbfb52018-04-05 09:33:19 +02005742/***********************************************************************
5743 * IPA Style Dynamic Timeslot Support
5744 ***********************************************************************/
5745
5746private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5747runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005748 /* Expect BTS to immediately acknowledge activation as PDCH */
5749 PCU.clear;
5750 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5751 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005752 timer T_wait := 2.0;
5753 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005754 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005755 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005756 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005757 [] T_wait.timeout {
5758 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5759 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5760 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005761 }
5762 /* try to activate this PDCH from the PCU point of view */
5763 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5764 /* FIXME: is there a response? */
5765
5766 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5767}
5768
5769private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5770runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005771 /* Send RSL CHAN REL (deactivate) */
5772 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5773 PCU.clear;
5774 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005775 timer T_wait := 2.0;
5776 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005777 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005778 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005779 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005780 [] T_wait.timeout {
5781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5782 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5783 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005784 }
5785 /* Emulate PCU asking BTS to deactivate PDCH */
5786 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5787 alt {
5788 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5789 setverdict(pass);
5790 }
5791 [] RSL.receive { repeat; }
5792 }
5793}
5794
5795/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005796private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005797 var PCUIF_Message first_info;
5798 var integer ts_nr := g_chan_nr.tn;
5799 var integer trx_nr := 0;
5800 var integer bts_nr := 0;
5801 var integer pcu_conn_id := -1;
5802
5803 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5804
5805 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5806 f_sleep(3.0);
5807 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5808
5809 setverdict(pass);
5810
5811}
5812testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5813 var ConnHdlrPars pars;
5814 var ConnHdlr vc_conn;
5815 f_init();
5816
5817 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5818 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5819 vc_conn.done;
5820}
5821
5822/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005823private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005824 var PCUIF_Message first_info;
5825 var integer ts_nr := g_chan_nr.tn;
5826 var integer trx_nr := 0;
5827 var integer bts_nr := 0;
5828 var integer pcu_conn_id := -1;
5829
5830 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5831
5832 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5833 "RSL CHAN ACT");
5834 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5835 "RF CHAN REL", true);
5836 setverdict(pass);
5837}
5838testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5839 var ConnHdlrPars pars;
5840 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005841 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005842
5843 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5844 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5845 vc_conn.done;
5846}
5847
5848/* 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 +07005849private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005850 var PCUIF_Message first_info;
5851 var integer ts_nr := g_chan_nr.tn;
5852 var integer trx_nr := 0;
5853 var integer bts_nr := 0;
5854 var integer pcu_conn_id := -1;
5855
5856 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5857
5858 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5859 "RSL CHAN ACT");
5860
5861 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5862 alt {
5863 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5864 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005866 }
5867 [] RSL.receive { repeat; }
5868 }
5869
5870 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5871 "RF CHAN REL", true);
5872 setverdict(pass);
5873}
5874testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5875 var ConnHdlrPars pars;
5876 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005877 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005878
5879 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5880 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5881 vc_conn.done;
5882}
5883
5884/* 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 +07005885private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005886 var PCUIF_Message first_info;
5887 var integer ts_nr := g_chan_nr.tn;
5888 var integer trx_nr := 0;
5889 var integer bts_nr := 0;
5890 var integer pcu_conn_id := -1;
5891
5892 /* register for the TCH/F channel number */
5893 f_rslem_register(0, g_chan_nr);
5894
5895 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5896
5897 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5898
5899 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5900 "RSL CHAN ACT");
5901
5902 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5903
5904 setverdict(pass);
5905}
5906testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5907 var ConnHdlrPars pars;
5908 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005909 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005910
5911 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5912 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5913 vc_conn.done;
5914}
5915
5916
Harald Welte0472ab42018-03-12 15:02:26 +01005917/***********************************************************************
5918 * LAPDm / RLL related
5919 ***********************************************************************/
5920
5921private function f_tx_lapdm(template (value) LapdmFrame l,
5922 template (value) RslLinkId link_id) runs on ConnHdlr {
5923 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005924 var template (value) SacchL1Header l1h;
5925
5926 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005927 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005928 /* Compose dummy L1 header */
5929 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5930 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 +02005931 } else {
5932 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005933 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 +01005934 }
Harald Welte0472ab42018-03-12 15:02:26 +01005935}
5936
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005937private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005938 uint3_t sapi,
5939 RslLinkId link_id,
5940 octetstring l3,
5941 boolean exp
5942}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005943private type record of RllTestCase RllTestCases;
5944private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5945 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005946 sapi := sapi,
5947 link_id := id,
5948 l3 := l3,
5949 exp := exp
5950}
5951
5952/* execute the same callback function with a set of different parameters (tcs) on a
5953 * variety of logical channels */
5954private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5955 var ConnHdlrPars pars;
5956 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005957 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005958
5959 /* test on each of the channels we have */
5960 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5961 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5962
5963 /* test each of the test cases on the current channel */
5964 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5965 pars.spec.rll := tcs[j];
5966 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5967 vc_conn := f_start_handler(fn, pars);
5968 vc_conn.done;
5969 }
5970 }
5971
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005972 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005973}
5974
5975/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5976private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5977 var RllTestCase tc := g_pars.spec.rll;
5978 timer T := 3.0;
5979
5980 f_l1_tune(L1CTL);
5981 RSL.clear;
5982
5983 /* activate the logical channel */
5984 f_est_dchan();
5985 L1CTL.clear;
5986
5987 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5988 T.start;
5989 alt {
5990 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5991 if (tc.exp) {
5992 setverdict(pass);
5993 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005994 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005995 }
5996 }
5997 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5998 if (tc.exp) {
5999 setverdict(pass);
6000 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006001 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006002 }
6003 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006004 /* We also expect to receive the measurements */
6005 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006006 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006007 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006008 }
6009 [not tc.exp] T.timeout {
6010 setverdict(pass);
6011 }
6012 }
6013
6014 f_rsl_chan_deact();
6015 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6016 f_rslem_unregister(0, g_chan_nr);
6017}
6018testcase TC_rll_est_ind() runs on test_CT {
6019 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006020 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006021 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006022 /* normal SAPI0 establishment */
6023 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006024 /* SAPI 3 doesn't support contention resolution */
6025 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6026 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6027 /* normal SAPI3 establishment on main DCCH */
6028 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6029 /* normal SAPI3 establishment on SACCH */
6030 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6031 };
6032 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6033}
6034
6035/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6036private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6037 var RllTestCase tc := g_pars.spec.rll;
6038 var L1ctlDlMessage dl;
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 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6049 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6050 T.start;
6051 alt {
6052 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6053 var LapdmFrame lapdm;
6054 var octetstring l2 := dl.payload.data_ind.payload;
6055 if (dl.dl_info.link_id.c == SACCH) {
6056 /* remove L1 header */
6057 l2 := substr(l2, 2, lengthof(l2)-2);
6058 }
6059 lapdm.ab := dec_LapdmFrameAB(l2);
6060 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6061 setverdict(pass);
6062 } else {
6063 repeat;
6064 }
6065 }
6066 [] L1CTL.receive { repeat; }
6067 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006069 }
6070 }
6071
6072 f_rsl_chan_deact();
6073 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6074 f_rslem_unregister(0, g_chan_nr);
6075}
6076testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6077 var RllTestCases tcs := {
6078 /* normal SAPI3 establishment on main DCCH */
6079 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6080 };
6081 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6082}
6083testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6084 var RllTestCases tcs := {
6085 /* normal SAPI3 establishment on SACCH */
6086 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6087 }
6088 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6089}
6090
6091/* altstep to receive a LAPDm frame matching the given template */
6092private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6093 var L1ctlDlMessage dl;
6094 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6095 var LapdmFrame lapdm;
6096 var octetstring l2 := dl.payload.data_ind.payload;
6097 if (dl.dl_info.link_id.c == SACCH) {
6098 /* remove L1 header */
6099 l2 := substr(l2, 2, lengthof(l2)-2);
6100 }
6101 if (ischosen(exp.ab)) {
6102 lapdm.ab := dec_LapdmFrameAB(l2);
6103 } else if (ischosen(exp.b4)) {
6104 lapdm.b4 := dec_LapdmFrameB4(l2);
6105 } else if (ischosen(exp.bbis)) {
6106 lapdm.bbis := dec_LapdmFrameBbis(l2);
6107 }
6108 log("Rx LAPDm ", lapdm);
6109 if (match(lapdm, exp)) {
6110 setverdict(pass);
6111 } else {
6112 repeat;
6113 }
6114 }
6115 [] L1CTL.receive { repeat; }
6116}
6117private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6118 timer T := t;
6119 T.start;
6120 alt {
6121 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006122 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006123 }
6124 [] as_l1_exp_lapdm(exp);
6125 }
6126}
6127
6128/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6129private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6130 /* send SABM from MS -> BTS */
6131 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6132 /* expect RLL EST IND on Abis */
6133 alt {
6134 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6135 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6136 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006137 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006138 }
6139 [] RSL.receive { repeat; }
6140 }
6141 /* expect UA from BTS -> MS */
6142 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6143}
6144
6145/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6146private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6147 var RllTestCase tc := g_pars.spec.rll;
6148
6149 f_l1_tune(L1CTL);
6150 RSL.clear;
6151
6152 /* activate the logical channel */
6153 f_est_dchan();
6154 L1CTL.clear;
6155
6156 /* first establish the link-layer */
6157 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6158
6159 /* then send the DISC */
6160 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6161 /* ... and expect the REL IND on the RSL side */
6162 alt {
6163 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6164 setverdict(pass);
6165 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006166 /* We also expect to receive the measurements */
6167 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006168 }
6169
6170 /* release the channel */
6171 f_rsl_chan_deact();
6172 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6173 f_rslem_unregister(0, g_chan_nr);
6174}
6175testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6176 var RllTestCases tcs := {
6177 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6178 };
6179 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6180}
6181
6182testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6183 var RllTestCases tcs := {
6184 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6185 };
6186 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6187}
6188testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6189 var RllTestCases tcs := {
6190 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6191 };
6192 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6193}
6194testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6195 var RllTestCases tcs := {
6196 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6197 };
6198 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6199}
6200
6201/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6202private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6203 var RllTestCase tc := g_pars.spec.rll;
6204 f_l1_tune(L1CTL);
6205 RSL.clear;
6206
6207 /* activate the logical channel */
6208 f_est_dchan();
6209 L1CTL.clear;
6210
6211 /* first establish the link-layer */
6212 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6213
6214 /* then send the REL REQ via RSL */
6215 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6216 /* ... and expect the DISC on the Um side */
6217 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006218 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006219 /* FIXME: send a UA in resposne to the DISC */
6220 }
6221 }
6222
6223 /* release the channel */
6224 f_rsl_chan_deact();
6225 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6226 f_rslem_unregister(0, g_chan_nr);
6227}
6228testcase TC_rll_rel_req() runs on test_CT {
6229 var RllTestCases tcs := {
6230 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6231 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6232 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6233 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6234 };
6235 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6236}
6237
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006238/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006239testcase TC_rll_data_req() runs on test_CT {
6240}
6241
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006242/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006243testcase TC_rll_data_ind() runs on test_CT {
6244}
6245
6246/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6247private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6248 var RllTestCase tc := g_pars.spec.rll;
6249
6250 f_l1_tune(L1CTL);
6251 RSL.clear;
6252
6253 f_est_dchan();
6254 L1CTL.clear;
6255
6256 /* Send UNITDATA REQ on RSL side */
6257 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6258 /* Expect it to arrive on the other side */
6259 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006260 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006261 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006262 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006263 }
6264
6265 /* release the channel */
6266 f_rsl_chan_deact();
6267 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6268 f_rslem_unregister(0, g_chan_nr);
6269}
6270testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6271 var octetstring l3 := f_rnd_octstring(15);
6272 var RllTestCases tcs := {
6273 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6274 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6275 };
6276 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6277}
6278testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6279 var octetstring l3 := f_rnd_octstring(19);
6280 var RllTestCases tcs := {
6281 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6282 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6283 };
6284 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6285}
6286
6287/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6288private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6289 var RllTestCase tc := g_pars.spec.rll;
6290
6291 f_l1_tune(L1CTL);
6292 RSL.clear;
6293
6294 f_est_dchan();
6295 L1CTL.clear;
6296
6297 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006298 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006299 /* Expdct RLL UNITDATA IND on RSL side */
6300 alt {
6301 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6302 setverdict(pass);
6303 }
6304 [] RSL.receive { repeat; }
6305 }
6306
6307 /* release the channel */
6308 f_rsl_chan_deact();
6309 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6310 f_rslem_unregister(0, g_chan_nr);
6311}
6312testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006313 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006314 var RllTestCases tcs := {
6315 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6316 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6317 };
6318 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6319}
6320testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6321 var octetstring l3 := f_rnd_octstring(18);
6322 var RllTestCases tcs := {
6323 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6324 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6325 };
6326 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6327}
6328
Harald Weltee613f962018-04-18 22:38:16 +02006329/***********************************************************************
6330 * Encryption Related
6331 ***********************************************************************/
6332
6333/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006334private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006335 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6336 if (link_id.c == SACCH) {
6337 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6338 } else {
6339 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6340 }
6341}
6342
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006343/* Expect (or not expect) other kinds of messages */
6344private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6345 [exp_any] RSL.receive { repeat; }
6346 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006348 }
6349}
6350
Harald Weltee613f962018-04-18 22:38:16 +02006351/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006352private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006353 RslLinkId link_id,
6354 octetstring l3,
6355 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006356 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006357) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006358 timer T := 3.0;
6359 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6360 T.start;
6361 /* Expect RLL UNITDATA IND on RSL side */
6362 alt {
6363 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6364 setverdict(pass);
6365 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006366 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006367 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006368 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006369 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006370 }
Harald Weltee613f962018-04-18 22:38:16 +02006371 }
6372}
6373
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006374/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6375private function f_data_mo(
6376 RslLinkId link_id,
6377 boolean p, uint3_t nr, uint3_t ns,
6378 octetstring l3,
6379 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006380 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006381) runs on ConnHdlr {
6382 timer T := 3.0;
6383 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6384 T.start;
6385 /* Expect RLL DATA IND on RSL side */
6386 alt {
6387 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6388 setverdict(pass);
6389 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006390 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006391 [] as_rsl_any_ind(exp_any);
6392 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006393 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006394 }
6395 }
6396}
6397
Harald Weltee613f962018-04-18 22:38:16 +02006398/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006399private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006400 f_l1_tune(L1CTL);
6401 f_est_dchan(true);
6402
6403 /* now we actually need to transmit some data both ways to check if the encryption works */
6404 var L1ctlDlMessage dl;
6405
Stefan Sperling603d98e2018-07-25 16:47:28 +02006406 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006407 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6408
6409 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6410 f_unitdata_mt(link_id, l3);
6411
6412 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6413 f_unitdata_mo(link_id, l3);
6414
6415 /* release the channel */
6416 f_rsl_chan_deact();
6417 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6418 f_rslem_unregister(0, g_chan_nr);
6419}
6420testcase TC_chan_act_a51() runs on test_CT {
6421 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6422 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6423 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6424}
6425testcase TC_chan_act_a52() runs on test_CT {
6426 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6427 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6428 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6429}
6430testcase TC_chan_act_a53() runs on test_CT {
6431 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6432 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6433 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6434}
6435
Eric Wildf1827a72019-05-28 17:37:35 +02006436/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6437 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 +07006438private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006439 f_l1_tune(L1CTL);
6440 f_est_dchan(true);
6441
6442 /* now we actually need to transmit some data both ways to check if the encryption works */
6443 var L1ctlDlMessage dl;
6444
6445 var octetstring l3 := f_rnd_octstring(20);
6446 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6447
6448 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6449 f_unitdata_mt(link_id, l3);
6450
6451 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6452 f_unitdata_mo(link_id, l3);
6453
6454 var RSL_Message rsl;
6455 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6456
6457 /* modify key to break proper encryption */
6458 g_pars.encr.key := f_rnd_octstring(8);
6459 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6460 rsl.ies := rsl.ies & { ei };
6461 RSL.send(rsl);
6462
6463 timer T0 := 1.0;
6464 T0.start;
6465 /* Expect RSL MODIFY ACK */
6466 alt {
6467 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6468 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6470 }
6471 [] T0.timeout {
6472 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6473 }
6474 }
6475
6476 var octetstring l3msg := f_rnd_octstring(15);
6477 timer T1 := 3.0;
6478 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6479 due to broken encryption */
6480 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6481 T1.start;
6482 alt {
6483 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6484 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6485 }
6486 [] T1.timeout {
6487 setverdict(pass);
6488 }
6489 }
6490
6491 /* release the channel */
6492 f_rsl_chan_deact();
6493 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6494 f_rslem_unregister(0, g_chan_nr);
6495}
6496testcase TC_rsl_modify_encr() runs on test_CT {
6497 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6498 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6499 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6500}
Harald Weltee613f962018-04-18 22:38:16 +02006501
6502/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006503private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006504 /* L3 payload doesn't matter, as it is passed transparently */
6505 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6506 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6507 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6508
6509 f_l1_tune(L1CTL);
6510
6511 /* first establish a dedicated channel in the clear */
6512 f_est_dchan(false);
6513
6514 /* Establish ABM */
6515 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6516
6517 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6518 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6519 /* expect the L3 to arrive still unencrypted on the MS side */
6520 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6521
6522 /* configure L1 to apply ciphering */
6523 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6524 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6525
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006526 /* send first ciphered I-frame in response and expect it on RSL */
6527 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006528
6529 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6530 * and hence enable encryption also on the downlink */
6531
6532 /* expect bi-directional communication work in encrypted mode */
6533 f_unitdata_mo(link_id, f_rnd_octstring(15));
6534 f_unitdata_mt(link_id, f_rnd_octstring(15));
6535
6536 /* release the channel */
6537 f_rsl_chan_deact();
6538 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6539 f_rslem_unregister(0, g_chan_nr);
6540}
6541testcase TC_encr_cmd_a51() runs on test_CT {
6542 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6543 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6544 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6545}
6546testcase TC_encr_cmd_a52() runs on test_CT {
6547 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6548 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6549 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6550}
6551testcase TC_encr_cmd_a53() runs on test_CT {
6552 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6553 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6554 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6555}
6556
6557private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6558 var LapdmFrame lf;
6559 var octetstring reenc;
6560
6561 /* decode the LAPDm frame */
6562 if (ischosen(exp_match.ab)) {
6563 lf.ab := dec_LapdmFrameAB(enc);
6564 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006565 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006566 }
6567
6568 /* check if decoder result matches expectation */
6569 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006570 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006571 } else {
6572 log(name, ": matched");
6573 setverdict(pass);
6574 }
6575
6576 /* test if re-encoded frame equals original input */
6577 reenc := enc_LapdmFrame(lf);
6578 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006579 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006580 } else {
6581 setverdict(pass);
6582 }
6583}
6584
6585testcase TC_lapdm_selftest() runs on test_CT {
6586 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6587 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6588 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6589 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6590 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6591 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6592 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6593}
6594
Stefan Sperling4880be42018-08-07 18:12:59 +02006595/***********************************************************************
6596 * DTX Related (see GSM 05.08, section 8.3)
6597 ***********************************************************************/
6598
6599/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006600private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006601 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6602 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6603 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6604 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6605}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006606private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006607 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6608 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6609}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006610private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006611 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6612 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6613 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6614 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6615}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006616private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006617 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6618 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6619 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6620 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6621 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6622 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6623 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6624 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6625}
6626
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006627private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006628 var L1ctlDlMessage dl;
6629 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6630 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6631 var GsmFrameNumber first_fn;
6632 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006633 var integer nfill_frames_sacch := 0;
6634 var integer nfill_frames_nonsacch := 0;
6635 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006636 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6637 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006638 const integer frame_dtx_tchf_mod := 104;
6639 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6640 * which operates in terms of blocks rather than frames. */
6641 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6642 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006643 timer T := 5.0;
6644
6645 f_l1_tune(L1CTL);
6646 RSL.clear;
6647 L1CTL.clear;
6648
6649 /* activate TCHF signalling channel */
6650 f_est_dchan(false);
6651
6652 T.start;
6653 alt {
6654 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6655 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6656 var octetstring l2 := dl.payload.data_ind.payload;
6657
6658 if (is_first_frame) {
6659 is_first_frame := false;
6660 first_fn := dl.dl_info.frame_nr;
6661 }
6662
6663 if (dl.dl_info.link_id.c == SACCH) {
6664 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6665 if (not match(l2_fill_frame_sacch, l2)) {
6666 repeat;
6667 }
6668 } else if (not match(l2_fill_frame, l2)) {
6669 repeat;
6670 }
6671
6672 if (dtxd) {
6673 if (not f_g_chan_is_tchf()) {
6674 T.stop;
6675 f_rsl_chan_deact();
6676 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006677 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 +02006678 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006679 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006680 T.stop;
6681 f_rsl_chan_deact();
6682 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006683
6684 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6685 * 2 SACCH, 1 TCH/F */
6686 expected_fill_frames := 3;
6687
6688 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6689 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6690 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006692 } else {
6693 setverdict(pass);
6694 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006695 } else {
6696 if (dl.dl_info.link_id.c == SACCH) {
6697 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006698 repeat;
6699 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006700 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6701 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6702 * we should only see the subset of frames numbers which correspond to a block boundary.
6703 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6704 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6705 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6706 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6707 repeat;
6708 }
6709 }
6710 log("Received DTX TCH fill frame with bad frame number: ", fn,
6711 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6712 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6713 f_rsl_chan_deact();
6714 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006715 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006716 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006717 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006718 if (dl.dl_info.link_id.c == SACCH) {
6719 nfill_frames_sacch := nfill_frames_sacch + 1;
6720 } else {
6721 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6722 }
6723 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006724 T.stop;
6725 if (f_g_chan_is_tchf()) {
6726 /* Without DTX we can expect 25 fill frames for every 104 frames.
6727 * (24 FACCH + 1 SACCH filling) */
6728 expected_fill_frames := 25;
6729 } else if (f_g_chan_is_tchh()) {
6730 /* We can expect 2 fill frames for every 104 frames. */
6731 expected_fill_frames := 2;
6732 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6733 /* We can expect 5 fill frames for every 104 frames. */
6734 expected_fill_frames := 5;
6735 } else {
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, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006739 }
6740
6741 f_rsl_chan_deact();
6742 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006743
6744 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006745 setverdict(pass);
6746 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006747 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6748 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006750 }
6751 } else {
6752 repeat;
6753 }
6754 }
6755 }
6756 [] L1CTL.receive { repeat; }
6757 [] T.timeout {
6758 f_rsl_chan_deact();
6759 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006760 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006761 }
6762 }
6763}
6764
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006765private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006766 f_test_l2_fill_frames(false);
6767}
6768
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006769private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006770 f_test_l2_fill_frames(true);
6771}
6772
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006773private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006774 var ConnHdlr vc_conn;
6775 var ConnHdlrPars pars;
6776 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006777 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006778 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6779 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6780 if (dtxd) {
6781 if (i >= 4) { /* DTX is only allowed on TCH/F */
6782 break;
6783 }
6784 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6785 } else {
6786 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6787 }
6788 vc_conn.done;
6789 }
6790}
6791
6792/* Verify that L2 fill frames are sent on TCH in signaling mode if
6793 * there is nothing to transmit while DTX is disabled on downlink. */
6794testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6795 f_tch_sign_l2_fill_frame(false);
6796}
6797
6798/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6799 * there is nothing to transmit while DTX is enabled on downlink. */
6800testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6801 f_tch_sign_l2_fill_frame(true);
6802}
Harald Welte0472ab42018-03-12 15:02:26 +01006803
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006804testcase TC_chopped_ipa_ping() runs on test_CT {
6805 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6806}
6807
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006808testcase TC_chopped_ipa_payload() runs on test_CT {
6809 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6810}
6811
Harald Welte0472ab42018-03-12 15:02:26 +01006812/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6813/* protocol error as per 44.006 */
6814/* link layer failure (repetition of I-frame N200 times without ACK */
6815/* repetition of SABM or DISC N200 times without ACK */
6816/* receptiom of SABM in multi-frame established state */
6817
6818
Harald Welte68e495b2018-02-25 00:05:57 +01006819/* TODO Areas:
6820
6821* channel activation
6822** with BS_Power / MS_Power, bypassing power control loop
6823** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006824** with timing advance from initial activation on
6825* mode modify
6826** encryption
6827** multirate
6828* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006829** unsupported algorithm
6830* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006831* BS Power Control
6832* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006833* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006834* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006835** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006836* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006837** DATA_IND from BTS->PCU
6838** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006839
6840*/
Harald Welte70767382018-02-21 12:16:40 +01006841
6842control {
6843 execute( TC_chan_act_stress() );
6844 execute( TC_chan_act_react() );
6845 execute( TC_chan_deact_not_active() );
6846 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006847 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006848 execute( TC_sacch_filling() );
6849 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006850 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006851 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006852 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006853 execute( TC_sacch_chan_act_ho_async() );
6854 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006855 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006856 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006857 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006858 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006859 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006860 execute( TC_rach_load_idle_thresh0() );
6861 execute( TC_rach_load_idle_below_thresh() );
6862 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006863 execute( TC_meas_res_sign_tchf() );
6864 execute( TC_meas_res_sign_tchh() );
6865 execute( TC_meas_res_sign_sdcch4() );
6866 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006867 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006868 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006869 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006870 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006871 execute( TC_rsl_bs_pwr_static_ass() );
6872 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006873 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006874 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006875 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006876 execute( TC_rsl_ms_pwr_dyn_up() );
6877 execute( TC_rsl_ms_pwr_dyn_down() );
6878 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6879 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006880 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006881 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006882 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006883 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006884 execute( TC_paging_imsi_80percent() );
6885 execute( TC_paging_tmsi_80percent() );
6886 execute( TC_paging_imsi_200percent() );
6887 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006888 execute( TC_rsl_protocol_error() );
6889 execute( TC_rsl_mand_ie_error() );
6890 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006891 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006892 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006893 execute( TC_si_sched_2bis() );
6894 execute( TC_si_sched_2ter() );
6895 execute( TC_si_sched_2ter_2bis() );
6896 execute( TC_si_sched_2quater() );
6897 execute( TC_si_sched_13() );
6898 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006899 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006900 execute( TC_ipa_crcx_twice_not_active() );
6901 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006902 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006903 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006904
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006905 if (mp_pcu_socket != "") {
6906 execute( TC_pcu_act_req() );
6907 execute( TC_pcu_act_req_wrong_ts() );
6908 execute( TC_pcu_act_req_wrong_bts() );
6909 execute( TC_pcu_act_req_wrong_trx() );
6910 execute( TC_pcu_deact_req() );
6911 execute( TC_pcu_deact_req_wrong_ts() );
6912 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006913 if (mp_l1_supports_gprs) {
6914 execute( TC_pcu_data_req_pdtch() );
6915 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006916 execute( TC_pcu_data_req_wrong_bts() );
6917 execute( TC_pcu_data_req_wrong_trx() );
6918 execute( TC_pcu_data_req_wrong_ts() );
6919 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006920 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006921 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006922 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006923 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006924 execute( TC_pcu_data_req_imm_ass_pch() );
6925 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006926 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006927 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006928 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006929 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006930 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006931 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006932 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006933 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006934 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006935 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006936 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006937 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006938 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006939 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006940 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006941 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006942 execute( TC_dyn_osmo_pdch_act_deact() );
6943 execute( TC_dyn_osmo_pdch_double_act() );
6944 execute( TC_dyn_ipa_pdch_act_deact() );
6945 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6946
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006947 if (PCUIF_Types.mp_pcuif_version >= 10) {
6948 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02006949 execute( TC_pcu_socket_nsvc_ipv4() );
6950 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07006951 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006952 } else {
6953 log("PCU socket path not available, skipping PCU tests");
6954 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006955
Harald Welte3d04ae62018-04-04 20:29:05 +02006956 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006957 execute( TC_dyn_osmo_pdch_tchf_act() );
6958 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006959 execute( TC_dyn_ipa_pdch_tchf_act() );
6960 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006961
6962 execute( TC_rll_est_ind() );
6963 execute( TC_rll_est_req_DCCH_3() );
6964 execute( TC_rll_est_req_ACCH_3() );
6965 execute( TC_rll_rel_ind_DCCH_0() );
6966 execute( TC_rll_rel_ind_DCCH_3() );
6967 execute( TC_rll_rel_ind_ACCH_0() );
6968 execute( TC_rll_rel_ind_ACCH_3() );
6969 execute( TC_rll_rel_req() );
6970 execute( TC_rll_unit_data_req_DCCH() );
6971 execute( TC_rll_unit_data_req_ACCH() );
6972 execute( TC_rll_unit_data_ind_DCCH() );
6973 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006974
6975 execute( TC_chan_act_a51() );
6976 execute( TC_chan_act_a52() );
6977 execute( TC_chan_act_a53() );
6978 execute( TC_encr_cmd_a51() );
6979 execute( TC_encr_cmd_a52() );
6980 execute( TC_encr_cmd_a53() );
6981
Harald Welteee25aae2019-05-19 14:32:37 +02006982 execute( TC_err_rep_wrong_mdisc() );
6983 execute( TC_err_rep_wrong_msg_type() );
6984 execute( TC_err_rep_wrong_sequence() );
6985
Harald Weltee613f962018-04-18 22:38:16 +02006986 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006987
6988 execute( TC_tch_sign_l2_fill_frame() );
6989 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006990
6991 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006992 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006993}
6994
6995
6996}