blob: a6ccf300af8160ecbf821d777a15903876c0975f [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;
Vadim Yanitskiy73878132021-05-05 02:22:45 +020069friend module BTS_Tests_VAMOS;
Harald Weltead033dc2019-05-25 17:28:16 +020070friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020071friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010072friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030073
Harald Welte70767382018-02-21 12:16:40 +010074/* The tests assume a BTS with the following timeslot configuration:
75 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020076 * TS1 : TCH/F
77 * TS2 : TCH/F
78 * TS3 : TCH/F_PDCH (IPA Style)
79 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010080 * TS5 : TCH/H
81 * TS6 : SDCCH/8
82 * TS7 : PDCH
83 */
84
85modulepar {
86 charstring mp_rsl_ip := "127.0.0.2";
87 integer mp_rsl_port := 3003;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070088 charstring mp_bts_trxc_ip := "127.0.0.1";
89 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010090 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020091 charstring mp_ctrl_ip := "127.0.0.1";
92 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020093 charstring mp_bsc_ctrl_ip := "127.0.0.1";
94 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020095 integer mp_tolerance_rxqual := 1;
96 integer mp_tolerance_rxlev := 3;
97 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020098 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020099 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200100 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200101 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
102 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 +0200103 integer mp_ms_actual_ta_exp := 0;
104 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700105 integer mp_uplink_power_target := -75;
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +0700106 integer mp_uplink_power_hysteresis := 8; /* -83 .. -67 */
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100107 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200108 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200109 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200110 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
111 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700112 /* how many transceivers do we expect to connect */
113 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700114 /* frequency hopping status */
115 boolean mp_freq_hop_enabled := false;
116 /* frequency hopping parameters */
117 FreqHopConfig mp_fh_config;
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700118 /* configuration for each individual transceiver */
119 TrxPars mp_trx_pars; /* see BTS_Tests.default */
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700120 /* default Training Sequence Code */
121 GsmTsc mp_tsc_def := 7;
Harald Welte70767382018-02-21 12:16:40 +0100122}
123
Harald Welte629cc6b2018-03-11 17:19:05 +0100124type record of RslChannelNr ChannelNrs;
125
Harald Welte70767382018-02-21 12:16:40 +0100126type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100127 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100128 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100129 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100130 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100131 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100132 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100133
134 /* L1CTL port (for classic tests) */
135 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100136
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700137 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700138 port TRXC_CODEC_PT BTS_TRXC;
139 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100140
Harald Weltef50e3ae2018-09-10 10:27:56 +0200141 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100142 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200143 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100144
Harald Welte883340c2018-02-28 18:59:29 +0100145 /* PCU Interface of BTS */
146 port PCUIF_CODEC_PT PCU;
147 var integer g_pcu_conn_id;
148 /* Last PCU INFO IND we received */
149 var PCUIF_Message g_pcu_last_info;
150
Harald Welte48494ca2018-02-25 16:59:50 +0100151 /* SI configuration */
152 var SystemInformationConfig si_cfg := {
153 bcch_extended := false,
154 si1_present := false,
155 si2bis_present := false,
156 si2ter_present := false,
157 si2quater_present := false,
158 si7_present := false,
159 si8_present := false,
160 si9_present := false,
161 si13_present := false,
162 si13alt_present := false,
163 si15_present := false,
164 si16_present := false,
165 si17_present := false,
166 si2n_present := false,
167 si21_present := false,
168 si22_present := false
169 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100170
171 /* all logical channels available on the BTS */
172 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100173 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100174}
175
176/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200177type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100178 port L1CTL_PT L1CTL;
179
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700180 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700181 port TRXC_CODEC_PT BTS_TRXC;
182 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100183
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200184 /* port to be initialized optionally to access BSC VTY */
185 port TELNETasp_PT BSCVTY;
186
Harald Welte70767382018-02-21 12:16:40 +0100187 timer g_Tguard;
188 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
189
190 var ConnHdlrPars g_pars;
191 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100192 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200193
194 /* PCU Interface of BTS */
195 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100196}
197
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700198private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700199 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200200 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700201 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200202 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700203 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200204 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700205 timer T;
206
Harald Welte70767382018-02-21 12:16:40 +0100207 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
208 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
209
210 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
211 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
212 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
213
214 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
215 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700216
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700217 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700218 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700219 T.start(mp_ipa_up_timeout);
220 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700221 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700222 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
223 /* Make sure that all transceivers use unique stream ID */
224 if (trx_mask[enum2int(ev.sid)] == '1'B) {
225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
226 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
227 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700228
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700229 trx_mask[enum2int(ev.sid)] := '1'B;
230 trx_count := trx_count + 1;
231
232 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200233 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700234 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200235 /* This message (RF RESource INDication) is sent by the IUT itself */
236 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
237 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
238 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
239 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
240 }
241 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
242 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
243 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
244 }
245
246 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
247 rfind_count := rfind_count + 1;
248 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
249 if (rfind_count < mp_transceiver_num) { repeat; }
250 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700251 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
252 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
253 [] T.timeout {
254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
255 "Timeout waiting for RSL bring up");
256 }
257 }
Harald Welte70767382018-02-21 12:16:40 +0100258}
259
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700260friend type record length(1 .. 256) of TrxParsItem TrxPars;
261friend type record TrxParsItem {
262 GsmArfcn arfcn,
263 TrxTsPars ts
264};
265
266friend type record length(8) of TrxTsParsItem TrxTsPars;
267friend type record TrxTsParsItem {
268 PchanConfig config
269};
270
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700271friend type record FreqHopPars {
272 /* Whether frequency hopping is in use */
273 boolean enabled,
274 /* Mobile Allocation Index Offset / Hopping Sequence Number */
275 MaioHsn maio_hsn,
276 /* MA bitmap to be indicated in RR Immediate Assignment */
277 MobileAllocationLV ma_map,
278 /* The actual Mobile Allocation (ARFCN list) to be used */
279 L1ctlMA ma
280};
281
Harald Welte70767382018-02-21 12:16:40 +0100282type record ConnHdlrPars {
283 RslChannelNr chan_nr,
284 RSL_IE_ChannelMode chan_mode,
285 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100286 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200287 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200288 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700289 BtsBand bts0_band optional,
290
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700291 /* Training Sequence Code */
292 GsmTsc tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700293 /* Frequency hopping parameters */
294 FreqHopPars fhp
295};
Harald Welte0472ab42018-03-12 15:02:26 +0100296
297/* Test-specific parameters */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +0200298friend type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100299 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100300}
301
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700302private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100303 max_retrans := RACH_MAX_RETRANS_7,
304 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100305 cell_barr_access := false,
306 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100307 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100308};
309
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700310private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100311 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200312 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100313 acs := '0'B,
314 neci := true,
315 rxlev_access_min := 0
316}
317
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700318private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100319 mcc_mnc := '262F42'H,
320 lac := 42
321}
322
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700323private template (value) GPRSIndicator ts_GPRSIndicator_def := {
324 ra_colour := 0,
325 si13_pos := '0'B
326}
327
328private template (value) SI3RestOctets ts_SI3RestOctets_def
329modifies ts_SI3RestOctets := {
330 gprs_ind := {
331 presence := CSN1_H,
332 ind := ts_GPRSIndicator_def
333 }
334}
335
336private template (value) SI4RestOctets ts_SI4RestOctets_def
337modifies ts_SI4RestOctets := {
338 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700339 presence := CSN1_H,
340 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700341 }
342}
343
Harald Welte7484fc42018-02-24 14:09:45 +0100344/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700345private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100346 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100347 payload := {
348 si3 := {
349 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100350 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100351 ctrl_chan_desc := {
352 msc_r99 := true,
353 att := true,
354 bs_ag_blks_res := 1,
355 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100356 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100357 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
358 spare := '00'B,
359 bs_pa_mfrms := 0, /* 2 multiframes */
360 t3212 := 1 /* 6 minutes */
361 },
Harald Welte82ccef72018-02-25 16:17:33 +0100362 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100363 dn_ind := false,
364 pwrc := false,
365 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100366 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100367 },
Harald Weltef10153f2018-02-25 16:34:05 +0100368 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100369 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200370 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100371 }
372 }
373}
Harald Welte70767382018-02-21 12:16:40 +0100374
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700375private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100376 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100377 payload := {
378 si2 := {
379 bcch_freq_list := '00000000000000000000000000000000'O,
380 ncc_permitted := '11111111'B,
381 rach_control := ts_RachCtrl_default
382 }
383 }
384}
385
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700386private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100387 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100388 payload := {
389 si4 := {
390 lai := ts_LAI_default,
391 cell_sel_par := ts_CellSelPar_default,
392 rach_control := ts_RachCtrl_default,
393 cbch_chan_desc := omit,
394 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200395 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100396 }
397 }
398}
399
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700400private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100401runs on test_CT {
402 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700403 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100404}
405
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700406private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100407runs on test_CT {
408 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
409 log("Setting ", rsl_si_type, ": ", si_dec);
410 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
411}
412
Harald Welte505cf9b2018-09-15 17:47:23 +0300413friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100414 map(self:BTSVTY, system:BTSVTY);
415 f_vty_set_prompts(BTSVTY);
416 f_vty_transceive(BTSVTY, "enable");
417}
418
Harald Welte505cf9b2018-09-15 17:47:23 +0300419friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200420 map(self:BSCVTY, system:BSCVTY);
421 f_vty_set_prompts(BSCVTY, "OsmoBSC");
422 f_vty_transceive(BSCVTY, "enable");
423}
424
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200425friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
426 map(self:BSCVTY, system:BSCVTY);
427 f_vty_set_prompts(BSCVTY, "OsmoBSC");
428 f_vty_transceive(BSCVTY, "enable");
429}
430
Harald Welte883340c2018-02-28 18:59:29 +0100431/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200432private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
433 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100434 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200435 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
436 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100437 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200438 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100440 }
441}
442
Harald Weltef26de0b2018-04-04 20:28:05 +0200443private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
444 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100445 timer T := 2.0;
446 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100447 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200448 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100449 return;
450 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200451 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100452
453 T.start;
454 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200455 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100456 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200457 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100458 }
459 }
460}
461
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700462private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
463 out integer trxc_conn_id) {
464 var Result res;
465
466 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
467 "", -1, -1, { udp := {} }, {});
468 if (not ispresent(res.connId)) {
469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
470 "Could not connect to the control (TRXC) interface " &
471 "of FakeTRX, check your configuration");
472 }
473 trxc_conn_id := res.connId;
474}
475
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +0100476/* global init function (without PCUIF connection) */
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700477friend function f_init(uint8_t trx_nr := 0)
478runs on test_CT
479{
480 var TrxParsItem trx_pars := mp_trx_pars[trx_nr];
Harald Welte10474062019-05-30 16:48:17 +0200481 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100482
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700483 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653.
484 * TODO: also generate this list dynamically from module parameters. */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700485 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200486 g_AllChanTypes := {
487 /* TS 1..4: TCH/F */
488 valueof(ts_RslChanNr_Bm(1)),
489 /* TS 5: TCH/H */
490 valueof(ts_RslChanNr_Lm(5,1)),
491 /* TS 0: SDCCH/4 */
492 valueof(ts_RslChanNr_SDCCH4(0,2)),
493 /* TS 6: SDCCH/8 */
494 valueof(ts_RslChanNr_SDCCH8(6,4))
495 };
496 } else {
497 g_AllChanTypes := {
498 /* TS 1..4: TCH/F */
499 valueof(ts_RslChanNr_Bm(1)),
500 /* TS 0: SDCCH/4 */
501 valueof(ts_RslChanNr_SDCCH4(0,2)),
502 /* TS 6: SDCCH/8 */
503 valueof(ts_RslChanNr_SDCCH8(6,4))
504 };
505 }
Vadim Yanitskiy7e707092020-11-16 17:08:03 +0700506
507 g_AllChannels := { };
508
509 /* Generate list of all logical channels from module parameters */
510 for (var integer tn := 0; tn < lengthof(trx_pars.ts); tn := tn + 1) {
511 select (trx_pars.ts[tn].config) {
512 case (GSM_PCHAN_CCCH_SDCCH4) {
513 g_AllChannels := g_AllChannels &
514 { valueof(ts_RslChanNr_SDCCH4(tn, 0)),
515 valueof(ts_RslChanNr_SDCCH4(tn, 1)),
516 valueof(ts_RslChanNr_SDCCH4(tn, 2)),
517 valueof(ts_RslChanNr_SDCCH4(tn, 3)) };
518 }
519 case (GSM_PCHAN_SDCCH8) {
520 g_AllChannels := g_AllChannels &
521 { valueof(ts_RslChanNr_SDCCH8(tn, 0)),
522 valueof(ts_RslChanNr_SDCCH8(tn, 1)),
523 valueof(ts_RslChanNr_SDCCH8(tn, 2)),
524 valueof(ts_RslChanNr_SDCCH8(tn, 3)),
525 valueof(ts_RslChanNr_SDCCH8(tn, 4)),
526 valueof(ts_RslChanNr_SDCCH8(tn, 5)),
527 valueof(ts_RslChanNr_SDCCH8(tn, 6)),
528 valueof(ts_RslChanNr_SDCCH8(tn, 7)) };
529 }
530 case (GSM_PCHAN_TCHH_TCHF_PDCH) {
531 g_AllChannels := g_AllChannels &
532 { valueof(ts_RslChanNr_Lm(tn, 0)),
533 valueof(ts_RslChanNr_Lm(tn, 1)),
534 valueof(ts_RslChanNr_Bm(tn)) };
535 }
536 case (GSM_PCHAN_TCHH) {
537 g_AllChannels := g_AllChannels &
538 { valueof(ts_RslChanNr_Lm(tn, 0)),
539 valueof(ts_RslChanNr_Lm(tn, 1)) };
540 }
541 case (GSM_PCHAN_TCHF, GSM_PCHAN_TCHF_PDCH) {
542 g_AllChannels := g_AllChannels &
543 { valueof(ts_RslChanNr_Bm(tn)) };
544 }
545 }
546 }
547
Harald Welte70767382018-02-21 12:16:40 +0100548 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100549 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100550 f_init_vty(id);
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100551 f_ipa_ctrl_start_client(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100552
553 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100554 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
555 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
556 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
557 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100558
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700559 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100560 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700561
562 /* Init TRXC interface to FakeTRX */
563 map(self:BTS_TRXC, system:BTS_TRXC);
564 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
565
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700566 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700567 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 +0700568 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700569 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
570 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100571 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200572
573 /* Wait some extra time to make sure the BTS emits a stable carrier.
574 * (this is only relevant when running the tests with a physical BTS.) */
575 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100576}
577
Harald Welte68e495b2018-02-25 00:05:57 +0100578/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700579friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100580 map(self:L1CTL, system:L1CTL);
581 f_connect_reset(L1CTL);
582}
583
Vadim Yanitskiy73878132021-05-05 02:22:45 +0200584friend type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100585
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700586private type record length(8) of FreqHopGroups FreqHopConfig;
587
588private type record of FreqHopGroup FreqHopGroups;
589private type record FreqHopGroup {
590 uint6_t hsn,
591 FreqHopGroupItems trx_maio
592};
593
594private type record of FreqHopGroupItem FreqHopGroupItems;
595private type record FreqHopGroupItem {
596 uint8_t trx_nr,
597 uint6_t maio
598};
599
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700600friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
601 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700602{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700603 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700604 var integer i, j;
605
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700606 fhp.enabled := false;
607
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700608 for (i := 0; i < lengthof(groups); i := i + 1) {
609 var FreqHopGroup g := groups[i];
610 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
611 var FreqHopGroupItem gi := g.trx_maio[j];
612 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700613 fhp.maio_hsn.maio := gi.maio;
614 fhp.maio_hsn.hsn := g.hsn;
615 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700616 break;
617 }
618 }
619
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700620 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700621 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700622 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
623 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
624 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700625
626 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700627 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
628 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700629 var GsmArfcn arfcn := mp_trx_pars[gi.trx_nr].arfcn;
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700630 fhp.ma := fhp.ma & { valueof(ts_GsmBandArfcn(arfcn)) };
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700631 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700632 }
633
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700634 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700635 break; /* We're done */
636 }
637 }
638}
639
Harald Welte70767382018-02-21 12:16:40 +0100640/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700641friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
642 boolean pcu_comp := false,
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200643 boolean trxc_comp := false,
644 boolean l1ctl := true)
Harald Welte70767382018-02-21 12:16:40 +0100645runs on test_CT return ConnHdlr {
646 var charstring id := testcasename();
647 var ConnHdlr vc_conn;
648
649 vc_conn := ConnHdlr.create(id);
650 /* connect to RSL Emulation main component */
651 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
652 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700653
654 /* The ConnHdlr component may want to talk to some ports directly,
655 * so we disconnect it from the test_CT and connect it to the component.
656 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200657 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200658 unmap(self:PCU, system:PCU);
659 map(vc_conn:PCU, system:PCU);
660 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700661 if (trxc_comp) {
662 unmap(self:BTS_TRXC, system:BTS_TRXC);
663 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
664 }
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200665 if (l1ctl) {
666 map(vc_conn:L1CTL, system:L1CTL);
667 }
Harald Welte70767382018-02-21 12:16:40 +0100668
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700669 /* Obtain frequency hopping parameters for a given timeslot */
670 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700671 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700672 }
673
Harald Welte70767382018-02-21 12:16:40 +0100674 vc_conn.start(f_handler_init(fn, id, pars));
675 return vc_conn;
676}
677
Harald Welte70767382018-02-21 12:16:40 +0100678private altstep as_Tguard() runs on ConnHdlr {
679 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100681 }
682}
683
Harald Welte990a3612019-05-27 14:02:13 +0200684friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +0700685 var GsmBandArfcn arfcn := valueof(ts_GsmBandArfcn(mp_trx_pars[0].arfcn));
Vadim Yanitskiy1acc7bb2020-11-14 04:24:57 +0700686 f_L1CTL_FBSB(L1CTL, arfcn, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100687}
688
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700689private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100690 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700691 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100692}
693
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700694private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100695 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700696 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100697}
698
699/* first function started in ConnHdlr component */
700private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
701runs on ConnHdlr {
702 g_pars := pars;
703 g_chan_nr := pars.chan_nr;
704
Vadim Yanitskiy918e2b22021-05-28 04:57:50 +0200705 if (L1CTL.checkstate("Mapped")) {
706 f_connect_reset(L1CTL);
707 }
Harald Welte70767382018-02-21 12:16:40 +0100708
Harald Welted48c0c72019-06-05 10:01:15 +0200709 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700710 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100711 }
Harald Welte70767382018-02-21 12:16:40 +0100712
713 g_Tguard.start(pars.t_guard);
714 activate(as_Tguard());
715
716 f_rslem_register(0, pars.chan_nr);
717
718 /* call the user-supplied test case function */
719 fn.apply(id);
720}
721
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700722private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
723 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200724runs on ConnHdlr return RSL_Message {
725 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100726 timer T := 3.0;
727 RSL.send(tx);
728 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100729 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200730 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100731 T.stop;
732 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100733 }
Harald Welte1eba3742018-02-25 12:48:14 +0100734 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200735 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100736 }
Harald Welte21240e62018-03-11 21:43:35 +0100737 [not ignore_other] as_l1_sacch();
738 [not ignore_other] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +0700739 [not ignore_other] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +0700740 [not ignore_other] as_l1_tch_loop();
Harald Welte21240e62018-03-11 21:43:35 +0100741 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200742 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100743 }
Harald Welte21240e62018-03-11 21:43:35 +0100744 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100745 }
Harald Welteb1726c92018-03-30 11:56:38 +0200746 return rx;
747}
748
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700749friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
750 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200751runs on ConnHdlr {
752 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100753}
754
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700755friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
756 boolean encr_enable := false,
757 RSL_IE_List more_ies := {},
758 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
759runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200760 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200761 if (encr_enable) {
762 /* append encryption related IEs, if requested */
763 var RSL_IE_EncryptionInfo encr_info;
764 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
765 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
766encr_info})) };
767 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200768 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200769 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100770}
771
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700772friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100773 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 +0100774 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100775}
776
Harald Welte2f2b2b72019-05-31 22:24:57 +0200777friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200778 template RSL_IE_ChannelMode chan_mode,
779 template (omit) TestSpecUnion spec := omit,
780 float t_guard := 20.0) := {
Harald Welte70767382018-02-21 12:16:40 +0100781 chan_nr := valueof(chan_nr),
782 chan_mode := valueof(chan_mode),
783 t_guard := t_guard,
784 l1_pars := {
785 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100786 toa256_enabled := false,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +0100787 meas_valid := true,
Harald Welte70767382018-02-21 12:16:40 +0100788 meas_ul := {
789 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200790 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100791 rxqual := 0
792 },
793 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200794 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100795 rxqual := 0
796 }
797 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200798 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100799 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200800 ms_power_level := mp_ms_power_level_exp,
Philipp Maier149c3922020-10-22 17:29:36 +0200801 ms_actual_ta := mp_ms_actual_ta_exp,
802 facch_enabled := false
Harald Welte0472ab42018-03-12 15:02:26 +0100803 },
Vadim Yanitskiye6c17552021-06-01 01:20:55 +0200804 spec := spec,
Eric Wild61edb7e2019-06-03 12:38:31 +0200805 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700806 bts0_band := omit,
Vadim Yanitskiy3191d732020-11-15 20:45:01 +0700807 tsc := mp_tsc_def,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700808 fhp := {
809 enabled := false,
810 maio_hsn := ts_HsnMaio(0, 0),
811 ma_map := c_MA_null,
Vadim Yanitskiy2b991b62020-11-14 21:40:41 +0700812 ma := { }
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700813 }
Harald Welte70767382018-02-21 12:16:40 +0100814}
815
Harald Welte93640c62018-02-25 16:59:33 +0100816/***********************************************************************
817 * Channel Activation / Deactivation
818 ***********************************************************************/
819
Harald Welte70767382018-02-21 12:16:40 +0100820/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700821private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100822 for (var integer i := 0; i < 500; i := i+1) {
823 f_rsl_chan_act(g_pars.chan_mode);
824 f_rsl_chan_deact();
825 }
826 setverdict(pass);
827}
828testcase TC_chan_act_stress() runs on test_CT {
829 var ConnHdlr vc_conn;
830 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200831 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100832 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
833 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200834 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100835}
836
837/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700838private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100839 f_rsl_chan_act(g_pars.chan_mode);
840 /* attempt to activate the same lchan again -> expect reject */
841 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
842 alt {
843 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200844 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100845 }
846 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
847 setverdict(pass);
848 }
849 }
850 f_rsl_chan_deact();
851}
852testcase TC_chan_act_react() runs on test_CT {
853 var ConnHdlr vc_conn;
854 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100855 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100856 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
857 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200858 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100859}
860
861/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700862private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100863 timer T := 3.0;
864 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
865 T.start;
866 alt {
867 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
868 setverdict(pass);
869 }
870 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200871 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100872 }
873 }
874}
875testcase TC_chan_deact_not_active() runs on test_CT {
876 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100877 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100878 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
879 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100881}
882
883/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700884private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100885 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
886 alt {
887 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200888 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100889 }
890 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
891 setverdict(pass);
892 }
893 }
894}
895private type record WrongChanNrCase {
896 RslChannelNr chan_nr,
897 charstring description
898}
899private type record of WrongChanNrCase WrongChanNrCases;
900private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
901 chan_nr := chan_nr,
902 description := desc
903}
904
905testcase TC_chan_act_wrong_nr() runs on test_CT {
906 var ConnHdlr vc_conn;
907 var ConnHdlrPars pars;
908
Harald Welte294b0a22018-03-10 23:26:48 +0100909 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100910
911 var WrongChanNrCases wrong := {
912 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
913 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
914 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
915 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
916 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
917 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
918 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
919 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
920 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
921 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
922 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
923 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
924 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
925 };
926
927 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
928 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
929 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
930 vc_conn.done;
931 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200932 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100933}
934
Harald Weltee613f962018-04-18 22:38:16 +0200935/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200936friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200937 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200938 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200939
940 /* test on each of the channels we have */
941 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
942 pars.chan_nr := valueof(g_AllChanTypes[i]);
943
944 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
945 vc_conn := f_start_handler(fn, pars);
946 vc_conn.done;
947 }
948
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200949 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200950}
951
Harald Welte93640c62018-02-25 16:59:33 +0100952/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100953 * SACCH handling
954 ***********************************************************************/
955
956private function f_exp_sacch(boolean exp) runs on ConnHdlr {
957 timer T_sacch := 3.0;
958 T_sacch.start;
959 alt {
960 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100962 }
963 [not exp] T_sacch.timeout {
964 setverdict(pass);
965 }
966 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
967 setverdict(pass);
968 }
969 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200970 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100971 }
972 [] L1CTL.receive { repeat; }
973 [] RSL.receive { repeat; }
974 }
975}
976
977/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
978private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
979 f_l1_tune(L1CTL);
980 RSL.clear;
981
982 /* activate the logical channel */
983 f_est_dchan();
984 L1CTL.clear;
985
986 /* check that SACCH actually are received as expected */
987 f_exp_sacch(true);
988
989 /* deactivate SACCH on the logical channel */
990 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
991 f_sleep(1.0);
992 L1CTL.clear;
993
994 /* check that no SACCH are received anymore */
995 f_exp_sacch(false);
996
997 /* release the channel */
998 f_rsl_chan_deact();
999 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1000}
1001testcase TC_deact_sacch() runs on test_CT {
1002 var ConnHdlr vc_conn;
1003 var ConnHdlrPars pars;
1004 f_init();
1005 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1006 //for (var integer i := 0; i < 1; i := i+1) {
1007 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1008 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1009 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
1010 vc_conn.done;
1011 }
1012 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +01001014}
1015
Harald Welte55700662018-03-12 13:15:43 +01001016/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +01001017private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
1018 var L1ctlDlMessage dl;
1019 /* check that the specified SI5 value is actually sent */
1020 timer T_sacch := 3.0;
1021 L1CTL.clear;
1022 T_sacch.start;
1023 alt {
1024 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1025 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1026 if (match(l3, l3_exp)) {
1027 setverdict(pass);
1028 } else {
1029 repeat;
1030 }
1031 }
1032 [] L1CTL.receive { repeat; }
1033 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +01001035 }
1036 }
1037}
1038
Harald Welte55700662018-03-12 13:15:43 +01001039/* verify that given SACCH payload is not present */
1040private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
1041 var L1ctlDlMessage dl;
1042 /* check that the specified SI5 value is actually sent */
1043 timer T_sacch := 3.0;
1044 L1CTL.clear;
1045 T_sacch.start;
1046 alt {
1047 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
1048 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
1049 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001051 } else {
1052 repeat;
1053 }
1054 }
1055 [] L1CTL.receive { repeat; }
1056 [] T_sacch.timeout {
1057 setverdict(pass);
1058 }
1059 }
1060}
1061
Harald Welte629cc6b2018-03-11 17:19:05 +01001062/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001063private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1064 /* Set a known default SACCH filling for SI5 */
1065 var octetstring si5 := f_rnd_octstring(19);
1066 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1067
1068 f_l1_tune(L1CTL);
1069 RSL.clear;
1070
1071 /* activate the logical channel */
1072 f_est_dchan();
1073
1074 /* check that the specified SI5 value is actually sent */
1075 f_sacch_present(si5);
1076
1077 /* release the channel */
1078 RSL.clear;
1079 f_rsl_chan_deact();
1080 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1081}
1082testcase TC_sacch_filling() runs on test_CT {
1083 var ConnHdlr vc_conn;
1084 var ConnHdlrPars pars;
1085 f_init();
1086 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1087 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1088 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1089 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1090 vc_conn.done;
1091 }
1092 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001094}
1095
Harald Welte629cc6b2018-03-11 17:19:05 +01001096/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001097private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1098 /* Set a known default SACCH filling for SI5 */
1099 var octetstring si5 := f_rnd_octstring(19);
1100 var octetstring si5_diff := f_rnd_octstring(19);
1101 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1102
1103 f_l1_tune(L1CTL);
1104 RSL.clear;
1105
1106 log("Activating channel, expecting standard SI5");
1107 /* activate the logical channel */
1108 f_est_dchan();
1109 /* check that the specified SI5 value is actually sent */
1110 f_sacch_present(si5);
1111
1112 /* set channel-specific different SI5 */
1113 log("Setting channel specific SACCH INFO, expecting it");
1114 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1115 /* check that the specified lchan-specific value is now used */
1116 f_sacch_present(si5_diff);
1117
1118 /* deactivate the channel and re-activate it, this should result in default SI5 */
1119 log("De-activating and re-activating channel, expecting standard SI5");
1120 f_rsl_chan_deact();
1121 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1122 /* Verify that the TRX-wide default SACCH filling is present again */
1123 f_sacch_present(si5);
1124
1125 /* release the channel */
1126 RSL.clear;
1127 f_rsl_chan_deact();
1128 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1129}
1130testcase TC_sacch_info_mod() runs on test_CT {
1131 var ConnHdlr vc_conn;
1132 var ConnHdlrPars pars;
1133 f_init();
1134 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1135 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1136 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1137 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1138 vc_conn.done;
1139 }
1140 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001141 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001142}
1143
Harald Welte075d84c2018-03-12 13:07:24 +01001144/* Test SACCH scheduling of multiple different SI message types */
1145private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1146 var octetstring si5 := f_rnd_octstring(19);
1147 var octetstring si5bis := f_rnd_octstring(19);
1148 var octetstring si5ter := f_rnd_octstring(19);
1149 var octetstring si6 := f_rnd_octstring(19);
1150
1151 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1152 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1153 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1154 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1155
1156 f_l1_tune(L1CTL);
1157 RSL.clear;
1158
1159 /* activate the logical channel */
1160 f_est_dchan();
1161 L1CTL.clear;
1162
1163 /* check that SACCH actually are received as expected */
1164 f_sacch_present(si5);
1165 f_sacch_present(si5bis);
1166 f_sacch_present(si5ter);
1167 f_sacch_present(si6);
1168
1169 /* release the channel */
1170 f_rsl_chan_deact();
1171 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1172}
1173testcase TC_sacch_multi() runs on test_CT {
1174 var ConnHdlr vc_conn;
1175 var ConnHdlrPars pars;
1176 f_init();
1177 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1178 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1179 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1180 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1181 vc_conn.done;
1182 }
1183 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001184 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001185}
1186
Harald Welte55700662018-03-12 13:15:43 +01001187/* Test if SACH information is modified as expected */
1188private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1189 var octetstring si5 := f_rnd_octstring(19);
1190 var octetstring si6 := f_rnd_octstring(19);
1191
1192 /* First, configure both SI5 and SI6 to be transmitted */
1193 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1194 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1195
1196 f_l1_tune(L1CTL);
1197 RSL.clear;
1198
1199 /* activate the logical channel */
1200 f_est_dchan();
1201 L1CTL.clear;
1202
1203 /* check that SACCH actually are received as expected */
1204 f_sacch_present(si5);
1205 f_sacch_present(si6);
1206
1207 /* disable SI6 */
1208 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1209
1210 /* check that SI5 is still transmitted */
1211 f_sacch_present(si5);
1212 /* check if SI6 is now gone */
1213 f_sacch_missing(si6);
1214
1215 /* release the channel */
1216 f_rsl_chan_deact();
1217 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1218}
1219testcase TC_sacch_multi_chg() runs on test_CT {
1220 var ConnHdlr vc_conn;
1221 var ConnHdlrPars pars;
1222 f_init();
1223 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1224 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1225 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1226 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1227 vc_conn.done;
1228 }
1229 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001230 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001231}
1232
Harald Weltec8d363c2019-05-19 20:36:48 +02001233/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1234private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1235 var octetstring si5 := f_rnd_octstring(19);
1236 var octetstring si6 := f_rnd_octstring(19);
1237 var octetstring si5_specific := f_rnd_octstring(19);
1238 var octetstring si6_specific := f_rnd_octstring(19);
1239
1240 /* First, configure both SI5 and SI6 to be transmitted */
1241 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1242 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1243
1244 f_l1_tune(L1CTL);
1245 RSL.clear;
1246
1247 /* activate channel with different SACCH filling */
1248 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1249 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1250 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1251 }));
1252 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1253 RSL_IE_Body:{sacch_info := sacch_info})) };
1254 f_est_dchan(more_ies := addl_ies);
1255
1256 /* check that SACCH actually are received as expected */
1257 f_sacch_present(si5_specific);
1258 f_sacch_present(si6_specific);
1259
1260 /* release the channel */
1261 f_rsl_chan_deact();
1262 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1263}
1264testcase TC_sacch_chan_act() runs on test_CT {
1265 var ConnHdlr vc_conn;
1266 var ConnHdlrPars pars;
1267 f_init();
1268
1269 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1270 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1271 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1272 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1273 vc_conn.done;
1274 }
1275 /* TODO: do the above in parallel, rather than sequentially? */
1276 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1277}
1278
Harald Welte8b01c792019-05-19 22:51:25 +02001279/* verify that SACCH DL transmission is started only if MS power IE present
1280 * see section 4.1.3 of 3GPP TS 48.058 */
1281private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1282 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001283 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
Harald Welte8b01c792019-05-19 22:51:25 +02001284
1285 f_l1_tune(L1CTL);
1286 RSL.clear;
1287
1288 /* Step 1: Activate ASYNC HO channel without MS power IE */
1289
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001290 var integer ho_ref := oct2int(f_rnd_octstring(1));
1291 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1292 RSL_IE_Body:{ handover_ref := ho_ref }));
1293 var RSL_IE_List addl_ies := {
1294 ho_ref_ie
1295 };
1296
Harald Welte8b01c792019-05-19 22:51:25 +02001297 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001298 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001299 /* don't perform immediate assignment here, as we're testing non-IA case */
1300 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001301 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001302
1303 /* Verify that no DL SACCH is being received */
1304 f_sacch_missing(?);
1305
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001306 /* Send handover Access Burst and expect SACCH to start */
1307 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1308
1309 f_sacch_present(si5);
1310
Harald Welte8b01c792019-05-19 22:51:25 +02001311 f_rsl_chan_deact();
1312 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1313
1314
1315 /* Step 2: Activate ASYNC HO channel with MS power IE */
1316
1317 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001318 addl_ies := {
1319 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001320 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1321 };
1322 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1323 /* don't perform immediate assignment here, as we're testing non-IA case */
1324 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001325 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001326
1327 /* Verify that DL SACCH is being received */
1328 f_sacch_present(si5);
1329
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001330 /* Send handover Access Burst and expect SACCH to remain present */
1331 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1332
1333 f_sacch_present(si5);
1334
Harald Welte8b01c792019-05-19 22:51:25 +02001335 f_rsl_chan_deact();
1336 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1337}
1338testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1339 var ConnHdlr vc_conn;
1340 var ConnHdlrPars pars;
1341 f_init();
1342
1343 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1344 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1345 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1346 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1347 vc_conn.done;
1348 }
1349 /* TODO: do the above in parallel, rather than sequentially? */
1350 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1351}
1352
1353/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1354 * see section 4.1.4 of 3GPP TS 48.058 */
1355private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1356 var octetstring si5 := f_rnd_octstring(19);
Neels Hofmeyrdd597412020-11-03 20:35:00 +00001357 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1358
Harald Welte8b01c792019-05-19 22:51:25 +02001359 var RSL_IE_List addl_ies;
1360
1361 f_l1_tune(L1CTL);
1362 RSL.clear;
1363
1364 /* Step 1: Activate SYNC HO channel without MS power IE */
1365
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001366 var integer ho_ref := oct2int(f_rnd_octstring(1));
1367 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1368 RSL_IE_Body:{ handover_ref := ho_ref }));
1369 addl_ies := {
1370 ho_ref_ie
1371 };
1372
Harald Welte8b01c792019-05-19 22:51:25 +02001373 /* Activate channel on BTS side */
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001374 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
Harald Welte8b01c792019-05-19 22:51:25 +02001375 /* don't perform immediate assignment here, as we're testing non-IA case */
1376 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001377 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001378
1379 /* Verify that no DL SACCH is being received */
1380 f_sacch_missing(?);
1381
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001382 /* Send handover Access Burst and expect SACCH to start */
1383 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1384
1385 f_sacch_present(si5);
1386
Harald Welte8b01c792019-05-19 22:51:25 +02001387 f_rsl_chan_deact();
1388 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1389
1390
1391 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1392
1393 /* Activate channel on BTS side */
1394 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001395 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001396 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1397 };
1398 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1399 /* don't perform immediate assignment here, as we're testing non-IA case */
1400 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001401 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001402
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001403 /* Verify that DL SACCH is being received, because MS Power IE was sent */
1404 f_sacch_present(si5);
Harald Welte8b01c792019-05-19 22:51:25 +02001405
Neels Hofmeyrd55a3ac2020-11-09 00:54:34 +00001406 /* Send handover Access Burst and expect SACCH to remain present */
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001407 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1408
1409 f_sacch_present(si5);
1410
Harald Welte8b01c792019-05-19 22:51:25 +02001411 f_rsl_chan_deact();
1412 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1413
1414
1415 /* Step 2b: Activate SYNC HO channel with TA IE */
1416
1417 /* Activate channel on BTS side */
1418 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001419 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001420 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1421 };
1422 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1423 /* don't perform immediate assignment here, as we're testing non-IA case */
1424 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001425 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001426
1427 /* Verify that no DL SACCH is being received */
1428 f_sacch_missing(?);
1429
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001430 /* Send handover Access Burst and expect SACCH to start */
1431 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1432
1433 f_sacch_present(si5);
1434
Harald Welte8b01c792019-05-19 22:51:25 +02001435 f_rsl_chan_deact();
1436 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1437
1438
1439 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1440
1441 /* Activate channel on BTS side */
1442 addl_ies := {
Neels Hofmeyrd34681b2020-11-03 20:35:00 +00001443 ho_ref_ie,
Harald Welte8b01c792019-05-19 22:51:25 +02001444 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1445 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1446 };
1447 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1448 /* don't perform immediate assignment here, as we're testing non-IA case */
1449 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001450 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001451
1452 /* Verify that DL SACCH is being received */
1453 f_sacch_present(si5);
1454
Neels Hofmeyr76d1d1a2020-11-09 00:03:33 +00001455 /* Send handover Access Burst and expect SACCH to remain present */
1456 f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1457
1458 f_sacch_present(si5);
1459
Harald Welte8b01c792019-05-19 22:51:25 +02001460 f_rsl_chan_deact();
1461 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1462}
1463testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1464 var ConnHdlr vc_conn;
1465 var ConnHdlrPars pars;
1466 f_init();
1467
1468 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1469 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1470 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1471 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1472 vc_conn.done;
1473 }
1474 /* TODO: do the above in parallel, rather than sequentially? */
1475 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1476}
Harald Welte629cc6b2018-03-11 17:19:05 +01001477
1478
1479/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001480 * RACH Handling
1481 ***********************************************************************/
1482
Harald Welte8c24c2b2018-02-26 08:31:31 +01001483/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001484private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001485 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001486 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001487 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001488
Harald Welte8c24c2b2018-02-26 08:31:31 +01001489 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001490 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001491 for (var integer i := 0; i < 1000; i := i+1) {
Neels Hofmeyrc897cfb2020-11-09 00:06:01 +00001492 var OCT1 ra;
Philipp Maier16ade782020-07-08 21:36:00 +02001493 if (emerg == true) {
1494 ra := f_rnd_ra_emerg();
1495 } else {
1496 ra := f_rnd_ra_cs();
1497 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001498 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1499 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001500 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001501 }
1502 fn_last := fn;
1503
1504 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001505 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001506 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001507 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001508 T.stop;
1509 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001510 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001511 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001512 }
1513 [] RSL_CCHAN.receive { repeat; }
1514 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001515 test_failed := true;
1516 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001517 }
1518 }
1519 }
Maxba06feb2019-03-05 10:52:46 +01001520 if (test_failed) {
1521 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001522 }
Maxba06feb2019-03-05 10:52:46 +01001523 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001524 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001525}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001526
Philipp Maier16ade782020-07-08 21:36:00 +02001527/* Normal variant */
1528testcase TC_rach_content() runs on test_CT {
1529 f_TC_rach_content(emerg := false);
1530}
1531
1532/* Emergency call variant */
1533testcase TC_rach_content_emerg() runs on test_CT {
1534 f_TC_rach_content(emerg := true);
1535}
1536
Harald Welte8c24c2b2018-02-26 08:31:31 +01001537/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1538testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001539 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001540 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001541 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001542 f_l1_tune(L1CTL);
1543
1544 var GsmFrameNumber fn_last := 0;
1545 for (var integer i := 0; i < 1000; i := i+1) {
1546 var OCT1 ra := f_rnd_ra_cs();
1547 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1548 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001550 }
1551 fn_last := fn;
1552 }
1553 var integer rsl_chrqd := 0;
1554 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001555 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001556 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001557 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001558 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001559 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001560 repeat;
1561 }
1562 [] RSL_CCHAN.receive { repeat; }
1563 [] T.timeout { }
1564 }
1565 if (rsl_chrqd == 1000) {
1566 setverdict(pass);
1567 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001569 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001570 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001571}
1572
Harald Welte3453ab42019-05-24 21:19:58 +02001573private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1574 var charstring bts_str := "bts " & int2str(bts_nr);
1575 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1576}
1577
1578/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1579private template integer tr_rach_slots_per_interval := (90 .. 130);
1580
1581/* Expect 0 RACH load on an idle BTS that has just started up */
1582testcase TC_rach_load_idle_thresh0() runs on test_CT {
1583 var ASP_RSL_Unitdata rx_ud;
1584
1585 f_init_vty_bsc();
1586 /* send load indications even at 0% load */
1587 f_vty_load_ind_thresh(0);
1588 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1589 f_sleep(2.0);
1590
1591 f_init();
1592
Harald Weltee37f9a52020-10-11 20:45:23 +02001593 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1594 alt {
1595 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1596 [] RSL_CCHAN.receive { repeat }
1597 }
1598
Harald Welte3453ab42019-05-24 21:19:58 +02001599 timer T := 5.0;
1600 T.start;
1601 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001602 [] 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 +02001603 setverdict(pass);
1604 repeat;
1605 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001606 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001607 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1608 repeat;
1609 }
1610 [] RSL_CCHAN.receive {
1611 repeat;
1612 }
1613 [] T.timeout { }
1614 }
1615
1616 f_vty_load_ind_thresh(10);
1617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1618}
1619
1620/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1621testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1622 var ASP_RSL_Unitdata rx_ud;
1623
1624 f_init_vty_bsc();
1625 f_init();
1626
1627 timer T := 5.0;
1628 T.start;
1629 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001630 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001631 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1632 repeat;
1633 }
1634 [] RSL_CCHAN.receive {
1635 repeat;
1636 }
1637 [] T.timeout {
1638 setverdict(pass);
1639 }
1640 }
1641
1642 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1643}
1644
1645/* Expect 0 RACH load on an idle BTS that has just started up */
1646testcase TC_rach_load_count() runs on test_CT {
1647 var ASP_RSL_Unitdata rx_ud;
1648 var integer load_access_count := 0;
1649
1650 f_init_vty_bsc();
1651 /* send load indications even at 0% load */
1652 f_vty_load_ind_thresh(0);
1653 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1654 f_sleep(2.0);
1655 f_init();
1656
1657 f_init_l1ctl();
1658 f_sleep(1.0);
1659 f_l1_tune(L1CTL);
1660
Harald Welte52ae1682020-10-11 20:45:55 +02001661 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1662 alt {
1663 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1664 [] RSL_CCHAN.receive { repeat }
1665 }
1666
Harald Welte3453ab42019-05-24 21:19:58 +02001667 var GsmFrameNumber fn_last := 0;
1668 for (var integer i := 0; i < 1000; i := i+1) {
1669 var OCT1 ra := f_rnd_ra_cs();
1670 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1671 if (fn == fn_last) {
1672 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1673 }
1674 fn_last := fn;
1675 }
1676
1677 timer T := 5.0;
1678 T.start;
1679 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001680 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001681 -> value rx_ud {
1682 var RSL_IE_Body ie;
1683 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1684 load_access_count := load_access_count + ie.rach_load.access_count;
1685 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1686 setverdict(fail, "Access count cannot be < Busy count");
1687 }
1688 repeat;
1689 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001690 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001691 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1692 repeat;
1693 }
1694 [] RSL_CCHAN.receive {
1695 repeat;
1696 }
1697 [] T.timeout { }
1698 }
1699 if (load_access_count == 1000) {
1700 setverdict(pass);
1701 } else {
1702 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1703 }
1704
1705 f_vty_load_ind_thresh(10);
1706 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1707}
1708
Harald Welte54a2a2d2018-02-26 09:14:05 +01001709private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001710 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001711 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001712 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001713 f_sleep(0.5);
1714
1715 /* Transmit RACH request + wait for confirmation */
1716 var OCT1 ra := f_rnd_ra_cs();
1717 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1718
1719 /* Check for expected result */
1720 timer T := 1.5;
1721 T.start;
1722 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001723 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001724 setverdict(pass);
1725 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001726 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001728 }
1729 [] RSL_CCHAN.receive { repeat; }
1730 [not expect_pass] T.timeout {
1731 setverdict(pass);
1732 }
1733 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001734 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001735 }
1736 }
1737}
1738
1739/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1740testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001741 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001742 f_init_l1ctl();
1743 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001744 f_sleep(1.0);
1745
1746 /* default max-ta is 63 (full range of GSM timing advance */
1747
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001748 /* We allow early arrival up to 2 symbols */
1749 f_rach_toffs(-1*256, true);
1750 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001751 f_rach_toffs(-10*256, false);
1752
1753 /* 0 / 32 / 63 bits is legal / permitted */
1754 f_rach_toffs(0, true);
1755 f_rach_toffs(32*256, true);
1756 f_rach_toffs(63*256, true);
1757
1758 /* more than 63 bits is not legal / permitted */
1759 f_rach_toffs(64*256, false);
1760 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001762}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001763
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001764private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001765 var GsmFrameNumber fn;
1766 var RSL_Message rm;
1767
1768 f_l1_tune(L1CTL);
1769 RSL.clear;
1770
1771 /* Generate a random Handover Reference */
1772 var integer ho_ref := oct2int(f_rnd_octstring(1));
1773
1774 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1775 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1776 RSL_IE_Body:{ handover_ref := ho_ref }));
1777
1778 /* Activate a channel on the BTS side (no encryption) */
1779 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1780 act_type := t_RSL_IE_ActType_HO_SYNC);
1781
1782 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1783 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001784 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001785
1786 /* Send handover Access Burst */
1787 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1788
1789 /* TODO: test mismatching Handover Reference, and missing IE */
1790
1791 /* Wait for handover detection */
1792 timer T := 3.0;
1793 T.start;
1794 alt {
1795 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1796 log("Handover RACH has been detected: ", rm);
1797 setverdict(pass);
1798 }
1799 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1801 log2str("RSL_CHAN_RQD was not expected: ", rm));
1802 }
1803 [] RSL.receive { repeat; }
1804 [] T.timeout {
1805 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1806 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1807 }
1808 }
1809
1810 /* Release the channel */
1811 f_rsl_chan_deact();
1812 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1813}
1814
1815/* Test handover RACH detection */
1816testcase TC_ho_rach() runs on test_CT {
1817 var ConnHdlrPars pars;
1818 var ConnHdlr vc_conn;
1819
1820 f_init();
1821
1822 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1823 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1824 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1825 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1826 vc_conn.done;
1827 }
1828
1829 /* TODO: do the above in parallel, rather than sequentially? */
1830 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1831}
1832
Harald Welte93640c62018-02-25 16:59:33 +01001833/***********************************************************************
1834 * Measurement Processing / Reporting
1835 ***********************************************************************/
1836
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001837private template (value) LapdmAddressField
1838ts_LapdmAddr(template (value) LapdmSapi sapi,
1839 template (value) boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001840 spare := '0'B,
1841 lpd := 0,
1842 sapi := sapi,
1843 c_r := c_r,
1844 ea := true
1845}
1846
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001847private template (value) LapdmFrameAB
1848ts_LAPDm_AB(template (value) LapdmSapi sapi,
1849 template (value) GsmRrL3Message l3,
1850 template (value) boolean c_r := false,
1851 template (value) boolean p := false) := {
Harald Welte70767382018-02-21 12:16:40 +01001852 addr := ts_LapdmAddr(sapi, c_r),
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001853 ctrl := ts_LapdmCtrlUI(valueof(p)),
Harald Welte70767382018-02-21 12:16:40 +01001854 len := 0, /* overwritten */
1855 m := false,
1856 el := 1,
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001857 payload := enc_GsmRrL3Message(valueof(l3))
Harald Welte70767382018-02-21 12:16:40 +01001858}
1859
1860/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001861private altstep as_l1_sacch() runs on ConnHdlr {
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001862 var template (value) LapdmFrameAB lb;
Harald Welte70767382018-02-21 12:16:40 +01001863 var L1ctlDlMessage l1_dl;
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001864
Harald Weltef8df4cb2018-03-10 15:15:08 +01001865 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001866 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Vadim Yanitskiy5351ccf2020-11-11 20:48:17 +07001867
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001868 lb := ts_LAPDm_AB(0, ts_MEAS_REP(g_pars.l1_pars.meas_valid,
Vadim Yanitskiycb57c1b2020-11-11 20:57:15 +07001869 g_pars.l1_pars.meas_ul.full.rxlev,
1870 g_pars.l1_pars.meas_ul.sub.rxlev,
1871 g_pars.l1_pars.meas_ul.full.rxqual,
1872 g_pars.l1_pars.meas_ul.sub.rxqual));
Harald Welte70767382018-02-21 12:16:40 +01001873 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001874
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001875 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1876 g_pars.l1_pars.ms_power_level, false,
1877 g_pars.l1_pars.ms_actual_ta);
1878
Vadim Yanitskiyf105a5b2020-11-30 14:27:55 +01001879 /* According to 3GPP TS 44.018, section 10.5.2.20, we should pad with zeroes */
1880 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(valueof(lb)), 21, '00'O);
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001881
1882 log("Sending Measurement Report: ", l1h, l2);
1883 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001884 repeat;
1885 }
1886}
1887
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07001888/* handle incoming downlink SACCH, decode the L1 header into the given record */
1889private altstep as_l1_sacch_l1h(inout SacchL1Header l1h,
1890 boolean do_apply := true)
1891runs on ConnHdlr
1892{
1893 var L1ctlDlMessage l1_dl;
1894
1895 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1896 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
1897 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
1898 log(%definitionId, "(): Rx SACCH L1 header: ", l1h);
1899
1900 if (do_apply) {
1901 /* Update TA and MS power to follow what BTS requests */
1902 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
1903 }
1904 }
1905}
1906
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07001907private altstep as_l1_dcch_loop() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001908 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001909 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001910 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1911 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001912 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1913 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001914 repeat;
1915 }
1916}
1917
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001918private altstep as_l1_tch_loop() runs on ConnHdlr {
1919 var L1ctlDlMessage l1_dl;
1920 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(g_chan_nr)) -> value l1_dl {
1921 log("TCH received: ", l1_dl.payload.traffic_ind.data);
Philipp Maier149c3922020-10-22 17:29:36 +02001922
1923 /* occasionaly inject FACCH frames into the uplink */
1924 if (g_pars.l1_pars.facch_enabled == true and l1_dl.dl_info.frame_nr mod 5 == 0) {
1925 var octetstring pl := '010301'O;
1926 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1927 f_pad_oct(pl, 23, '2B'O)));
1928 } else {
1929 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(g_chan_nr, l1_dl.dl_info.link_id,
1930 l1_dl.payload.traffic_ind.data));
1931 }
1932
Vadim Yanitskiydc008112020-10-19 14:42:04 +07001933 repeat;
1934 }
1935}
1936
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001937private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001938 uint6_t rxlev,
1939 uint3_t rxqual
1940}
1941
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001942private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001943 MeasElem full,
1944 MeasElem sub
1945}
1946
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001947private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001948 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001949 boolean toa256_enabled,
Vadim Yanitskiy7dad6082020-11-28 22:42:27 +01001950 boolean meas_valid,
Harald Welte70767382018-02-21 12:16:40 +01001951 MeasElemFS meas_ul,
1952 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001953 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001954 uint5_t ms_power_level,
Philipp Maier149c3922020-10-22 17:29:36 +02001955 uint8_t ms_actual_ta,
1956 boolean facch_enabled
Harald Welte70767382018-02-21 12:16:40 +01001957}
1958
1959/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1960private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1961 return 63 + (toffs256s/256);
1962}
1963
Harald Welted5684392018-03-10 18:22:04 +01001964private function f_max(integer a, integer b) return integer {
1965 if (a > b) {
1966 return a;
1967 } else {
1968 return b;
1969 }
1970}
1971
1972private function f_min(integer a, integer b) return integer {
1973 if (a < b) {
1974 return a;
1975 } else {
1976 return b;
1977 }
1978}
1979
1980/* compute negative tolerance val-tolerance, ensure >= min */
1981private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1982 val := val - tolerance;
1983 return f_max(val, min);
1984}
1985
1986/* compute positive tolerance val+tolerance, ensure <= max */
1987private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1988 val := val + tolerance;
1989 return f_min(val, max);
1990}
1991
1992/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1993private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1994return template integer {
1995 var template integer ret;
1996 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1997 return ret;
1998}
1999
2000
Harald Welte70767382018-02-21 12:16:40 +01002001/* build a template for matching measurement results against */
2002private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
2003 var ConnL1Pars l1p := g_pars.l1_pars;
2004 var template RSL_IE_UplinkMeas ul_meas := {
2005 len := 3,
2006 rfu := '0'B,
2007 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01002008 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002009 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002010 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01002011 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01002012 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
2013 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01002014 supp_meas_info := omit
2015 };
Harald Welte685d5982018-02-27 20:42:05 +01002016 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02002017 ul_meas.len := (3+8);
2018 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002019 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02002020 toa256_min := ?,
2021 toa256_max := ?,
2022 toa256_std_dev := ?
2023 }
Harald Welte685d5982018-02-27 20:42:05 +01002024 }
Harald Welte70767382018-02-21 12:16:40 +01002025 var template RSL_IE_BS_Power bs_power := {
2026 reserved := 0,
2027 epc := false,
2028 fpc := false,
2029 power_level := l1p.bs_power_level
2030 };
2031 var template RSL_IE_L1Info l1_info := {
2032 ms_power_lvl := l1p.ms_power_level,
2033 fpc := false,
2034 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002035 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01002036 };
2037 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002038 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01002039 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
2040 ?, t_toffs);
2041}
2042
Philipp Maierdd841d32019-12-17 14:44:54 +01002043/* build a template for matching measurement results that do not contain any
2044 * MS related measurement (l1_info, l3_info and ms timing offset). */
2045private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
2046 var ConnL1Pars l1p := g_pars.l1_pars;
2047 var template RSL_IE_UplinkMeas ul_meas := {
2048 len := 3,
2049 rfu := '0'B,
2050 dtx_d := l1p.dtx_enabled,
2051 rxlev_f_u := ?,
2052 reserved1 := '00'B,
2053 rxlev_s_u := ?,
2054 reserved2 := '00'B,
2055 rxq_f_u := ?,
2056 rxq_s_u := ?,
2057 supp_meas_info := omit
2058 };
2059 if (l1p.toa256_enabled) {
2060 ul_meas.len := (3+8);
2061 ul_meas.supp_meas_info := {
2062 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
2063 toa256_min := ?,
2064 toa256_max := ?,
2065 toa256_std_dev := ?
2066 }
2067 }
2068 var template RSL_IE_BS_Power bs_power := {
2069 reserved := 0,
2070 epc := false,
2071 fpc := false,
2072 power_level := l1p.bs_power_level
2073 };
2074
2075 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
2076}
2077
Harald Welte70767382018-02-21 12:16:40 +01002078/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002079private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002080 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01002081 var boolean chan_est := false;
2082
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07002083 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01002084
2085 /* Receive osmocom specific measurement reports. This is the normal
2086 * case. Here we verify that the measurement reports we sent are
2087 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01002088 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
2089 /* increment counter of next to-be-expected meas rep */
2090 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2091 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01002092 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01002093
2094 /* The following two cases may only happen in the beginning
2095 * of the channel establishment phase. Once we have received
2096 * the "our" measurement report the first time, the channel
2097 * is established and empty or hardcoded TRXCON reports must
2098 * not occur anymore. */
2099 chan_est := true;
2100
2101 repeat;
2102 }
2103
2104 /* When the BTS has established the channel, the MS might need slightly
2105 * more time to establish the channel and actually start sending. The
2106 * result is then a measurement report that just lacks the measurement
2107 * information of the MS. This is normal and we tolerate this behavior. */
2108 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
2109 /* increment counter of next to-be-expected meas rep */
2110 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2111 /* Re-start the timer expecting the next MEAS RES */
2112 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01002113 repeat;
2114 }
Philipp Maierdd841d32019-12-17 14:44:54 +01002115
2116 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
2117 * measurements if the TTCN3 side does not supply measurement input in
2118 * time. In those cases TRXCON will either use a cached measurement
2119 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
2120 * report the templates above will not match. We tolerate this
2121 * behavior, but only once. */
2122 [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 +01002123 /* increment counter of next to-be-expected meas rep */
2124 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
2125 if (g_first_meas_res) {
2126 g_first_meas_res := false;
2127 repeat;
2128 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002129 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01002130 }
Harald Welte70767382018-02-21 12:16:40 +01002131 }
2132 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01002134 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02002135 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002136 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01002137 }
2138}
2139
Harald Weltee613f962018-04-18 22:38:16 +02002140private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
2141 select (rsl_alg_id) {
2142 case (RSL_ALG_ID_A5_0) { return 0; }
2143 case (RSL_ALG_ID_A5_1) { return 1; }
2144 case (RSL_ALG_ID_A5_2) { return 2; }
2145 case (RSL_ALG_ID_A5_3) { return 3; }
2146 case (RSL_ALG_ID_A5_4) { return 4; }
2147 case (RSL_ALG_ID_A5_5) { return 5; }
2148 case (RSL_ALG_ID_A5_6) { return 6; }
2149 case (RSL_ALG_ID_A5_7) { return 7; }
2150 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2152 /* Make compiler happy by calling mtc.stop here. It is already
2153 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002154 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002155 }
2156 }
2157}
2158
2159private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2160 select (rsl_alg_id) {
2161 case (RSL_ALG_ID_A5_1) { return '000'B; }
2162 case (RSL_ALG_ID_A5_2) { return '001'B; }
2163 case (RSL_ALG_ID_A5_3) { return '010'B; }
2164 case (RSL_ALG_ID_A5_4) { return '011'B; }
2165 case (RSL_ALG_ID_A5_5) { return '100'B; }
2166 case (RSL_ALG_ID_A5_6) { return '101'B; }
2167 case (RSL_ALG_ID_A5_7) { return '110'B; }
2168 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2170 /* Make compiler happy by calling mtc.stop here. It is already
2171 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002172 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002173 }
2174 }
2175}
2176
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002177/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2178private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2179 var GsmFrameNumber fn;
2180 timer T := 8.0;
2181
2182 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2183 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2184
2185 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2186 /* Send the actual RACH */
2187 fn := f_L1CTL_RACH(L1CTL, ra);
2188
2189 T.start;
2190 alt {
2191 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2192 [] T.timeout {
2193 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2194 }
2195 }
2196 T.stop
2197 return fn;
2198}
Harald Weltee613f962018-04-18 22:38:16 +02002199
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002200/* Tune to a dedicated channel: L1CTL only */
2201private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002202 if (not pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002203 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr, pars.tsc,
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07002204 mp_trx_pars[0].arfcn));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002205 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002206 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr, pars.tsc,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002207 pars.fhp.maio_hsn.hsn,
2208 pars.fhp.maio_hsn.maio,
2209 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002210 }
2211}
2212
Harald Welte70767382018-02-21 12:16:40 +01002213/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002214private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002215 var GsmFrameNumber fn;
2216 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002217 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002218 var integer ra := 23;
2219
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002220 /* Send RACH request and wait for ChanReq */
2221 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002222
2223 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002224 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002225
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002226 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002227 if (g_pars.fhp.enabled) {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002228 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002229 } else {
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07002230 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx_pars[0].arfcn, g_pars.tsc));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002231 }
2232
Harald Welte70767382018-02-21 12:16:40 +01002233 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002234 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 +01002235 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2236
2237 /* receive IMM.ASS on MS side */
2238 var ImmediateAssignment ia_um;
2239 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002240
2241 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2242 if (ch_desc.h != ia_um.chan_desc.h) {
2243 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2244 }
2245
Harald Welte70767382018-02-21 12:16:40 +01002246 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002247 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002248 /* enable encryption, if requested */
2249 if (encr_enable) {
2250 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2251 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2252 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002253
Vadim Yanitskiy52787bf2020-10-19 17:34:52 +07002254 /* Send TCH Mode Request to the L1 if needed */
2255 if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
2256 var L1ctlTchMode tch_mode;
2257
2258 select (g_pars.chan_mode.coding_alg_rate) {
2259 case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
2260 case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
2261 case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
2262 case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
2263 case else {
2264 log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
2265 " is not supported by the L1, falling back to signalling");
2266 tch_mode := L1CTL_CHAN_MODE_SIGN;
2267 }
2268 }
2269
2270 f_L1CTL_TCH_MODE(L1CTL, tch_mode);
2271 }
2272
Harald Weltefa45e9e2018-03-10 18:59:03 +01002273 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002274}
2275
2276/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002277private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002278 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002279 RSL.clear;
2280
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002281 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002282 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002283 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002284 }
Harald Welte70767382018-02-21 12:16:40 +01002285
2286 f_est_dchan();
2287
2288 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2289 * RSL measurement reports on Abis side */
2290 timer T := 8.0;
2291 T.start;
2292 alt {
2293 [] as_l1_sacch();
2294 [] as_meas_res();
Vadim Yanitskiya4f88c62020-10-19 14:38:37 +07002295 [] as_l1_dcch_loop();
Vadim Yanitskiydc008112020-10-19 14:42:04 +07002296 [] as_l1_tch_loop();
Harald Welte70767382018-02-21 12:16:40 +01002297 [] L1CTL.receive { repeat; }
2298 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002299 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002300 * of any earlier errors, so if we reach this timeout, we're good */
2301 setverdict(pass);
2302 }
2303 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002304 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002305 }
2306 }
2307 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002308 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002309}
Harald Welte0472ab42018-03-12 15:02:26 +01002310
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002311/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2312private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002313 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002314 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2315 timer Tup := 10.0;
2316 Tup.start;
2317 alt {
2318 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2319 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2320 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002321
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002322 if (rx_lvl != max_rx_lvl) {
2323 repeat;
2324 }
2325 Tup.stop;
2326 }
2327 [] L1CTL.receive { repeat; }
2328 [] Tup.timeout {
2329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2330 log2str("Didn't reach full power ", max_rx_lvl));
2331 }
2332 }
2333 return max_rx_lvl;
2334}
2335
2336/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2337private function f_verify_ramp_up() runs on ConnHdlr {
2338 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002339 var integer initial_rx_lvl := -1;
2340 var integer last_rx_lvl := -1;
2341 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2342
2343 timer T := 2.0;
2344 alt {
2345 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2346 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2347 log("Received rx_level=", rx_lvl);
2348 if (initial_rx_lvl == -1) {
2349 initial_rx_lvl := rx_lvl;
2350 last_rx_lvl := rx_lvl;
2351
2352 /* Expect a somehow low value during first received messages */
2353 if (initial_rx_lvl >= max_rx_lvl / 2) {
2354 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2355 log2str("Detected high initial tx power during ramp up: ",
2356 initial_rx_lvl , ", full power is", max_rx_lvl));
2357 }
2358 }
2359
2360 /* received Rx level bigger than maximum allowed power by CN */
2361 if (rx_lvl > max_rx_lvl) {
2362 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2363 log2str("Detected Tx power higher than full power: ",
2364 rx_lvl , " > ", max_rx_lvl));
2365 }
2366
2367 /* Make sure it never decreases, since we are rumping up */
2368 if (last_rx_lvl > rx_lvl) {
2369 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2370 log2str("Detected Tx power decrease during ramp up: ",
2371 last_rx_lvl , " -> ", rx_lvl));
2372 }
2373
2374 if (rx_lvl == max_rx_lvl and not T.running) {
2375 /* We reached the maximum power, start timer and receive
2376 /* a few more to make sure we don't surpass it */
2377 log("Reached full power, wating a bit more until success");
2378 T.start;
2379 }
2380
2381 last_rx_lvl := rx_lvl;
2382 repeat;
2383 }
2384 [] L1CTL.receive { repeat; }
2385 [] T.timeout { }
2386 }
2387
2388 /* We didn't increase tx power during ramp up */
2389 if (initial_rx_lvl < last_rx_lvl) {
2390 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2391 } else {
2392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2393 log2str("No Tx power increase during whole ramp up: ",
2394 initial_rx_lvl , " -> ", last_rx_lvl));
2395 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002396}
2397
2398/* verify BTS ramps power down to rx_level 0 */
2399private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2400 var L1ctlDlMessage l1_dl;
2401 var integer last_rx_lvl := max_rx_lvl;
2402
2403 timer Tdown := 5.0;
2404 Tdown.start;
2405 alt {
2406 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2407 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2408 log("Received rx_level=", rx_lvl);
2409
2410 /* received Rx level bigger than maximum allowed power by CN */
2411 if (rx_lvl > max_rx_lvl) {
2412 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2413 log2str("Detected Tx power higher than full power: ",
2414 rx_lvl , " > ", max_rx_lvl));
2415 }
2416
2417 /* Make sure it never increases, since we are rumping down */
2418 if (last_rx_lvl < rx_lvl) {
2419 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2420 log2str("Detected Tx power increase during ramp up: ",
2421 last_rx_lvl , " -> ", rx_lvl));
2422 }
2423
2424 last_rx_lvl := rx_lvl;
2425 if (last_rx_lvl != 0) {
2426 repeat;
2427 }
2428 /* we reached power level 0, we are done */
2429 Tdown.stop;
2430 }
2431 [] L1CTL.receive { repeat; }
2432 [] Tdown.timeout { }
2433 }
2434
2435 /* We didn't increase tx power during ramp down */
2436 if (max_rx_lvl > last_rx_lvl) {
2437 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2438 } else {
2439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2440 log2str("No Tx power decrease during whole ramp down: ",
2441 max_rx_lvl , " -> ", last_rx_lvl));
2442 }
2443}
2444
2445/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002446private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002447 f_l1_tune(L1CTL);
2448 RSL.clear;
2449
2450 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002451
2452 setverdict(pass);
2453}
2454testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2455 var ConnHdlr vc_conn;
2456 var ConnHdlrPars pars;
2457 f_init();
2458 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2459 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2460 pcu_comp := false, trxc_comp := true);
2461 vc_conn.done;
2462 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2463}
2464
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002465/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002466private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002467 f_connhdlr_init_vty_bsc();
2468
2469 f_l1_tune(L1CTL);
2470 RSL.clear;
2471
2472 /* Wait until BTS is started and at full power */
2473 var integer max_rx_lvl := f_wait_ramp_up();
2474 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2475
2476 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2477 f_verify_ramp_down(max_rx_lvl);
2478
2479 setverdict(pass);
2480}
2481testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2482 var ConnHdlr vc_conn;
2483 var ConnHdlrPars pars;
2484 f_init();
2485 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2486 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2487 pcu_comp := false, trxc_comp := true);
2488 vc_conn.done;
2489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2490}
2491
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002492/* Verify Tx power:
2493 * + ramping down during ADM state UNLOCKED->LOCKED
2494 * + ramping up during ADM state LOCKED->UNLOCKED
2495 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002496private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002497 var L1ctlDlMessage l1_dl;
2498 var integer last_rx_lvl;
2499
2500 f_connhdlr_init_vty_bsc();
2501
2502 f_l1_tune(L1CTL);
2503 RSL.clear;
2504
2505 /* Wait until BTS is started and at full power */
2506 var integer max_rx_lvl := f_wait_ramp_up();
2507 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2508
2509 log("ADM STATE UNLOCKED->LOCKED");
2510 f_vty_enter_cfg_trx(BSCVTY);
2511 f_vty_transceive(BSCVTY, "rf_locked 1");
2512 last_rx_lvl := max_rx_lvl;
2513 f_verify_ramp_down(max_rx_lvl);
2514
2515 /* Let some time after we received 0dBm, then check we don't receive BCCH
2516 * anymore because scheduler has stopped after ramping down */
2517 f_sleep(2.0);
2518 L1CTL.clear;
2519 timer Tlocked := 2.0;
2520 Tlocked.start;
2521 alt {
2522 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2523 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2524 log2str("Received data_ind during rf_locked: ", l1_dl));
2525 }
2526 [] L1CTL.receive { repeat; }
2527 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2528 }
2529
2530 log("ADM STATE LOCKED->UNLOCKED");
2531 f_vty_transceive(BSCVTY, "rf_locked 0");
2532 f_verify_ramp_up();
2533 setverdict(pass);
2534}
2535testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2536 var ConnHdlr vc_conn;
2537 var ConnHdlrPars pars;
2538 f_init();
2539 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2540 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2541 pcu_comp := false, trxc_comp := true);
2542 vc_conn.done;
2543 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2544}
2545
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002546private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002547 timer T := 8.0;
2548 T.start;
2549 var RSL_Message rsl;
2550 alt {
2551 [] as_l1_sacch();
2552 [] L1CTL.receive { repeat; }
2553 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2554 if (rsl.ies[3].body.bs_power.power_level == level) {
2555 setverdict(pass)
2556 } else {
2557 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2558 }
2559 }
2560 [] T.timeout {
2561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2562 }
2563 }
2564}
2565
2566/* see if the rsl meas res contains our expeced bs power level
2567bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002568private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002569 f_l1_tune(L1CTL);
2570 RSL.clear;
2571
2572 if (mp_bts_trxc_port != -1) {
2573 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2574 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2575 }
2576
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002577 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002578 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2579 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2580
2581 f_est_dchan(more_ies :={valueof(pwr)});
2582
2583 f_check_meas_bs_power_level(pwr_var);
2584
2585 f_rsl_chan_deact();
2586 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2587}
2588
2589/* see if the rsl meas res contains our expeced bs power level
2590bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002591private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002592 f_l1_tune(L1CTL);
2593 RSL.clear;
2594
2595 if (mp_bts_trxc_port != -1) {
2596 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2597 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2598 }
2599
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002600 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002601 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2602
2603 f_est_dchan();
2604
2605 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2606
2607 f_check_meas_bs_power_level(pwr_var);
2608
2609 f_rsl_chan_deact();
2610 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2611}
2612
2613testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2614 var ConnHdlr vc_conn;
2615 var ConnHdlrPars pars;
2616 f_init();
2617 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2618 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2619 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2620 pcu_comp := false, trxc_comp := true);
2621 vc_conn.done;
2622 }
2623 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2624}
2625
2626testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2627 var ConnHdlr vc_conn;
2628 var ConnHdlrPars pars;
2629 f_init();
2630 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2631 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2632 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2633 pcu_comp := false, trxc_comp := true);
2634 vc_conn.done;
2635 }
2636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2637}
2638
Eric Wild61edb7e2019-06-03 12:38:31 +02002639/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2640second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2641These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002642private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002643 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002644 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002645
2646 f_trxc_fake_rssi(rxlev2dbm(10));
2647 f_l1_tune(L1CTL);
2648 RSL.clear;
2649
2650 var RSL_IE_List addl_ies;
2651 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2652
2653 addl_ies := {
2654 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2655 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2656 };
2657
2658 /* establish with power parameters */
2659 f_est_dchan(more_ies := addl_ies);
2660
2661 /* set a high value to ensure L1 power control level increases */
2662 f_trxc_fake_rssi(rxlev2dbm(20));
2663
2664 timer T2 := 6.0;
2665 T2.start;
2666 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002667 [] as_l1_sacch_l1h(l1h) {
2668 if (l1h.ms_power_lvl < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002669 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002670 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002671 T2.stop;
2672 }
2673 [] L1CTL.receive { repeat; }
2674 [] T2.timeout {
2675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2676 "Power Level in L1 header has not increased sufficiently");
2677 }
2678 }
2679
2680 /* set a low value to ensure L1 power control level decreases */
2681 f_trxc_fake_rssi(rxlev2dbm(0));
2682
2683 timer T4 := 6.0;
2684 T4.start;
2685 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002686 [] as_l1_sacch_l1h(l1h) {
2687 if (l1h.ms_power_lvl > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002688 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002689 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002690 T4.stop;
2691 setverdict(pass, "Power level in L1 decreased/increased as expected");
2692 }
2693 [] L1CTL.receive { repeat; }
2694 [] T4.timeout {
2695 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2696 "Power Level in L1 header has not decreased sufficiently");
2697 }
2698 }
2699
2700 f_rsl_chan_deact();
2701 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2702
2703}
2704
2705/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002706private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002707 var uint5_t pwr_var := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002708 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002709
2710 /* set a low value to ensure power increases */
2711 f_trxc_fake_rssi(rxlev2dbm(10));
2712 f_l1_tune(L1CTL);
2713 RSL.clear;
2714
2715 var RSL_IE_List addl_ies;
2716 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2717
2718 addl_ies := {
2719 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2720 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2721 };
2722
2723 /* establish with power parameters */
2724 f_est_dchan(more_ies := addl_ies);
2725
2726 timer T1 := 10.0;
2727 T1.start;
2728 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002729 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002730 [] L1CTL.receive { repeat; }
2731 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002732 if (not isbound(l1h)) {
2733 setverdict(fail, "No SACCH blocks were received");
2734 } else if (l1h.ms_power_lvl != pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002735 setverdict(fail, "Power level in L1 header should not have changed");
2736 }
2737 }
2738 }
2739
2740 f_rsl_chan_deact();
2741 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2742
2743}
2744
2745/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002746private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002747 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002748 var uint5_t pwr_var := 15;
2749 var uint5_t pwr_max_var := f_get_max_power_from_band();
2750
2751 /* set a low value to ensure power increases */
2752 f_trxc_fake_rssi(rxlev2dbm(10));
2753 f_l1_tune(L1CTL);
2754 RSL.clear;
2755
2756 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2757 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2758
2759 /* establish with fixed power level */
2760 f_est_dchan(more_ies :={valueof(pwr)});
2761
2762 /* check our initial power level */
2763 f_wait_for_l1_power_level(pwr_var);
2764
2765 /* update power param to enable power loop
2766 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2767 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2768
2769 /* wait, then check that our power level was reduced */
2770 timer T1 := 10.0;
2771 T1.start;
2772 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002773 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002774 [] L1CTL.receive { repeat; }
2775 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002776 if (not isbound(l1h)) {
2777 setverdict(fail, "No SACCH blocks were received");
2778 } else if (f_power_level_is_highest_dbm(l1h.ms_power_lvl)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002779 setverdict(pass, "Power level in L1 header reduced as expected");
2780 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002781 setverdict(fail, "Power level := ", l1h.ms_power_lvl, " did not ",
2782 "reach the expected value := ", pwr_max_var);
Eric Wild61edb7e2019-06-03 12:38:31 +02002783 }
2784 }
2785 }
2786
2787 f_rsl_chan_deact();
2788 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2789
2790}
2791
2792/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002793private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002794 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002795
2796 /* set a high value to ensure power decreases */
2797 f_trxc_fake_rssi(rxlev2dbm(50));
2798 f_l1_tune(L1CTL);
2799 RSL.clear;
2800
2801 var uint5_t pwr_var := 5;
2802 var uint5_t pwr_target_val := 15;
2803
2804 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2805 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2806
2807 /* establish with fixed power level */
2808 f_est_dchan(more_ies :={valueof(pwr)});
2809
2810 /* check our initial power level */
2811 f_wait_for_l1_power_level(pwr_var);
2812
2813 /* update power param to enable power loop
2814 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002815 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002816
2817 /* wait, then check that our power level was increased */
2818 timer T1 := 10.0;
2819 T1.start;
2820 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002821 [] as_l1_sacch_l1h(l1h) { repeat; }
Eric Wild61edb7e2019-06-03 12:38:31 +02002822 [] L1CTL.receive { repeat; }
2823 [] T1.timeout {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002824 if (not isbound(l1h)) {
2825 setverdict(fail, "No SACCH blocks were received");
2826 } else if (f_power_level_is_lowest_dbm(l1h.ms_power_lvl)) {
2827 setverdict(pass, "Power level increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002828 } else {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002829 setverdict(fail, "Power level NOT increased to lowest power value");
Eric Wild61edb7e2019-06-03 12:38:31 +02002830 }
2831 }
2832 }
2833
2834 f_rsl_chan_deact();
2835 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2836
2837}
2838
Eric Wild095024b2019-06-17 15:08:57 +02002839/* see if we change the power level without receiving power parameters, which should not happen
2840rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002841private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002842 var SacchL1Header l1h;
Eric Wild280ccb82019-06-17 11:11:52 +02002843
2844 /* set a high value to ensure power decreases */
2845 f_trxc_fake_rssi(rxlev2dbm(50));
2846 f_l1_tune(L1CTL);
2847 RSL.clear;
2848
2849 var uint5_t pwr_var := 5;
2850
2851 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2852 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2853
2854 /* establish with fixed power level */
2855 f_est_dchan(more_ies :={valueof(pwr)});
2856
2857 /* check our initial power level */
2858 f_wait_for_l1_power_level(pwr_var);
2859
2860 /* wait, then check that our power level did not change */
2861 timer T1 := 10.0;
2862 T1.start;
2863 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002864 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2865 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild280ccb82019-06-17 11:11:52 +02002866 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2867 "BS power control should not be active unless we receive a power parameters IE!");
2868 }
2869 repeat;
2870 }
2871 [] L1CTL.receive { repeat; }
2872 [] T1.timeout { setverdict(pass); }
2873 }
2874
2875 f_rsl_chan_deact();
2876 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2877
2878}
2879
Eric Wild095024b2019-06-17 15:08:57 +02002880/* see if we change the power level without receiving power parameters, which should not happen
2881ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002882private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002883 var SacchL1Header l1h;
Eric Wild095024b2019-06-17 15:08:57 +02002884
2885 /* set a high value to ensure power decreases */
2886 f_trxc_fake_rssi(rxlev2dbm(50));
2887 f_l1_tune(L1CTL);
2888 RSL.clear;
2889
2890 var uint5_t pwr_var := 5;
2891
2892 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2893 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2894
2895 /* establish with fixed power level */
2896 f_est_dchan(more_ies :={valueof(pwr)});
2897
2898 /* check our initial power level */
2899 f_wait_for_l1_power_level(pwr_var);
2900
2901 /* pwr control without power params IE, should NOT activate MS power control*/
2902 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2903
2904 /* wait, then check that our power level did not change */
2905 timer T1 := 10.0;
2906 T1.start;
2907 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002908 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2909 if (l1h.ms_power_lvl != pwr_var) {
Eric Wild095024b2019-06-17 15:08:57 +02002910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2911 "BS power control should not be active unless we receive a power parameters IE!");
2912 }
2913 repeat;
2914 }
2915 [] L1CTL.receive { repeat; }
2916 [] T1.timeout { setverdict(pass); }
2917 }
2918
2919 f_rsl_chan_deact();
2920 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2921
2922}
2923
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002924private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002925 var SacchL1Header l1h;
Eric Wild61edb7e2019-06-03 12:38:31 +02002926 timer T0 := 10.0;
2927 T0.start;
2928 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07002929 [] as_l1_sacch_l1h(l1h, do_apply := false) {
2930 if (l1h.ms_power_lvl != level) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002931 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2932 "Power level in L1 header != signaled (RSL) power level.");
2933 }
2934 }
2935 [] L1CTL.receive { repeat; }
2936 [] T0.timeout {
2937 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2938 "Timeout waiting for initial power level");
2939 }
2940 }
2941 T0.stop;
2942}
2943
2944private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2945 var IntegerRecord min_dbm_level;
2946 var IntegerRecord max_dbm_level;
2947 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2948
2949 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2950 if (min_dbm_level[i] == level) {
2951 return true;
2952 }
2953 }
2954 return false;
2955}
2956
2957private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2958 var IntegerRecord min_dbm_level;
2959 var IntegerRecord max_dbm_level;
2960 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2961
2962 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2963 if (max_dbm_level[i] == level) {
2964 return true;
2965 }
2966 }
2967 return false;
2968}
2969
2970private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2971 var IntegerRecord min_dbm_level;
2972 var IntegerRecord max_dbm_level;
2973 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2974 return max_dbm_level[0];
2975}
2976
2977type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002978private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002979private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2980 // 45.005 4.1.1
2981 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2982 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2983 2, 1, 0};
2984 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2985 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2986 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2987 var IntegerRecord rv;
2988
2989 select(band){
2990 case (BtsBand_allGSM){
2991 rv := gsm_power;
2992 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2993 max_dbm_level := {2, 1, 0};
2994 }
2995 case("DCS1800"){
2996 rv := dcs_power;
2997 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2998 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2999 }
3000 case("PCS1900"){
3001 rv := pcs_power;
3002 min_dbm_level := {15};
3003 max_dbm_level := {30};
3004 }
Harald Welte194b6912020-10-11 21:01:55 +02003005 case else {
3006 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
3007 }
Eric Wild61edb7e2019-06-03 12:38:31 +02003008 }
3009
3010 return rv;
3011}
3012
3013private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02003014 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 +02003015}
3016
3017testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
3018 var ConnHdlr vc_conn;
3019 var ConnHdlrPars pars;
3020 f_init();
3021 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3022 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3023 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3024 pars.bts0_band := f_vty_get_bts0_band();
3025 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
3026 vc_conn.done;
3027 }
3028 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3030}
3031
3032testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
3033 var ConnHdlr vc_conn;
3034 var ConnHdlrPars pars;
3035 f_init();
3036 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3037 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3038 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3039 pars.bts0_band := f_vty_get_bts0_band();
3040 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
3041 vc_conn.done;
3042 }
3043 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3044 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3045}
3046
3047testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
3048 var ConnHdlr vc_conn;
3049 var ConnHdlrPars pars;
3050 f_init();
3051 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
3052 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3053 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3054 pars.bts0_band := f_vty_get_bts0_band();
3055 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
3056 vc_conn.done;
3057 }
3058 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3059 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3060}
3061
3062testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
3063 var ConnHdlr vc_conn;
3064 var ConnHdlrPars pars;
3065 f_init();
3066 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3067 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3068 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3069 pars.bts0_band := f_vty_get_bts0_band();
3070 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
3071 vc_conn.done;
3072 }
3073 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3074 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3075}
3076
Eric Wild280ccb82019-06-17 11:11:52 +02003077testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
3078 var ConnHdlr vc_conn;
3079 var ConnHdlrPars pars;
3080 f_init();
3081 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3082 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3083 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3084 pars.bts0_band := f_vty_get_bts0_band();
3085 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
3086 vc_conn.done;
3087 }
3088 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3090}
3091
Eric Wild095024b2019-06-17 15:08:57 +02003092testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
3093 var ConnHdlr vc_conn;
3094 var ConnHdlrPars pars;
3095 f_init();
3096 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
3097 for (var integer tn := 1; tn <= 1; tn := tn+1) {
3098 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3099 pars.bts0_band := f_vty_get_bts0_band();
3100 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
3101 vc_conn.done;
3102 }
3103 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
3104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3105}
3106
Philipp Maier149c3922020-10-22 17:29:36 +02003107function f_TC_meas_res_speech_tchf(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003108 var template RSL_IE_ChannelMode ch_mode;
3109 var ConnHdlr vc_conn;
3110 var ConnHdlrPars pars;
3111 f_init();
3112 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1);
3113 for (var integer tn := 1; tn <= 1; tn := tn + 1) {
3114 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003115 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003116 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3117 pcu_comp := false, trxc_comp := true);
3118 vc_conn.done;
3119 }
3120 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3121}
Philipp Maier149c3922020-10-22 17:29:36 +02003122
3123testcase TC_meas_res_speech_tchf() runs on test_CT {
3124 f_TC_meas_res_speech_tchf(false);
3125}
3126
3127testcase TC_meas_res_speech_tchf_facch() runs on test_CT {
3128 f_TC_meas_res_speech_tchf(true);
3129}
3130
3131function f_TC_meas_res_speech_tchh(boolean facch_enabled) runs on test_CT {
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003132 var template RSL_IE_ChannelMode ch_mode;
3133 var ConnHdlr vc_conn;
3134 var ConnHdlrPars pars;
3135 f_init();
3136 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3137 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3138 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
Philipp Maier149c3922020-10-22 17:29:36 +02003139 pars.l1_pars.facch_enabled := facch_enabled;
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003140 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3141 pcu_comp := false, trxc_comp := true);
3142 vc_conn.done;
3143 }
3144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3145}
Philipp Maier149c3922020-10-22 17:29:36 +02003146
3147testcase TC_meas_res_speech_tchh() runs on test_CT {
3148 f_TC_meas_res_speech_tchh(false)
3149}
3150
3151testcase TC_meas_res_speech_tchh_facch() runs on test_CT {
3152 f_TC_meas_res_speech_tchh(true)
3153}
3154
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07003155testcase TC_meas_res_speech_tchh_toa256() runs on test_CT {
3156 var template RSL_IE_ChannelMode ch_mode;
3157 var ConnHdlr vc_conn;
3158 var ConnHdlrPars pars;
3159 f_init();
3160 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3161 ch_mode := ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1);
3162 for (var integer ss := 0; ss <= 1; ss := ss + 1) {
3163 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ch_mode));
3164 pars.l1_pars.toa256_enabled := true;
3165 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3166 pcu_comp := false, trxc_comp := true);
3167 vc_conn.done;
3168 }
3169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3170}
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07003171
Harald Welte70767382018-02-21 12:16:40 +01003172testcase TC_meas_res_sign_tchf() runs on test_CT {
3173 var ConnHdlr vc_conn;
3174 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003175 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003176 for (var integer tn := 1; tn <= 4; tn := tn+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003177 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_F)));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003178 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3179 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003180 vc_conn.done;
3181 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003183}
3184testcase TC_meas_res_sign_tchh() runs on test_CT {
3185 var ConnHdlr vc_conn;
3186 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003187 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003188 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003189 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Eric Wild5b9ef142019-07-11 19:28:02 +02003190 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3191 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003192 vc_conn.done;
3193 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003194 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003195}
3196testcase TC_meas_res_sign_sdcch4() runs on test_CT {
3197 var ConnHdlr vc_conn;
3198 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003199 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003200 for (var integer ss := 0; ss <= 3; ss := ss+1) {
3201 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003202 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3203 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003204 vc_conn.done;
3205 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003207}
3208testcase TC_meas_res_sign_sdcch8() runs on test_CT {
3209 var ConnHdlr vc_conn;
3210 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003211 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003212 for (var integer ss := 0; ss <= 7; ss := ss+1) {
3213 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02003214 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3215 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01003216 vc_conn.done;
3217 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01003219}
Harald Welte685d5982018-02-27 20:42:05 +01003220testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
3221 var ConnHdlr vc_conn;
3222 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003223 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01003224 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3225 for (var integer ss := 0; ss <= 1; ss := ss+1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07003226 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN(RSL_CHRT_TCH_H)));
Harald Welte685d5982018-02-27 20:42:05 +01003227 pars.l1_pars.toa256_enabled := true;
Vadim Yanitskiy0b652192020-10-20 02:39:02 +07003228 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
3229 pcu_comp := false, trxc_comp := true);
Harald Welte685d5982018-02-27 20:42:05 +01003230 vc_conn.done;
3231 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003232 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003233}
3234
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003235/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3236 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003237private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003238 var SacchL1Header l1h;
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003239 var RSL_IE_MS_Power ms_power;
3240 var RSL_Message rsl;
3241 var uint5_t power_level := 0;
3242
3243 f_l1_tune(L1CTL);
3244 RSL.clear;
3245
3246 f_est_dchan();
3247
3248 ms_power.reserved := 0;
3249 ms_power.fpc_epc := false;
3250
3251 /* Send the first power control command. This will disable any BTS/TRX
3252 * internal power control and switch the MS (which is not in scope of
3253 * this test) to a constant power level. We start with a power level
3254 * of 0 */
3255 ms_power.power_level := power_level;
3256 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3257 RSL.send(rsl);
3258
3259 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003260 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3261 if (l1h.ms_power_lvl != power_level) {
3262 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3263 "match the signaled (RSL) power level := ", power_level);
3264 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003265 }
3266
3267 /* Signal a new power level via RSL for the next turn. */
3268 if (power_level < 31) {
3269 power_level := power_level + 1;
3270 ms_power.power_level := power_level;
3271 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3272 RSL.send(rsl);
3273 repeat;
3274 }
3275
3276 }
3277
3278 /* Ignore all other blocks */
3279 [] L1CTL.receive { repeat; }
3280
3281 }
3282
3283 f_rsl_chan_deact();
3284 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3285
3286 setverdict(pass);
3287}
3288
3289testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3290 var ConnHdlr vc_conn;
3291 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003292 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003293
3294 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3295 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3296 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3297 vc_conn.done;
3298 }
3299 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3300}
Harald Welte70767382018-02-21 12:16:40 +01003301
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003302/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003303TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003304private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003305 var uint5_t ta_to_test := 16;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003306 var SacchL1Header l1h;
Eric Wild6833cc92019-05-23 19:34:44 +02003307
3308 f_l1_tune(L1CTL);
3309 RSL.clear;
3310
3311 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003312 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003313
3314 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3315
3316
3317 alt {
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003318 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3319 if (l1h.actual_ta != ta_to_test) {
Eric Wild6833cc92019-05-23 19:34:44 +02003320 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3321 }
3322
3323 }
3324
3325 /* Ignore all other blocks */
3326 [] L1CTL.receive { repeat; }
3327
3328 }
3329
3330 f_rsl_chan_deact();
3331 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3332
3333 setverdict(pass);
3334}
3335
3336testcase TC_rsl_chan_initial_ta() runs on test_CT {
3337 var ConnHdlr vc_conn;
3338 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003339 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003340 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003341 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3342 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003343 vc_conn.done;
3344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3345}
3346
Eric Wilde57e1a62019-05-28 13:30:55 +02003347/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003348private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003349 var uint5_t ms_power_level := 7;
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003350 var SacchL1Header l1h;
Eric Wilde57e1a62019-05-28 13:30:55 +02003351
3352 var RSL_IE_MS_Power ms_power;
3353 ms_power.reserved := 0;
3354 ms_power.fpc_epc := false;
3355 ms_power.power_level := ms_power_level;
3356
3357 f_l1_tune(L1CTL);
3358 RSL.clear;
3359
3360 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3361
3362 timer T := 1.0;
3363 T.start;
3364 alt {
3365 /* Pick all SACCH blocks for checking */
Vadim Yanitskiyab5769c2020-11-11 07:02:28 +07003366 [] as_l1_sacch_l1h(l1h, do_apply := false) {
3367 if (l1h.ms_power_lvl != ms_power_level) {
3368 setverdict(fail, "Power level := ", l1h.ms_power_lvl, "does not ",
3369 "match the signaled (RSL) power level := ", ms_power_level);
Eric Wilde57e1a62019-05-28 13:30:55 +02003370 }
3371 }
3372 /* Ignore all other blocks */
3373 [] L1CTL.receive { repeat; }
3374 [] T.timeout {
3375 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3376 }
3377 }
3378
3379 f_rsl_chan_deact();
3380 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3381 setverdict(pass);
3382}
3383
3384testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3385 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3386 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3387}
3388
Harald Welte0472ab42018-03-12 15:02:26 +01003389/* 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 +01003390private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003391 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003392 RSL.clear;
3393
3394 f_est_dchan();
3395 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003396 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003397
3398 timer T := 40.0;
3399 T.start;
3400 alt {
3401 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3402 setverdict(pass)
3403 }
3404 [] RSL.receive { repeat };
3405 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003407 }
3408 }
3409 f_rsl_chan_deact();
3410}
3411testcase TC_conn_fail_crit() runs on test_CT {
3412 var ConnHdlr vc_conn;
3413 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003414 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003415 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3416 pars.t_guard := 60.0;
3417 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3418 vc_conn.done;
3419}
3420
Harald Welte93640c62018-02-25 16:59:33 +01003421/***********************************************************************
3422 * Paging
3423 ***********************************************************************/
3424
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003425private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003426 if (tmsi == 'FFFFFFFF'O) {
3427 return true;
3428 } else {
3429 return false;
3430 }
3431}
Harald Welte70767382018-02-21 12:16:40 +01003432
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003433private type record allowedFn { integer frame_nr }
3434private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3435private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3436private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3437private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3438private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3439private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3440private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3441private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3442private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003443{
3444 var integer frame_nr_51;
3445 frame_nr_51 := frame_nr mod 51
3446
3447 var allowedFn fn_check;
3448 fn_check.frame_nr := frame_nr_51;
3449
3450 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003451 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003452 return;
3453 }
3454
3455 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3456 return;
3457 }
3458 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3459 return;
3460 }
3461 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3462 return;
3463 }
3464 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3465 return;
3466 }
3467 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3468 return;
3469 }
3470 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3471 return;
3472 }
3473 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3474 return;
3475 }
3476 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3477 return;
3478 }
3479
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003481 return;
3482}
3483
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003484private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3485 inout integer num_paging_rcv_ids,
3486 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003487runs on test_CT {
3488 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003489 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003490 repeat;
3491 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003492 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003493 var octetstring without_plen :=
3494 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3495 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003496
3497 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3498
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003499 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3500 /* Ignore empty RR Paging Request (PCH filling) messages.
3501 * TODO: does it make sense to count them? */
3502 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003503 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3504 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003505 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003506 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3507 }
3508 } else if (match(rr, tr_PAGING_REQ2)) {
3509 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3510 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3511 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3512 }
3513 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3514 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3515 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003516 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003517 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3518 }
3519 } else if (match(rr, tr_PAGING_REQ3)) {
3520 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3521 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3522 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3523 }
3524 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3525 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3526 }
3527 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3528 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3529 }
3530 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3531 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3532 }
3533 }
3534 repeat;
3535 }
3536}
3537
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003538private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003539 boolean combined_ccch,
3540 integer bs_ag_blks_res,
3541 float load_factor,
3542 boolean exp_load_ind,
3543 boolean exp_overload,
3544 boolean use_tmsi
3545}
3546
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003547private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003548 integer num_paging_sent,
3549 integer num_paging_rcv_msgs,
3550 integer num_paging_rcv_ids,
3551 integer num_overload
3552}
3553
Harald Welte68e495b2018-02-25 00:05:57 +01003554/* Helper function for paging related testing */
3555private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003556 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003557 f_init_l1ctl();
3558 f_l1_tune(L1CTL);
3559
3560 var PagingTestState st := {
3561 num_paging_sent := 0,
3562 num_paging_rcv_msgs := 0,
3563 num_paging_rcv_ids := 0,
3564 num_overload := 0
3565 };
3566
3567 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3568 var float max_pch_imsi_per_sec;
3569 if (cfg.use_tmsi) {
3570 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3571 } else {
3572 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3573 }
3574 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3575 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003576 var float time_total := 20.0;
3577 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3578 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003579
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003580 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3581 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003582
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003583 timer T_itv := 0.0;
3584 T_itv.start;
3585 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003586 alt {
3587 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003588 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003589 st.num_overload := st.num_overload + 1;
3590 repeat;
3591 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003592 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003593 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003594 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003595 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003596 log("Rx LOAD_IND");
3597 /* FIXME: analyze/verify interval + contents */
3598 repeat;
3599 }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003600 /* ignore other RSL messages like RF RESource INDication */
3601 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003602 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003603 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003604 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003605 [] T_itv.timeout {
3606 /* Send paging cmds based on elapsed time */
3607 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3608 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003609 var MobileIdentityV mi;
3610
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003611 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003612 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003613 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003614 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003615 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003616 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003617
3618 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003619 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 +02003620
3621 st.num_paging_sent := st.num_paging_sent + 1;
3622 }
3623 if (st.num_paging_sent < pkt_total) {
3624 /* Wait for interval to next PAGING COMMAND */
3625 var float time_now := T_total.read;
3626 var float next_sched := int2float(st.num_paging_sent)*interval;
3627 if (next_sched > time_now) {
3628 T_itv.start(next_sched - time_now);
3629 } else {
3630 T_itv.start(0.0);
3631 }
3632 } else {
3633 /* We are done, no need to keep counting */
3634 T_total.stop;
3635 }
3636 }
3637 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003638 }
3639 }
3640
3641 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3642 timer T_wait := 18.0;
3643 T_wait.start;
3644 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003645 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003646 [] L1CTL.receive { repeat; }
3647 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003648 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3649 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Vadim Yanitskiy2372db62021-06-09 00:50:11 +02003650 /* ignore other RSL messages like RF RESource INDication */
3651 [] RSL_CCHAN.receive { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003652 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003654 }
Harald Welte68e495b2018-02-25 00:05:57 +01003655 }
3656
3657 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3658 " rcvd_ids=", st.num_paging_rcv_ids);
3659 return st;
3660}
3661
3662/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3663 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3664 * - that CCCH LOAD IND (PCH) are being generated
3665 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3666testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003667 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003668 var PagingTestCfg cfg := {
3669 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003670 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003671 load_factor := 0.8,
3672 exp_load_ind := true,
3673 exp_overload := false,
3674 use_tmsi := false
3675 };
3676 var PagingTestState st := f_TC_paging(cfg);
3677 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003678 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3679 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003680 } else {
3681 setverdict(pass);
3682 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003684}
3685
3686/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3687 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3688 * - that CCCH LOAD IND (PCH) are being generated
3689 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3690testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003691 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003692 var PagingTestCfg cfg := {
3693 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003694 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003695 load_factor := 0.8,
3696 exp_load_ind := true,
3697 exp_overload := false,
3698 use_tmsi := true
3699 };
3700 var PagingTestState st := f_TC_paging(cfg);
3701 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3703 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003704 } else {
3705 setverdict(pass);
3706 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003708}
3709
3710/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3711 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3712 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3713 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3714testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003715 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003716 var PagingTestCfg cfg := {
3717 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003718 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003719 load_factor := 2.0,
3720 exp_load_ind := true,
3721 exp_overload := true,
3722 use_tmsi := false
3723 };
3724 var PagingTestState st := f_TC_paging(cfg);
3725 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3726 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003727 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003728 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003729 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 +01003730 } else {
3731 setverdict(pass);
3732 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003733 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003734}
3735
3736/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3737 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3738 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3739 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3740testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003741 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003742 var PagingTestCfg cfg := {
3743 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003744 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003745 load_factor := 2.0,
3746 exp_load_ind := true,
3747 exp_overload := true,
3748 use_tmsi := true
3749 };
3750 var PagingTestState st := f_TC_paging(cfg);
3751 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3752 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003753 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003754 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003755 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 +01003756 } else {
3757 setverdict(pass);
3758 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003759 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003760}
3761
3762
Harald Welte93640c62018-02-25 16:59:33 +01003763/***********************************************************************
3764 * Immediate Assignment / AGCH
3765 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003766private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003767 len := 0,
3768 ma := ''B
3769}
Harald Welte93640c62018-02-25 16:59:33 +01003770
Harald Weltee8d750e2018-06-10 21:41:35 +02003771private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3772 return int2str(num_tx) & " sent, "
3773 & int2str(num_rx) & " received, "
3774 & int2str(num_del) & " deleted";
3775}
3776
3777private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3778 var L1ctlDlMessage l1_dl;
3779 timer T := 10.0;
3780 var integer num_tx := 0;
3781 var integer num_rx := 0;
3782 var integer num_del := 0;
3783 var charstring res_str;
3784 var float rx_ratio;
3785
Harald Welte10474062019-05-30 16:48:17 +02003786 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003787 f_init_l1ctl();
3788 f_l1_tune(L1CTL);
3789
3790 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07003791 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07003792 mp_trx_pars[0].arfcn,
3793 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02003794 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3795 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003796 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003797 num_tx := num_tx+1;
3798 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003799 }
3800 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003801 T.start;
3802 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003803 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003804 num_del := num_del+1;
3805 repeat;
3806 }
3807 [] RSL_CCHAN.receive {
3808 repeat;
3809 }
3810 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003811 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3812 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3813 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003814 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003815 } else {
3816 num_rx := num_rx+1;
3817 }
3818 repeat;
3819 }
3820 [] L1CTL.receive { repeat; }
3821 [] T.timeout { }
3822 }
3823 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3824 log("AGCH test: " & res_str);
3825 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003827 }
3828 rx_ratio := int2float(num_rx) / int2float(num_tx);
3829 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003830 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 +02003831 } else {
3832 setverdict(pass);
3833 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003834 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003835}
3836
Harald Weltee8d750e2018-06-10 21:41:35 +02003837/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3838testcase TC_imm_ass_1000_20ms() runs on test_CT {
3839 f_TC_imm_ass(1000, 0.02, 0.25);
3840}
3841
3842/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3843testcase TC_imm_ass_200_0ms() runs on test_CT {
3844 f_TC_imm_ass(200, 0.0, 0.05);
3845}
3846
3847/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3848testcase TC_imm_ass_200_76ms() runs on test_CT {
3849 f_TC_imm_ass(150, 0.076, 1.00);
3850}
3851
3852
3853
Harald Welte48494ca2018-02-25 16:59:50 +01003854/***********************************************************************
3855 * BCCH
3856 ***********************************************************************/
3857
3858/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003859private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003860 GsmFrameNumber frame_number,
3861 SystemInformation si
3862}
3863
3864/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003865private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003866
3867/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003868private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003869
3870/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003871private function f_si_vecslot_contains(SystemInformationVector arr,
3872 RrMessageType key,
3873 boolean bcch_ext := false)
3874return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003875 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3876 var integer fn_mod51 := arr[i].frame_number mod 51;
3877 if (not bcch_ext and fn_mod51 == 2 or
3878 bcch_ext and fn_mod51 == 6) {
3879 if (arr[i].si.header.message_type == key) {
3880 return true;
3881 }
3882 }
3883 }
3884 return false;
3885}
3886
3887/* 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 +07003888private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3889 integer tc, RrMessageType key,
3890 boolean ext_bcch := false)
3891{
Harald Welte48494ca2018-02-25 16:59:50 +01003892 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003894 }
3895}
3896
3897/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003898private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3899 RrMessageType key)
3900return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003901 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3902 if (f_si_vecslot_contains(arr[tc], key) or
3903 f_si_vecslot_contains(arr[tc], key, true)) {
3904 return true;
3905 }
3906 }
3907 return false;
3908}
3909
3910/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003911private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3912 RrMessageType key,
3913 boolean bcch_ext := false,
3914 integer n := 1, integer m := 4)
3915return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003916 var integer count := 0;
3917 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3919 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003920 }
3921 for (var integer i:= 0; i < m; i := i + 1) {
3922 var integer fn_mod51 := arr[i].frame_number mod 51;
3923 if (not bcch_ext and fn_mod51 == 2 or
3924 bcch_ext and fn_mod51 == 6) {
3925 if (arr[i].si.header.message_type == key) {
3926 count := count + 1;
3927 }
3928 }
3929 }
3930 if (count >= n) {
3931 return true;
3932 } else {
3933 return false;
3934 }
3935}
3936
3937/* 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 +07003938private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3939 integer tc, RrMessageType key,
3940 boolean ext_bcch := false,
3941 integer n, integer m)
3942{
Harald Welte48494ca2018-02-25 16:59:50 +01003943 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003945 }
3946}
3947
3948/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003949private function f_si_vecslot_contains_only(SystemInformationVector arr,
3950 RrMessageType key,
3951 boolean bcch_ext := false)
3952return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003953 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3954 var integer fn_mod51 := arr[i].frame_number mod 51;
3955 if (not bcch_ext and fn_mod51 == 2 or
3956 bcch_ext and fn_mod51 == 6) {
3957 if (arr[i].si.header.message_type != key) {
3958 return false;
3959 }
3960 }
3961 }
3962 return true;
3963}
3964
3965/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003966private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3967 integer tc, RrMessageType key,
3968 boolean ext_bcch := false)
3969{
Harald Welte48494ca2018-02-25 16:59:50 +01003970 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003971 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003972 }
3973}
3974
3975/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003976private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003977 boolean bcch_extended,
3978 boolean si1_present,
3979 boolean si2bis_present,
3980 boolean si2ter_present,
3981 boolean si2quater_present,
3982 boolean si7_present,
3983 boolean si8_present,
3984 boolean si9_present,
3985 boolean si13_present,
3986 boolean si13alt_present,
3987 boolean si15_present,
3988 boolean si16_present,
3989 boolean si17_present,
3990 boolean si2n_present,
3991 boolean si21_present,
3992 boolean si22_present
3993}
3994
3995/* 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 +07003996private function f_validate_si_scheduling(SystemInformationConfig cfg,
3997 SystemInformationVectorPerTc si_per_tc)
3998{
Harald Welte48494ca2018-02-25 16:59:50 +01003999 var integer i;
4000 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
4001 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01004003 }
4004 }
4005 if (cfg.si1_present) {
4006 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4007 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4008 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4009 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4010 /* make sure *ALL* contain SI1 */
4011 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4012 }
4013 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4014 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4015 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4016 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4017 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4018 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4019
4020 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4021 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4022 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4023 * consecutive occurrences of TC = 4. */
4024 if (cfg.si2bis_present and not cfg.si2ter_present) {
4025 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4026 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4027 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4028 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4029 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4030 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4031 }
4032
4033 if (cfg.si7_present or cfg.si8_present) {
4034 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4035 * if System Information type 4 does not contain all information needed for cell
4036 * selection and reselection. */
4037 if (not cfg.bcch_extended) {
4038 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4039 }
4040 if (cfg.si7_present) {
4041 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4042 }
4043 if (cfg.si8_present) {
4044 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4045 }
4046 }
4047
4048 if (cfg.si2quater_present) {
4049 /* iii) System information type 2 quater is sent if needed, as determined by the system
4050 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4051 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4052 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4053 * within any of 4 consecutive occurrences of TC = 5. */
4054 if (not (cfg.bcch_extended)) {
4055 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4056 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4057 } else {
4058 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4059 }
4060 } else {
4061 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4062 }
4063 }
4064 if (cfg.si9_present) {
4065 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4066 * in system information type 3 as defined in 3GPP TS 44.018. */
4067 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4068 }
4069 if (cfg.si13_present) {
4070 /* vii) System Information type 13 is only related to the GPRS service. System Information
4071 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4072 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4073 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4074 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4075 * within any of 4 consecutive occurrences of TC=4. */
4076 if (not cfg.bcch_extended) {
4077 log("not-bccch-extended");
4078 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4079 } else {
4080 log("bccch-extended");
4081 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4082 }
4083 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004085 }
4086 }
4087 if (cfg.si16_present or cfg.si17_present) {
4088 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4089 * should not be sent in a cell where network sharing is used (see rule xv). */
4090 if (cfg.si22_present) {
4091 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4092 }
4093 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004094 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004095 }
4096 if (not cfg.bcch_extended) {
4097 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4098 }
4099 if (cfg.si16_present) {
4100 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4101 }
4102 if (cfg.si17_present) {
4103 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4104 }
4105 }
4106
4107 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4108 * broadcast information. The frequency with which they are sent is determined by the
4109 * system operator. System Information type 9 identifies the scheduling of System
4110 * Information type 18 and 20 messages. */
4111
4112 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4113 * Information Type 19 is present, then its scheduling shall be indicated in System
4114 * Information Type 9. */
4115
4116 if (cfg.si15_present) {
4117 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4118 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4119 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4120 * 4 consecutive occurrences of TC = 1. */
4121 if (not cfg.bcch_extended) {
4122 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4123 } else {
4124 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4125 }
4126 }
4127 if (cfg.si13alt_present) {
4128 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4129 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4130 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4131 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4132 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4133 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4134 * of TC = 4. */
4135 if (cfg.si13_present) {
4136 testcase.stop("Error: Cannot have SI13alt and SI13");
4137 }
4138 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004139 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004140 }
4141 if (not cfg.bcch_extended) {
4142 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4143 } else {
4144 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4145 }
4146 }
4147 if (cfg.si2n_present) {
4148 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4149 * as determined by the system operator. In the case that the message is sent on the
4150 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4151 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4152 * consecutive occurrences of TC = 4. */
4153 if (not cfg.bcch_extended) {
4154 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4155 } else {
4156 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4157 }
4158 }
4159 if (cfg.si21_present) {
4160 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4161 * determined by the system operator. If Extended Access Barring is in use in the cell
4162 * then this message is sent at least once within any of 4 consecutive occurrences of
4163 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4164 * cell then this message shall only be sent on BCCH Ext. */
4165 if (not cfg.bcch_extended) {
4166 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4167 } else {
4168 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4169 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004170 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004171 }
4172 }
4173 }
4174 if (cfg.si22_present) {
4175 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4176 * should not be sent in a cell where SoLSA is used (see rule viii). System
4177 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4178 * =2 and TC=6. */
4179 if (cfg.si16_present or cfg.si17_present) {
4180 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4181 }
4182 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4183 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004184 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004185 }
4186 if (not cfg.bcch_extended) {
4187 testcase.stop("Error: SI22 requires BCCH Extd!");
4188 } else {
4189 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4190 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4191 }
4192 }
4193}
4194
4195/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004196private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4197return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004198 timer T := duration;
4199 var SystemInformationVectorPerTc si_per_tc;
4200 var L1ctlDlMessage l1_dl;
4201
4202 /* initialize all per-TC vectors empty */
4203 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4204 si_per_tc[i] := {};
4205 }
4206
4207 /* flush all previous L1 queued msgs */
4208 pt.clear;
4209
4210 T.start;
4211 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004212 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004213 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4214 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4215 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004216 repeat;
4217 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004218
Harald Welte48494ca2018-02-25 16:59:50 +01004219 var integer tc := f_gsm_compute_tc(sig.frame_number);
4220 log("SI received at TC=", tc, ": ", sig.si);
4221 /* append to the per-TC bucket */
4222 si_per_tc[tc] := si_per_tc[tc] & { sig };
4223 repeat;
4224 }
4225 [] pt.receive { repeat; }
4226 [] T.timeout { }
4227 }
4228
4229 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4230 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4231 }
4232 log("si_per_tc=", si_per_tc);
4233 return si_per_tc;
4234}
4235
4236/* helper function: Set given SI via RSL + validate scheduling.
4237 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004238private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004239 var SystemInformationVectorPerTc si_per_tc;
4240 f_init_l1ctl();
4241 f_l1_tune(L1CTL);
4242
4243 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004244 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004245 f_validate_si_scheduling(si_cfg, si_per_tc);
4246
4247 setverdict(pass);
4248}
4249
4250testcase TC_si_sched_default() runs on test_CT {
4251 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004252 /* 2+3+4 are mandatory and set in f_init() */
4253 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004255}
4256
4257testcase TC_si_sched_1() runs on test_CT {
4258 f_init();
4259 si_cfg.si1_present := true;
4260 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004261 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004263}
4264
4265testcase TC_si_sched_2bis() runs on test_CT {
4266 f_init();
4267 si_cfg.si2bis_present := true;
4268 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4269 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004270 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004271}
4272
4273testcase TC_si_sched_2ter() runs on test_CT {
4274 f_init();
4275 si_cfg.si2ter_present := true;
4276 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4277 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004279}
4280
4281testcase TC_si_sched_2ter_2bis() runs on test_CT {
4282 f_init();
4283 si_cfg.si2bis_present := true;
4284 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4285 si_cfg.si2ter_present := true;
4286 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4287 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004288 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004289}
4290
4291testcase TC_si_sched_2quater() runs on test_CT {
4292 f_init();
4293 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004294 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004295 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004297}
4298
4299testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004300 /* NOTE: PCUIF connection is not used in this test case, but
4301 * without it the IUT would not broadcast SI13 (see OS#3075). */
4302 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004303 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004304 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004305 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004306 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004307}
4308
4309testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004310 /* NOTE: PCUIF connection is not used in this test case, but
4311 * without it the IUT would not broadcast SI13 (see OS#3075). */
4312 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004313 si_cfg.si2bis_present := true;
4314 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4315 si_cfg.si2ter_present := true;
4316 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4317 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004318 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004319 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004320 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004321 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004322 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004323}
4324
4325
Harald Welte68e495b2018-02-25 00:05:57 +01004326testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004327 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004328 /* FIXME: enable / disable individual BCCH info */
4329 //ts_RSL_BCCH_INFO(si_type, info);
4330 /* expect no ERROR REPORT after either of them *
4331 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004333}
4334
Harald Welte93640c62018-02-25 16:59:33 +01004335/***********************************************************************
4336 * Low-Level Protocol Errors / ERROR REPORT
4337 ***********************************************************************/
4338
Harald Welte01d982c2018-02-25 01:31:40 +01004339private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4340 timer T := 5.0;
4341 T.start;
4342 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004343 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004344 setverdict(pass);
4345 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004346 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004348 }
4349 [] RSL_CCHAN.receive {
4350 repeat;
4351 }
4352 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004353 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004354 }
4355 }
4356}
4357
4358/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4359testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004360 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004361 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4362 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004363 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004364
4365 f_exp_err_rep(RSL_ERR_PROTO);
4366}
4367
4368/* Provoke a mandatory IE error and match on ERROR REPORT */
4369testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004370 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004371
4372 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4373 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004374 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004375
4376 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4377}
4378
4379/* Provoke an IE content error and match on ERROR REPORT */
4380testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004381 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004382 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4383 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004384 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004385
4386 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4387}
4388
Harald Welteee25aae2019-05-19 14:32:37 +02004389/* attempt to activate channel with wrong RSL Message Discriminator IE */
4390function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4391 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4392 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4393 RSL.send(rsl);
4394 f_rslem_unregister(0, g_chan_nr);
4395}
4396testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4397 var ConnHdlr vc_conn;
4398 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4399
Harald Welte10474062019-05-30 16:48:17 +02004400 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004401
4402 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4403 vc_conn.done;
4404 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4405
4406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4407}
4408
4409/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004410private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004411 var template (value) RSL_Message rsl_tx;
4412 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4413 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4414 RSL.send(rsl_tx);
4415 f_rslem_unregister(0, g_chan_nr);
4416}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004417private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004418 var template (value) RSL_Message rsl_tx;
4419 /* we first have to activate the dedicated channel */
4420 f_rsl_chan_act(g_pars.chan_mode);
4421 /* ... to then send an invalid RLL message */
4422 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4423 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4424 RSL.send(rsl_tx);
4425 f_rslem_unregister(0, g_chan_nr);
4426}
4427testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4428 var ConnHdlr vc_conn;
4429 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4430 var template (value) RSL_Message rsl_tx;
4431
Harald Welte10474062019-05-30 16:48:17 +02004432 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004433
4434 /* Common Channel with wrong message type */
4435 RSL_CCHAN.clear;
4436 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4437 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004438 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004439 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4440
4441 /* TRX Management */
4442 RSL_CCHAN.clear;
4443 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4444 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004445 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004446 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4447
4448 /* Dedicated Channel */
4449 RSL_CCHAN.clear;
4450 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4451 vc_conn.done;
4452 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4453
4454 /* RLL */
4455 RSL_CCHAN.clear;
4456 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4457 vc_conn.done;
4458 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4459}
4460
4461/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004462private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004463 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4464 f_rslem_unregister(0, g_chan_nr);
4465}
4466testcase TC_err_rep_wrong_sequence() runs on test_CT {
4467 var ConnHdlr vc_conn;
4468 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4469
Harald Welte10474062019-05-30 16:48:17 +02004470 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004471
4472 RSL_CCHAN.clear;
4473 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4474 vc_conn.done;
4475 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4476}
4477
Harald Welte93640c62018-02-25 16:59:33 +01004478/***********************************************************************
4479 * IPA CRCX/MDCX/DLCS media stream handling
4480 ***********************************************************************/
4481
Harald Weltea871a382018-02-25 02:03:14 +01004482/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004483private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004484 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4485 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004486}
4487testcase TC_ipa_dlcx_not_active() runs on test_CT {
4488 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004489 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004490 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4491 vc_conn.done;
4492}
Harald Welte68e495b2018-02-25 00:05:57 +01004493
Harald Weltea3f1df92018-02-25 12:49:55 +01004494/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004495private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004496 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4497 "IPA CRCX ACK");
4498 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4499 "IPA CRCX NACK");
4500}
4501testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4502 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004503 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004504 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4505 vc_conn.done;
4506}
4507
4508/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004509private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004510 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4511 "IPA CRCX ACK");
4512 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4513 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4514 var uint7_t rtp_pt2 := f_rnd_int(127);
4515 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4516 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4517 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4518 "IPA MDCX ACK");
4519 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4520 "IPA DLCX ACK");
4521}
4522testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4523 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004524 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004525 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4526 vc_conn.done;
4527}
4528
Harald Welte3ae11da2018-02-25 13:36:06 +01004529/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004530private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004531 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4532 "IPA CRCX ACK");
4533 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4534 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4535 var uint7_t rtp_pt2 := f_rnd_int(127);
4536 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4537 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4538 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4539 "IPA MDCX ACK");
4540 /* Second MDCX */
4541 remote_ip := f_rnd_int(c_UINT32_MAX);
4542 remote_port := f_rnd_int(c_UINT16_MAX);
4543 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4544 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4545 "IPA MDCX ACK");
4546 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4547 "IPA DLCX ACK");
4548}
4549testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4550 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004551 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004552 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4553 vc_conn.done;
4554}
4555
Harald Welte9912eb52018-02-25 13:30:15 +01004556/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004557private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004558 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4559 "IPA CRCX NACK");
4560}
4561testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4562 var ConnHdlrPars pars;
4563 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004564 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004565
4566 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4567 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4568 vc_conn.done;
4569
4570 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4571 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4572 vc_conn.done;
4573}
4574
Harald Weltea3f1df92018-02-25 12:49:55 +01004575
Harald Welte883340c2018-02-28 18:59:29 +01004576/***********************************************************************
4577 * PCU Socket related tests
4578 ***********************************************************************/
4579
Harald Welte07bd2d22019-05-25 11:03:30 +02004580/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004581friend 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 +01004582runs on test_CT {
4583 timer T := 3.0;
4584
4585 /* we don't expect any RTS.req before PDCH are active */
4586 T.start;
4587 alt {
4588 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004589 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004590 }
4591 [] PCU.receive { repeat; }
4592 [] T.timeout { }
4593 }
4594
4595 /* Send PDCH activate request for known PDCH timeslot */
4596 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4597
4598 /* we now expect RTS.req for this timeslot (only) */
4599 T.start;
4600 alt {
4601 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4602 setverdict(pass);
4603 }
4604 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4605 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004607 }
4608 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004609 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004610 }
4611 [] PCU.receive { repeat; }
4612 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004613 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004614 }
4615 [not exp_success] T.timeout {
4616 setverdict(pass);
4617 }
4618 }
4619}
4620
Harald Welte07bd2d22019-05-25 11:03:30 +02004621/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004622friend 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 +01004623runs on test_CT {
4624 timer T := 3.0;
4625
4626 /* Send PDCH activate request for known PDCH timeslot */
4627 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 +02004628 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4629 * when it will actually have been executed in the BTS */
4630 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004631 PCU.clear;
4632 /* we now expect no RTS.req for this timeslot */
4633 T.start;
4634 alt {
4635 [] 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 +02004636 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004637 }
4638 [] PCU.receive { repeat; }
4639 [] T.timeout {
4640 setverdict(pass);
4641 }
4642 }
4643}
4644
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004645friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004646 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004647 map(self:PCU, system:PCU);
4648 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01004649 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4650}
4651
Harald Welte883340c2018-02-28 18:59:29 +01004652/* PDCH activation via PCU socket; check for presence of RTS.req */
4653testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004654 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004655
Harald Welte883340c2018-02-28 18:59:29 +01004656 f_TC_pcu_act_req(0, 0, 7, true);
4657}
4658
4659/* PDCH activation via PCU socket on non-PDCU timeslot */
4660testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004661 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004662
Harald Welte883340c2018-02-28 18:59:29 +01004663 f_TC_pcu_act_req(0, 0, 1, false);
4664}
4665
4666/* PDCH activation via PCU socket on wrong BTS */
4667testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004668 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004669
Harald Welte883340c2018-02-28 18:59:29 +01004670 f_TC_pcu_act_req(23, 0, 7, false);
4671}
4672
4673/* PDCH activation via PCU socket on wrong TRX */
4674testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004675 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004676
Harald Welte883340c2018-02-28 18:59:29 +01004677 f_TC_pcu_act_req(0, 23, 7, false);
4678}
4679
4680/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4681testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004682 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004683
Harald Welte883340c2018-02-28 18:59:29 +01004684 /* Activate PDCH */
4685 f_TC_pcu_act_req(0, 0, 7, true);
4686 f_sleep(1.0);
4687 /* and De-Activate again */
4688 f_TC_pcu_deact_req(0, 0, 7);
4689}
4690
4691/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4692testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004693 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004694
Harald Welte883340c2018-02-28 18:59:29 +01004695 f_TC_pcu_deact_req(0, 0, 1);
4696}
4697
4698/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01004699function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01004700 var PCUIF_send_data sd;
4701 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004702 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01004703
4704 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01004705 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01004706
Harald Welte883340c2018-02-28 18:59:29 +01004707 T.start;
4708 alt {
4709 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
Philipp Maier94c08482021-02-01 17:36:05 +01004710 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01004711 setverdict(pass);
4712 } else {
4713 repeat;
4714 }
4715 }
4716 [] PCU.receive { repeat; }
4717 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01004718 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01004719 }
4720 }
4721}
4722
Philipp Maier94c08482021-02-01 17:36:05 +01004723/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
4724testcase TC_pcu_ver_si1() runs on test_CT {
4725 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
4726 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
4727}
4728
4729/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
4730testcase TC_pcu_ver_si3() runs on test_CT {
4731 const octetstring si3 := '49012223242526272929AABBCC'O;
4732 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
4733}
4734
4735/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4736testcase TC_pcu_ver_si13() runs on test_CT {
4737 const octetstring si13 := '01010203040506070909'O;
4738 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
4739}
4740
Harald Welte883340c2018-02-28 18:59:29 +01004741private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4742
4743/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004744friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004745 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4746runs on test_CT
4747{
4748 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4749 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4750}
4751
4752/* 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 +02004753friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4754 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004755runs on test_CT
4756{
4757 var PCUIF_send_data sd;
4758
4759 timer T := 3.0;
4760 T.start;
4761 alt {
4762 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4763 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4764 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4765 sd.data.u.rts_req.fn, sapi, data);
4766 }
4767 [] PCU.receive { repeat; }
4768 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004770 }
4771 }
4772}
4773
4774/* Send DATA.req on invalid BTS */
4775testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004776 var TfiUsfArr tua := f_TfiUsfArrInit();
4777 var octetstring data := '0000'O & f_rnd_octstring(21);
4778
4779 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004780
Harald Welte883340c2018-02-28 18:59:29 +01004781 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004782 f_TfiUsfArrSet(tua, 7, 0);
4783 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4784 f_sleep(1.0);
4785
4786 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004787}
4788
4789/* Send DATA.req on invalid TRX */
4790testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004791 var TfiUsfArr tua := f_TfiUsfArrInit();
4792 var octetstring data := '0000'O & f_rnd_octstring(21);
4793
4794 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004795
Harald Welte883340c2018-02-28 18:59:29 +01004796 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004797 f_TfiUsfArrSet(tua, 7, 0);
4798 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4799 f_sleep(1.0);
4800
4801 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004802}
4803
4804/* Send DATA.req on invalid timeslot */
4805testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004806 var TfiUsfArr tua := f_TfiUsfArrInit();
4807 var octetstring data := '0000'O & f_rnd_octstring(21);
4808
4809 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004810
Harald Welte883340c2018-02-28 18:59:29 +01004811 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004812 f_TfiUsfArrSet(tua, 7, 0);
4813 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4814 f_sleep(1.0);
4815
4816 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004817}
4818
4819/* Send DATA.req on timeslot that hasn't been activated */
4820testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004821 var TfiUsfArr tua := f_TfiUsfArrInit();
4822 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004823
Harald Welte7162a612019-05-26 12:56:09 +02004824 f_virtphy_common();
4825
4826 f_TfiUsfArrSet(tua, 7, 0);
4827 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4828 f_sleep(1.0);
4829
4830 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004831}
4832
Harald Weltead033dc2019-05-25 17:28:16 +02004833private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004834 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4835 boolean wait_rts := true)
4836runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004837 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004838 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004839
4840 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004841 if (wait_rts) {
4842 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4843 } else {
4844 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4845 }
Harald Weltead033dc2019-05-25 17:28:16 +02004846
4847 T.start;
4848 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004849 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004850 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4851 setverdict(pass);
4852 }
Harald Welte7162a612019-05-26 12:56:09 +02004853 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4854 setverdict(fail, "Received unexpected ", rx_dl);
4855 }
Harald Weltead033dc2019-05-25 17:28:16 +02004856 [] L1CTL.receive {
4857 repeat;
4858 }
Harald Welte7162a612019-05-26 12:56:09 +02004859 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004860 setverdict(fail, "Timeout waiting for ", data);
4861 }
Harald Welte7162a612019-05-26 12:56:09 +02004862 [not expect_data] T.timeout {
4863 setverdict(pass);
4864 }
Harald Weltead033dc2019-05-25 17:28:16 +02004865 }
4866}
4867
4868private function f_disable_dynamic_ts() runs on test_CT
4869{
4870 f_init_vty_bsc();
4871 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4872 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4873 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4874 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004875 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02004876}
4877
4878private function f_virtphy_common() runs on test_CT {
4879 f_disable_dynamic_ts();
4880 f_init_l1ctl();
4881 f_l1_tune(L1CTL);
4882}
4883
4884testcase TC_pcu_data_req_pdtch() runs on test_CT {
4885 var TfiUsfArr tua := f_TfiUsfArrInit();
4886 var octetstring data := '0000'O & f_rnd_octstring(21);
4887
4888 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004889
Harald Welte883340c2018-02-28 18:59:29 +01004890 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004891 f_TfiUsfArrSet(tua, 7, 0);
4892 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4893 f_sleep(1.0);
4894
4895 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004896}
4897
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004898/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004899testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004900 var TfiUsfArr tua := f_TfiUsfArrInit();
4901 var octetstring data := '0000'O & f_rnd_octstring(21);
4902
4903 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004904
Harald Welte883340c2018-02-28 18:59:29 +01004905 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004906 f_TfiUsfArrSet(tua, 7, 0);
4907 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4908 f_sleep(1.0);
4909
4910 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004911}
4912
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004913private function f_TC_pcu_ptcch_ul(uint16_t ra)
4914runs on test_CT {
4915 var template PCUIF_Message pcu_rach_ind;
4916 var PCUIF_send_data sd;
4917 var GsmFrameNumber fn;
4918 timer T;
4919
4920 /* Send an Access Burst on PTCCH/U over the Um-interface */
4921 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4922 chan_nr := ts_RslChanNr_PDCH(7),
4923 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4924
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004925 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4926 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004927
4928 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4929 T.start(52.0 * 4.615 / 1000.0);
4930 alt {
4931 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4932 log("Rx an Access Burst on the PCU interface: ", sd.data);
4933 setverdict(pass);
4934 T.stop;
4935 }
4936 [] PCU.receive { repeat; }
4937 [] T.timeout {
4938 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4939 /* Keep going, that's not the end of the world */
4940 }
4941 }
4942}
4943
4944testcase TC_pcu_ptcch() runs on test_CT {
4945 var L1ctlDlMessage dl;
4946 var octetstring data;
4947 timer T;
4948
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004949 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004950 f_init_l1ctl();
4951 f_l1_tune(L1CTL);
4952
4953 /* Activate PDCH channel on TS7 */
4954 f_TC_pcu_act_req(0, 0, 7, true);
4955
4956 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004957 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004958 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004959 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004960 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004961
4962 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4963 for (var integer i := 0; i < 16; i := i + 1) {
4964 log("Sending an Access Burst towards the L1CTL interface");
4965 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4966 }
4967
4968 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4969 data := f_rnd_octstring(23);
4970
4971 /* Verify PTCCH/D: send a random data block, make sure it's received */
4972 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4973 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4974
4975 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4976 * let's give it more time in case if we miss the beginning. */
4977 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4978 alt {
4979 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4980 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4981 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4982 frame := data)) -> value dl {
4983 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4984 setverdict(pass);
4985 T.stop;
4986 }
4987 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4988 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4989 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4990 l2_data := data)) -> value dl {
4991 log("Rx PTCCH/D data block on L1CTL: ", dl);
4992 setverdict(pass);
4993 T.stop;
4994 }
4995 [] L1CTL.receive { repeat; }
4996 [] T.timeout {
4997 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4998 }
4999 }
5000}
5001
Harald Welte883340c2018-02-28 18:59:29 +01005002/* Send AGCH from PCU; check it appears on Um side */
5003testcase TC_pcu_data_req_agch() runs on test_CT {
5004 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005005 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005006 f_init_l1ctl();
5007 f_l1_tune(L1CTL);
5008
5009 f_TC_pcu_act_req(0, 0, 7, true);
5010 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5011
5012 T.start;
5013 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005014 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005015 setverdict(pass);
5016 }
5017 [] L1CTL.receive { repeat; }
5018 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005020 }
5021 }
5022}
5023
Harald Welte928622b2019-05-26 13:22:59 +02005024/* Send AGCH from PCU; check it appears on Um side */
5025testcase TC_pcu_data_req_pch() runs on test_CT {
5026 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005027 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005028 f_init_l1ctl();
5029 f_l1_tune(L1CTL);
5030
5031 f_TC_pcu_act_req(0, 0, 7, true);
5032 /* three characters prefix: last 3 digits of IMSI as ASCII */
5033 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5034
5035 T.start;
5036 alt {
5037 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5038 setverdict(pass);
5039 }
5040 [] L1CTL.receive { repeat; }
5041 [] T.timeout {
5042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5043 }
5044 }
5045}
5046
Harald Welte883340c2018-02-28 18:59:29 +01005047/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5048testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5049 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005050 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005051 f_init_l1ctl();
5052 f_l1_tune(L1CTL);
5053
5054 /* append 3 last imsi digits so BTS can compute pagng group */
5055 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5056
5057 timer T := 0.5;
5058 T.start;
5059 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005060 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005061 /* TODO: verify paging group */
5062 setverdict(pass);
5063 }
5064 [] L1CTL.receive { repeat; }
5065 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005066 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005067 }
5068 }
5069}
5070
5071/* Send RACH from Um side, expect it to show up on PCU socket */
5072testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005073 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005074 f_init_l1ctl();
5075 f_l1_tune(L1CTL);
5076
5077 var GsmFrameNumber fn_last := 0;
5078 for (var integer i := 0; i < 1000; i := i+1) {
5079 var OCT1 ra := f_rnd_ra_ps();
5080 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5081 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005082 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005083 }
5084 fn_last := fn;
5085
5086 timer T := 2.0;
5087 T.start;
5088 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005089 [] 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 +01005090 T.stop;
5091 }
5092 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005094 }
5095 [] PCU.receive { repeat; }
5096 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005097 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005098 }
5099 }
5100 }
5101 setverdict(pass);
5102}
5103
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005104/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5105 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5106testcase TC_pcu_ext_rach_content() runs on test_CT {
5107 var template PCUIF_Message pcu_rach_ind;
5108 var GsmFrameNumber fn_last := 0;
5109 var L1ctlRachSynchSeq synch_seq;
5110 var PCUIF_BurstType pcu_bt;
5111 var GsmFrameNumber fn;
5112 var BIT11 ra11;
5113
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005114 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005115 f_init_l1ctl();
5116 f_l1_tune(L1CTL);
5117
5118 for (var integer i := 0; i < 1000; i := i+1) {
5119 /* We need to test both TS1 & TS2 */
5120 if (i rem 2 == 0) {
5121 synch_seq := RACH_SYNCH_SEQ_TS1;
5122 pcu_bt := BURST_TYPE_1;
5123 } else {
5124 synch_seq := RACH_SYNCH_SEQ_TS2;
5125 pcu_bt := BURST_TYPE_2;
5126 }
5127
5128 ra11 := f_rnd_ra11_ps();
5129 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5130 if (fn == fn_last) {
5131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5132 "Two RACH in same FN?!?");
5133 }
5134 fn_last := fn;
5135
5136 /* Compose the expected message */
5137 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005138 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005139 ra := bit2int(ra11),
5140 is_11bit := 1,
5141 burst_type := pcu_bt,
5142 fn := fn);
5143
5144 timer T := 2.0;
5145 T.start;
5146 alt {
5147 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5148 T.stop;
5149 }
5150 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5152 }
5153 [] PCU.receive { repeat; }
5154 [] T.timeout {
5155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5156 }
5157 }
5158 }
5159 setverdict(pass);
5160}
5161
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005162private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5163runs on test_CT {
5164 var template PCUIF_send_data sdt;
5165 var PCUIF_send_data sd;
5166 var int16_t lqual_cb;
5167 timer T := 1.0;
5168
5169 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5170 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5171
5172 /* Send a random PDTCH frame over Um */
5173 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5174 '0000'O & f_rnd_octstring(21)));
5175
5176 T.start;
5177 alt {
5178 /* If expected link quality is above the threshold */
5179 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5180 lqual_cb := sd.data.u.data_ind.lqual_cb;
5181 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5182
5183 /* Make sure the actual link quality matches the expected value */
5184 if (not match(lqual_cb, lqual_cb_exp)) {
5185 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5186 "expected value ", lqual_cb_exp));
5187 } else {
5188 setverdict(pass);
5189 }
5190 }
5191 /* If expected link quality is below the threshold */
5192 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5193 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5194 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5195 }
5196 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5197 [] PCU.receive { repeat; }
5198 [lqual_cb_exp < thresh] T.timeout {
5199 log("Rx nothing, as expected");
5200 setverdict(pass);
5201 }
5202 [lqual_cb_exp >= thresh] T.timeout {
5203 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5204 "Timeout waiting for PCUIF_DATA.ind");
5205 }
5206 }
5207}
5208
5209/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5210testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005211 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005212 PCU.clear;
5213
5214 f_init_l1ctl();
5215 f_l1_tune(L1CTL);
5216
5217 /* Activate a PDCH channel on TS7 */
5218 f_TC_pcu_act_req(0, 0, 7, true);
5219
5220 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005221 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005222 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005223 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005224 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005225
5226 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5227 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5228 var TrxcMessage ret;
5229
5230 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5231 valueof(ts_TRXC_FAKE_CI(i)));
5232
5233 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5234 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5235 }
5236}
5237
Harald Welte883340c2018-02-28 18:59:29 +01005238/* Send PAGING via RSL, expect it to shw up on PCU socket */
5239testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005240 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005241
5242 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005243 var MobileIdentityLV mi_lv;
5244 var octetstring mi_lv_enc;
5245 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005246 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005247
Harald Welte883340c2018-02-28 18:59:29 +01005248 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005249 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005250 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005251 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005252 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005253
5254 /* Fancy encoding for PCUIF */
5255 mi_lv := valueof(ts_MI_LV(mi));
5256 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5257 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005258
5259 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005260 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005261 T.start;
5262 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005263 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005264 }
5265 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005267 }
5268 [] PCU.receive { repeat; }
5269 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005270 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005271 }
5272 }
5273 }
5274 setverdict(pass);
5275}
5276
Harald Welted66c9b82019-05-25 09:03:15 +02005277/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5278testcase TC_pcu_time_ind() runs on test_CT {
5279 var PCUIF_send_data pcu_sd;
5280 var integer num_time_ind := 0;
5281 var integer first_fn, last_fn;
5282 var float test_duration := 5.0;
5283 timer T;
5284
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005285 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005286 f_TC_pcu_act_req(0, 0, 7, true);
5287
5288 PCU.clear;
5289 T.start(test_duration);
5290 alt {
5291 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5292 num_time_ind := num_time_ind + 1;
5293 if (not isbound(first_fn)) {
5294 first_fn := pcu_sd.data.u.time_ind.fn;
5295 }
5296 last_fn := pcu_sd.data.u.time_ind.fn;
5297 repeat;
5298 }
5299 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5300 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5301 repeat;
5302 }
5303 [] PCU.receive {
5304 repeat;
5305 }
5306 [] T.timeout {}
5307 }
5308 var integer fn_expired := last_fn - first_fn;
5309 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5310
5311 /* verify the number of frames expired matches our expectation */
5312 const float c_GSM_FN_DURATION_MS := 4.61538;
5313 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005314 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005315 if (not match(fn_expired, t_fn_expected)) {
5316 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5317 }
5318
5319 /* There are three TIME.ind in every fn MOD 13 */
5320 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5321 /* Add some tolerance */
5322 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5323 if (not match(num_time_ind, t_time_ind_exp)) {
5324 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5325 }
5326
5327 setverdict(pass);
5328}
5329
Harald Welte4832c862019-05-25 14:57:18 +02005330/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5331testcase TC_pcu_rts_req() runs on test_CT {
5332 var PCUIF_send_data pcu_sd;
5333 var integer first_fn, last_fn;
5334 var integer num_rts_pdtch := 0;
5335 var integer num_rts_ptcch := 0;
5336 var float test_duration := 5.0;
5337 timer T;
5338
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005339 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005340 f_TC_pcu_act_req(0, 0, 7, true);
5341
5342 PCU.clear;
5343 T.start(test_duration);
5344 alt {
5345 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5346 -> value pcu_sd {
5347 num_rts_pdtch := num_rts_pdtch + 1;
5348 if (not isbound(first_fn)) {
5349 first_fn := pcu_sd.data.u.rts_req.fn;
5350 }
5351 last_fn := pcu_sd.data.u.rts_req.fn;
5352 repeat;
5353 }
5354 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5355 -> value pcu_sd {
5356 num_rts_ptcch := num_rts_ptcch + 1;
5357 if (not isbound(first_fn)) {
5358 first_fn := pcu_sd.data.u.rts_req.fn;
5359 }
5360 last_fn := pcu_sd.data.u.rts_req.fn;
5361 repeat;
5362 }
5363 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5364 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5365 repeat;
5366 }
5367 [] PCU.receive {
5368 repeat;
5369 }
5370 [] T.timeout {}
5371 }
5372 var integer fn_expired := last_fn - first_fn;
5373 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5374 ", num_rts_ptcch=", num_rts_ptcch);
5375
5376 /* verify the number of frames expired matches our expectation */
5377 const float c_GSM_FN_DURATION_MS := 4.61538;
5378 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005379 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005380 if (not match(fn_expired, t_fn_expected)) {
5381 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5382 }
5383
5384 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5385 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5386 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5387 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5388 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5389 t_ptcch_exp);
5390 }
5391
5392 /* We have 12 PDTCH blocks every 52-multiframe */
5393 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5394 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5395 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5396 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5397 t_pdtch_exp);
5398 }
5399
5400 setverdict(pass);
5401}
5402
Harald Welte07bd2d22019-05-25 11:03:30 +02005403/* test for generating Abis side OML ALERT from the PCU */
5404testcase TC_pcu_oml_alert() runs on test_CT {
5405 var PCUIF_send_data pcu_sd;
5406 var integer num_time_ind := 0;
5407 var integer first_fn, last_fn;
5408 var float test_duration := 5.0;
5409 timer T;
5410
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005411 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005412 f_TC_pcu_act_req(0, 0, 7, true);
5413
5414 /* re-connect CTRL port from BTS to BSC */
5415 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005416 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005417
5418 /* Send that OML Alert */
5419 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5420
5421 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5422 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5423 setverdict(pass);
5424}
5425
Harald Welteeaa9a862019-05-26 23:01:08 +02005426/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5427private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5428 var PCUIF_Message first_info;
5429 var integer pcu_conn_id := -1;
5430 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5431 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5432 var OCT4 tlli := '01020304'O;
5433 var OCT1 cause := '23'O;
5434 timer T := 5.0;
5435
5436 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5437
5438 f_l1_tune(L1CTL);
5439 RSL.clear;
5440
5441 f_est_dchan();
5442 L1CTL.clear;
5443
5444 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5445
5446 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5447 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5448 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5449
5450 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5451 T.start;
5452 alt {
5453 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5454 setverdict(pass);
5455 }
5456 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5457 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5458 }
5459 [] PCU.receive {
5460 repeat;
5461 }
5462 [] T.timeout {
5463 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5464 }
5465 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005466
5467 /* release the channel */
5468 f_rsl_chan_deact();
5469 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5470 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005471}
5472testcase TC_pcu_rr_suspend() runs on test_CT {
5473 var ConnHdlrPars pars;
5474 var ConnHdlr vc_conn;
5475
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005476 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005477
5478 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5479 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5480 vc_conn.done;
5481}
Harald Welte07bd2d22019-05-25 11:03:30 +02005482
Harald Weltea2e0e942019-05-27 18:12:53 +02005483/* Ensure that PCUIF socket can accept only a single connection */
5484testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005485 var boolean connected := false;
5486 var UD_connect_result cr;
5487 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005488 timer T := 5.0;
5489
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005490 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5491 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5492
Harald Weltea2e0e942019-05-27 18:12:53 +02005493 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005494 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005495
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005496 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005497 PCU.send(UD_connect:{mp_pcu_socket, -1});
5498 T.start;
5499 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005500 /* the IUT will first accept() the new connection, and close() it immediately */
5501 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5502 log("BTS has accept()ed connection");
5503 connected := true;
5504 cid := cr.id;
5505 repeat;
5506 }
5507 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5508 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005509 setverdict(pass);
5510 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005511 /* ignore other messages related to the first connection */
5512 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005513 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005514 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005515 }
5516 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005517
Harald Weltea2e0e942019-05-27 18:12:53 +02005518 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5519}
5520
Harald Weltec8effb72019-05-27 18:23:04 +02005521/* Ensure that PCUIF socket can disconnect + reconnect */
5522testcase TC_pcu_socket_reconnect() runs on test_CT {
5523 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005524 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005525
5526 f_sleep(1.0);
5527
5528 f_pcuif_close(PCU, g_pcu_conn_id);
5529 g_pcu_conn_id := -1;
5530
5531 f_sleep(1.0);
5532
5533 /* re-connect */
5534 PCU.clear;
5535 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5536 setverdict(pass);
5537
5538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5539}
5540
Harald Weltebe030482019-05-27 22:29:35 +02005541/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005542private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5543runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005544 var L1ctlDlMessage l1_dl;
5545 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005546 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005547 timer T := 5.0;
5548 T.start;
5549 alt {
5550 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005551 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5552 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005553 repeat;
5554 }
5555 }
5556 [] pt.receive {
5557 repeat;
5558 }
5559 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5561 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005562 }
5563 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005564 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005565}
5566
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005567/* Check if GPRS Indicator is present in RR System Information of a given type */
5568private function f_si_has_gprs_indicator(RrMessageType si_type)
5569runs on test_CT return boolean {
5570 var SystemInformation si := f_get_si(L1CTL, si_type);
5571
5572 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005573 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005574 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005575 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005576 }
5577
5578 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5579 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005580}
5581
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005582/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5583private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5584runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005585 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02005586 f_init_l1ctl();
5587 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005588 f_sleep(2.0);
5589 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005590
5591 if (f_si_has_gprs_indicator(si_type)) {
5592 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005593 } else {
5594 setverdict(pass);
5595 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005596
Harald Weltebe030482019-05-27 22:29:35 +02005597 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5598}
5599
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005600testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5601 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5602}
Harald Weltebe030482019-05-27 22:29:35 +02005603
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005604testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5605 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5606}
5607
5608/* Ensure that GPRS capability is advertised after PCU socket connect */
5609private function f_TC_pcu_socket_connect(RrMessageType si_type)
5610runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005611 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005612 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005613 f_init_l1ctl();
5614 f_l1_tune(L1CTL);
5615
5616 f_sleep(2.0);
5617 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005618
5619 if (not f_si_has_gprs_indicator(si_type)) {
5620 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005621 } else {
5622 setverdict(pass);
5623 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005624
Harald Weltebe030482019-05-27 22:29:35 +02005625 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5626}
5627
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005628testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5629 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5630}
Harald Weltebe030482019-05-27 22:29:35 +02005631
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005632testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5633 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5634}
5635
5636/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5637private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5638runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005639 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005640 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005641 f_init_l1ctl();
5642 f_l1_tune(L1CTL);
5643
5644 f_pcuif_close(PCU, g_pcu_conn_id);
5645 g_pcu_conn_id := -1;
5646
5647 f_sleep(1.0);
5648
5649 /* re-connect */
5650 PCU.clear;
5651 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5652
5653 f_sleep(2.0);
5654 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005655
5656 if (f_si_has_gprs_indicator(si_type)) {
5657 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005658 } else {
5659 setverdict(pass);
5660 }
5661
5662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5663}
5664
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005665testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5666 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5667}
5668
5669testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5670 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5671}
5672
Oliver Smithf5239c72019-08-28 10:01:25 +02005673/* 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) */
5674testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5675 var SystemInformation si3 := valueof(ts_SI3_default);
5676
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005677 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02005678
Harald Welte76220222020-10-11 20:32:44 +02005679 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5680 * information */
5681 timer T := 2.0;
5682 T.start;
5683 alt {
5684 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5685 [] T.timeout {}
5686 }
5687
Oliver Smithf5239c72019-08-28 10:01:25 +02005688 /* Verify cell_id */
5689 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5690 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5691 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005692 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5693 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5694 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005695 }
5696
5697 /* Verify LAC */
5698 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5699 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5700 if (lac_si3 != lac_pcu) {
5701 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5702 }
5703
5704 setverdict(pass);
5705}
Harald Welted66c9b82019-05-25 09:03:15 +02005706
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005707/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5708testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5709 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005710 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005711
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005712 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005713
5714 info_ind := g_pcu_last_info.u.info_ind;
5715
5716 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5717 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005718 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005719 /* Skip inactive timeslots */
5720 continue;
5721 }
5722
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005723 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005724 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005725 else
5726 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005727
5728 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005729 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005730 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005731 hsn := fhp.maio_hsn.hsn,
5732 maio := fhp.maio_hsn.maio,
5733 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005734 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005735 } else {
5736 tr_ts := tr_PCUIF_InfoTrxTsH0;
5737 }
5738
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005739 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005740 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5741 if (not match(ts, tr_ts)) {
5742 setverdict(fail, "Hopping parameters do not match: ",
5743 "received ", ts, " vs expected ", tr_ts);
5744 } else {
5745 setverdict(pass);
5746 }
5747 }
5748 }
5749}
5750
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005751/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02005752testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5753 f_init_vty_bsc();
5754 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5755 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5756
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005757 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02005758
5759 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005760 var template PCUIF_RemoteAddr tr_remote_addr := {
5761 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01005762 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005763 };
Alexander Couzens5283f552020-07-28 15:39:04 +02005764
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005765 if (not match(remote_addr, tr_remote_addr)) {
5766 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02005767 }
5768
5769 setverdict(pass);
5770}
5771
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005772/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02005773testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5774 f_init_vty_bsc();
5775 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5776
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005777 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02005778
5779 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005780 var template PCUIF_RemoteAddr tr_remote_addr := {
5781 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
5782 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
5783 };
Alexander Couzens5283f552020-07-28 15:39:04 +02005784
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005785 if (not match(remote_addr, tr_remote_addr)) {
5786 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02005787 }
5788
5789 setverdict(pass);
5790}
5791
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005792/* Verify coding of two NSVCs in the INFO.ind message */
5793testcase TC_pcu_socket_two_nsvc() runs on test_CT {
5794 f_init_vty_bsc();
5795
5796 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
5797 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
5798 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5799 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
5800
5801 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
5802 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
5803 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
5804 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
5805
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005806 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005807
5808 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
5809 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
5810 var template PCUIF_RemoteAddr tr_remote_addr := {
5811 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01005812 addr := {
5813 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
5814 f_inet6_addr("fd00::ca:ff:ee")
5815 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005816 };
5817
5818 if (not match(info_ind.nsvci, { 1234, 5678 }))
5819 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
5820 if (not match(remote_addr, tr_remote_addr))
5821 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
5822 if (not match(info_ind.local_port, { 1234, 5678 }))
5823 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
5824 if (not match(info_ind.remote_port, { 1234, 5678 }))
5825 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
5826
5827 setverdict(pass);
5828}
5829
Harald Welte3d04ae62018-04-04 20:29:05 +02005830/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005831 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005832 ***********************************************************************/
5833
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005834private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5835 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005836runs on ConnHdlr {
5837 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005838
5839 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005840 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005841 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5842 repeat;
5843 }
5844 }
5845}
5846
5847private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5848runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005849 /* Expect BTS to immediately acknowledge activation as PDCH */
5850 PCU.clear;
5851 f_rsl_chan_act(g_pars.chan_mode);
5852 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005853 timer T_wait := 2.0;
5854 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005855 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005856 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005857 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005858 [] T_wait.timeout {
5859 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5860 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5861 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005862 }
5863 /* try to activate this PDCH from the PCU point of view */
5864 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5865 /* FIXME: is there a response? */
5866}
5867
5868private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5869runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005870 /* Send RSL CHAN REL (deactivate) */
5871 PCU.clear;
5872 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5873 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005874 timer T_wait := 2.0;
5875 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005876 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005877 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005878 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005879 [] T_wait.timeout {
5880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5881 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5882 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005883 }
5884 /* Emulate PCU asking BTS to deactivate PDCH */
5885 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5886 alt {
5887 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5888 setverdict(pass);
5889 }
5890 [] RSL.receive { repeat; }
5891 }
5892}
5893
5894/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005895private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005896 var PCUIF_Message first_info;
5897 var integer ts_nr := g_chan_nr.tn;
5898 var integer trx_nr := 0;
5899 var integer bts_nr := 0;
5900 var integer pcu_conn_id := -1;
5901
5902 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5903
5904 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5905 f_sleep(3.0);
5906 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5907 setverdict(pass);
5908}
5909testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5910 var ConnHdlrPars pars;
5911 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005912 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005913
5914 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5915 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5916 vc_conn.done;
5917}
5918
5919/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005920private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005921 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005922 var integer pcu_conn_id := -1;
5923
5924 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5925
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005926 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5927 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5928 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005929 setverdict(pass);
5930}
5931testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5932 var ConnHdlrPars pars;
5933 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005934 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005935
5936 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5937 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5938 vc_conn.done;
5939}
5940
5941/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005942private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005943 var PCUIF_Message first_info;
5944 var integer ts_nr := g_chan_nr.tn;
5945 var integer trx_nr := 0;
5946 var integer bts_nr := 0;
5947 var integer pcu_conn_id := -1;
5948
5949 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5950
5951 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005952 /* Send a second Chan Activ and expect it to be NACKed */
5953 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5954 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005955 setverdict(pass);
5956}
5957testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5958 var ConnHdlrPars pars;
5959 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005960 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005961
5962 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5963 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5964 vc_conn.done;
5965}
5966
5967/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005968private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005969 var PCUIF_Message first_info;
5970 var integer ts_nr := g_chan_nr.tn;
5971 var integer trx_nr := 0;
5972 var integer bts_nr := 0;
5973 var integer pcu_conn_id := -1;
5974 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5975
5976 /* register for the TCH/F channel number */
5977 f_rslem_register(0, chan_nr);
5978
5979 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5980
5981 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5982 "RSL CHAN ACT");
5983 setverdict(pass);
5984}
5985testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5986 var ConnHdlrPars pars;
5987 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005988 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005989
5990 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5991 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5992 vc_conn.done;
5993}
5994
5995/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005996private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005997 var PCUIF_Message first_info;
5998 var integer ts_nr := g_chan_nr.tn;
5999 var integer trx_nr := 0;
6000 var integer bts_nr := 0;
6001 var integer pcu_conn_id := -1;
6002 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
6003 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6004
6005 /* register for the TCH/H channel numbers */
6006 f_rslem_register(0, chan_nr[0]);
6007 f_rslem_register(0, chan_nr[1]);
6008
6009 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6010
6011 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6012 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6013 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6014 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6015 setverdict(pass);
6016}
6017testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6018 var ConnHdlrPars pars;
6019 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006020 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006021
6022 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6023 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6024 vc_conn.done;
6025}
6026
Harald Welte9bbbfb52018-04-05 09:33:19 +02006027/***********************************************************************
6028 * IPA Style Dynamic Timeslot Support
6029 ***********************************************************************/
6030
6031private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6032runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006033 /* Expect BTS to immediately acknowledge activation as PDCH */
6034 PCU.clear;
6035 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6036 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006037 timer T_wait := 2.0;
6038 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006039 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006040 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006041 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006042 [] T_wait.timeout {
6043 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6044 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6045 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006046 }
6047 /* try to activate this PDCH from the PCU point of view */
6048 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6049 /* FIXME: is there a response? */
6050
6051 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6052}
6053
6054private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6055runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006056 /* Send RSL CHAN REL (deactivate) */
6057 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6058 PCU.clear;
6059 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006060 timer T_wait := 2.0;
6061 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006062 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006063 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006064 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006065 [] T_wait.timeout {
6066 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6067 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6068 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006069 }
6070 /* Emulate PCU asking BTS to deactivate PDCH */
6071 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6072 alt {
6073 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6074 setverdict(pass);
6075 }
6076 [] RSL.receive { repeat; }
6077 }
6078}
6079
6080/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006081private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006082 var PCUIF_Message first_info;
6083 var integer ts_nr := g_chan_nr.tn;
6084 var integer trx_nr := 0;
6085 var integer bts_nr := 0;
6086 var integer pcu_conn_id := -1;
6087
6088 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6089
6090 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6091 f_sleep(3.0);
6092 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6093
6094 setverdict(pass);
6095
6096}
6097testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6098 var ConnHdlrPars pars;
6099 var ConnHdlr vc_conn;
6100 f_init();
6101
6102 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6103 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6104 vc_conn.done;
6105}
6106
6107/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006108private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006109 var PCUIF_Message first_info;
6110 var integer ts_nr := g_chan_nr.tn;
6111 var integer trx_nr := 0;
6112 var integer bts_nr := 0;
6113 var integer pcu_conn_id := -1;
6114
6115 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6116
6117 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6118 "RSL CHAN ACT");
6119 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6120 "RF CHAN REL", true);
6121 setverdict(pass);
6122}
6123testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6124 var ConnHdlrPars pars;
6125 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006126 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006127
6128 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6129 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6130 vc_conn.done;
6131}
6132
6133/* 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 +07006134private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006135 var PCUIF_Message first_info;
6136 var integer ts_nr := g_chan_nr.tn;
6137 var integer trx_nr := 0;
6138 var integer bts_nr := 0;
6139 var integer pcu_conn_id := -1;
6140
6141 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6142
6143 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6144 "RSL CHAN ACT");
6145
6146 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6147 alt {
6148 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6149 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006150 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006151 }
6152 [] RSL.receive { repeat; }
6153 }
6154
6155 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6156 "RF CHAN REL", true);
6157 setverdict(pass);
6158}
6159testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6160 var ConnHdlrPars pars;
6161 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006162 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006163
6164 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6165 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6166 vc_conn.done;
6167}
6168
6169/* 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 +07006170private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006171 var PCUIF_Message first_info;
6172 var integer ts_nr := g_chan_nr.tn;
6173 var integer trx_nr := 0;
6174 var integer bts_nr := 0;
6175 var integer pcu_conn_id := -1;
6176
6177 /* register for the TCH/F channel number */
6178 f_rslem_register(0, g_chan_nr);
6179
6180 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6181
6182 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6183
6184 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6185 "RSL CHAN ACT");
6186
6187 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6188
6189 setverdict(pass);
6190}
6191testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6192 var ConnHdlrPars pars;
6193 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006194 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006195
6196 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6197 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6198 vc_conn.done;
6199}
6200
6201
Harald Welte0472ab42018-03-12 15:02:26 +01006202/***********************************************************************
6203 * LAPDm / RLL related
6204 ***********************************************************************/
6205
6206private function f_tx_lapdm(template (value) LapdmFrame l,
6207 template (value) RslLinkId link_id) runs on ConnHdlr {
6208 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006209 var template (value) SacchL1Header l1h;
6210
6211 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006212 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006213 /* Compose dummy L1 header */
6214 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6215 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 +02006216 } else {
6217 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006218 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 +01006219 }
Harald Welte0472ab42018-03-12 15:02:26 +01006220}
6221
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006222friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006223 uint3_t sapi,
6224 RslLinkId link_id,
6225 octetstring l3,
6226 boolean exp
6227}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006228friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006229friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6230 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006231 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006232 sapi := sapi,
6233 link_id := id,
6234 l3 := l3,
6235 exp := exp
6236}
6237
6238/* execute the same callback function with a set of different parameters (tcs) on a
6239 * variety of logical channels */
6240private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6241 var ConnHdlrPars pars;
6242 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006243 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006244
6245 /* test on each of the channels we have */
6246 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6247 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6248
6249 /* test each of the test cases on the current channel */
6250 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6251 pars.spec.rll := tcs[j];
6252 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6253 vc_conn := f_start_handler(fn, pars);
6254 vc_conn.done;
6255 }
6256 }
6257
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006259}
6260
6261/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6262private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6263 var RllTestCase tc := g_pars.spec.rll;
6264 timer T := 3.0;
6265
6266 f_l1_tune(L1CTL);
6267 RSL.clear;
6268
6269 /* activate the logical channel */
6270 f_est_dchan();
6271 L1CTL.clear;
6272
6273 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6274 T.start;
6275 alt {
6276 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6277 if (tc.exp) {
6278 setverdict(pass);
6279 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006280 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006281 }
6282 }
6283 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6284 if (tc.exp) {
6285 setverdict(pass);
6286 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006288 }
6289 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006290 /* We also expect to receive the measurements */
6291 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006292 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006293 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006294 }
6295 [not tc.exp] T.timeout {
6296 setverdict(pass);
6297 }
6298 }
6299
6300 f_rsl_chan_deact();
6301 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6302 f_rslem_unregister(0, g_chan_nr);
6303}
6304testcase TC_rll_est_ind() runs on test_CT {
6305 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006306 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006307 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006308 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006309 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006310 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006311 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6312 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006313 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006314 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006315 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006316 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006317 };
6318 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6319}
6320
6321/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6322private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6323 var RllTestCase tc := g_pars.spec.rll;
6324 var L1ctlDlMessage dl;
6325 timer T := 3.0;
6326
6327 f_l1_tune(L1CTL);
6328 RSL.clear;
6329
6330 /* activate the logical channel */
6331 f_est_dchan();
6332 L1CTL.clear;
6333
6334 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6335 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6336 T.start;
6337 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006338 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006339 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006340 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006341 }
6342 }
6343
6344 f_rsl_chan_deact();
6345 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6346 f_rslem_unregister(0, g_chan_nr);
6347}
6348testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6349 var RllTestCases tcs := {
6350 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006351 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006352 };
6353 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6354}
6355testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6356 var RllTestCases tcs := {
6357 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006358 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006359 }
6360 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6361}
6362
6363/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006364friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006365 var L1ctlDlMessage dl;
6366 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6367 var LapdmFrame lapdm;
6368 var octetstring l2 := dl.payload.data_ind.payload;
6369 if (dl.dl_info.link_id.c == SACCH) {
6370 /* remove L1 header */
6371 l2 := substr(l2, 2, lengthof(l2)-2);
6372 }
6373 if (ischosen(exp.ab)) {
6374 lapdm.ab := dec_LapdmFrameAB(l2);
6375 } else if (ischosen(exp.b4)) {
6376 lapdm.b4 := dec_LapdmFrameB4(l2);
6377 } else if (ischosen(exp.bbis)) {
6378 lapdm.bbis := dec_LapdmFrameBbis(l2);
6379 }
6380 log("Rx LAPDm ", lapdm);
6381 if (match(lapdm, exp)) {
6382 setverdict(pass);
6383 } else {
6384 repeat;
6385 }
6386 }
6387 [] L1CTL.receive { repeat; }
6388}
6389private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6390 timer T := t;
6391 T.start;
6392 alt {
6393 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006395 }
6396 [] as_l1_exp_lapdm(exp);
6397 }
6398}
6399
6400/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6401private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6402 /* send SABM from MS -> BTS */
6403 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6404 /* expect RLL EST IND on Abis */
6405 alt {
6406 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6407 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6408 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006410 }
6411 [] RSL.receive { repeat; }
6412 }
6413 /* expect UA from BTS -> MS */
6414 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6415}
6416
6417/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6418private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6419 var RllTestCase tc := g_pars.spec.rll;
6420
6421 f_l1_tune(L1CTL);
6422 RSL.clear;
6423
6424 /* activate the logical channel */
6425 f_est_dchan();
6426 L1CTL.clear;
6427
6428 /* first establish the link-layer */
6429 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6430
6431 /* then send the DISC */
6432 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6433 /* ... and expect the REL IND on the RSL side */
6434 alt {
6435 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6436 setverdict(pass);
6437 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006438 /* We also expect to receive the measurements */
6439 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006440 }
6441
6442 /* release the channel */
6443 f_rsl_chan_deact();
6444 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6445 f_rslem_unregister(0, g_chan_nr);
6446}
6447testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6448 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006449 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006450 };
6451 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6452}
6453
6454testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6455 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006456 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006457 };
6458 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6459}
6460testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6461 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006462 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006463 };
6464 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6465}
6466testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6467 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006468 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006469 };
6470 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6471}
6472
6473/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6474private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6475 var RllTestCase tc := g_pars.spec.rll;
6476 f_l1_tune(L1CTL);
6477 RSL.clear;
6478
6479 /* activate the logical channel */
6480 f_est_dchan();
6481 L1CTL.clear;
6482
6483 /* first establish the link-layer */
6484 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6485
6486 /* then send the REL REQ via RSL */
6487 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6488 /* ... and expect the DISC on the Um side */
6489 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006490 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006491 /* FIXME: send a UA in resposne to the DISC */
6492 }
6493 }
6494
6495 /* release the channel */
6496 f_rsl_chan_deact();
6497 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6498 f_rslem_unregister(0, g_chan_nr);
6499}
6500testcase TC_rll_rel_req() runs on test_CT {
6501 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006502 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
6503 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
6504 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
6505 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006506 };
6507 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6508}
6509
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006510/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006511testcase TC_rll_data_req() runs on test_CT {
6512}
6513
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006514/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006515testcase TC_rll_data_ind() runs on test_CT {
6516}
6517
6518/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6519private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6520 var RllTestCase tc := g_pars.spec.rll;
6521
6522 f_l1_tune(L1CTL);
6523 RSL.clear;
6524
6525 f_est_dchan();
6526 L1CTL.clear;
6527
6528 /* Send UNITDATA REQ on RSL side */
6529 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6530 /* Expect it to arrive on the other side */
6531 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006532 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006533 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006534 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006535 }
6536
6537 /* release the channel */
6538 f_rsl_chan_deact();
6539 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6540 f_rslem_unregister(0, g_chan_nr);
6541}
6542testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6543 var octetstring l3 := f_rnd_octstring(15);
6544 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006545 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6546 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006547 };
6548 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6549}
6550testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6551 var octetstring l3 := f_rnd_octstring(19);
6552 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006553 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6554 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006555 };
6556 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6557}
6558
6559/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6560private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6561 var RllTestCase tc := g_pars.spec.rll;
6562
6563 f_l1_tune(L1CTL);
6564 RSL.clear;
6565
6566 f_est_dchan();
6567 L1CTL.clear;
6568
6569 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006570 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006571 /* Expdct RLL UNITDATA IND on RSL side */
6572 alt {
6573 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6574 setverdict(pass);
6575 }
6576 [] RSL.receive { repeat; }
6577 }
6578
6579 /* release the channel */
6580 f_rsl_chan_deact();
6581 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6582 f_rslem_unregister(0, g_chan_nr);
6583}
6584testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006585 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006586 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006587 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6588 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006589 };
6590 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6591}
6592testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6593 var octetstring l3 := f_rnd_octstring(18);
6594 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006595 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6596 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006597 };
6598 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6599}
6600
Harald Weltee613f962018-04-18 22:38:16 +02006601/***********************************************************************
6602 * Encryption Related
6603 ***********************************************************************/
6604
6605/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006606private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006607 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6608 if (link_id.c == SACCH) {
6609 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6610 } else {
6611 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6612 }
6613}
6614
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006615/* Expect (or not expect) other kinds of messages */
6616private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6617 [exp_any] RSL.receive { repeat; }
6618 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006619 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006620 }
6621}
6622
Harald Weltee613f962018-04-18 22:38:16 +02006623/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006624private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006625 RslLinkId link_id,
6626 octetstring l3,
6627 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006628 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006629) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006630 timer T := 3.0;
6631 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6632 T.start;
6633 /* Expect RLL UNITDATA IND on RSL side */
6634 alt {
6635 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6636 setverdict(pass);
6637 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006638 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006639 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006640 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006641 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006642 }
Harald Weltee613f962018-04-18 22:38:16 +02006643 }
6644}
6645
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006646/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6647private function f_data_mo(
6648 RslLinkId link_id,
6649 boolean p, uint3_t nr, uint3_t ns,
6650 octetstring l3,
6651 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006652 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006653) runs on ConnHdlr {
6654 timer T := 3.0;
6655 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6656 T.start;
6657 /* Expect RLL DATA IND on RSL side */
6658 alt {
6659 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6660 setverdict(pass);
6661 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006662 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006663 [] as_rsl_any_ind(exp_any);
6664 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006666 }
6667 }
6668}
6669
Harald Weltee613f962018-04-18 22:38:16 +02006670/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006671private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006672 f_l1_tune(L1CTL);
6673 f_est_dchan(true);
6674
6675 /* now we actually need to transmit some data both ways to check if the encryption works */
6676 var L1ctlDlMessage dl;
6677
Stefan Sperling603d98e2018-07-25 16:47:28 +02006678 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006679 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6680
6681 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6682 f_unitdata_mt(link_id, l3);
6683
6684 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6685 f_unitdata_mo(link_id, l3);
6686
6687 /* release the channel */
6688 f_rsl_chan_deact();
6689 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6690 f_rslem_unregister(0, g_chan_nr);
6691}
6692testcase TC_chan_act_a51() runs on test_CT {
6693 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6694 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6695 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6696}
6697testcase TC_chan_act_a52() runs on test_CT {
6698 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6699 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6700 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6701}
6702testcase TC_chan_act_a53() runs on test_CT {
6703 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6704 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6705 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6706}
Eric Wildb9260392021-05-15 19:48:22 +02006707testcase TC_chan_act_a54() runs on test_CT {
6708 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6709 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
6710 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6711}
Harald Weltee613f962018-04-18 22:38:16 +02006712
Eric Wildf1827a72019-05-28 17:37:35 +02006713/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6714 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 +07006715private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006716 f_l1_tune(L1CTL);
6717 f_est_dchan(true);
6718
6719 /* now we actually need to transmit some data both ways to check if the encryption works */
6720 var L1ctlDlMessage dl;
6721
6722 var octetstring l3 := f_rnd_octstring(20);
6723 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6724
6725 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6726 f_unitdata_mt(link_id, l3);
6727
6728 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6729 f_unitdata_mo(link_id, l3);
6730
6731 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006732 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006733
6734 /* modify key to break proper encryption */
6735 g_pars.encr.key := f_rnd_octstring(8);
6736 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6737 rsl.ies := rsl.ies & { ei };
6738 RSL.send(rsl);
6739
6740 timer T0 := 1.0;
6741 T0.start;
6742 /* Expect RSL MODIFY ACK */
6743 alt {
6744 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6745 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6746 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6747 }
6748 [] T0.timeout {
6749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6750 }
6751 }
6752
6753 var octetstring l3msg := f_rnd_octstring(15);
6754 timer T1 := 3.0;
6755 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6756 due to broken encryption */
6757 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6758 T1.start;
6759 alt {
6760 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6762 }
6763 [] T1.timeout {
6764 setverdict(pass);
6765 }
6766 }
6767
6768 /* release the channel */
6769 f_rsl_chan_deact();
6770 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6771 f_rslem_unregister(0, g_chan_nr);
6772}
6773testcase TC_rsl_modify_encr() runs on test_CT {
6774 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6775 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6776 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6777}
Harald Weltee613f962018-04-18 22:38:16 +02006778
6779/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006780private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006781 /* L3 payload doesn't matter, as it is passed transparently */
6782 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6783 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6784 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6785
6786 f_l1_tune(L1CTL);
6787
6788 /* first establish a dedicated channel in the clear */
6789 f_est_dchan(false);
6790
6791 /* Establish ABM */
6792 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6793
6794 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6795 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6796 /* expect the L3 to arrive still unencrypted on the MS side */
6797 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6798
6799 /* configure L1 to apply ciphering */
6800 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6801 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6802
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006803 /* send first ciphered I-frame in response and expect it on RSL */
6804 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006805
6806 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6807 * and hence enable encryption also on the downlink */
6808
6809 /* expect bi-directional communication work in encrypted mode */
6810 f_unitdata_mo(link_id, f_rnd_octstring(15));
6811 f_unitdata_mt(link_id, f_rnd_octstring(15));
6812
6813 /* release the channel */
6814 f_rsl_chan_deact();
6815 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6816 f_rslem_unregister(0, g_chan_nr);
6817}
6818testcase TC_encr_cmd_a51() runs on test_CT {
6819 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6820 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6821 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6822}
6823testcase TC_encr_cmd_a52() runs on test_CT {
6824 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6825 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6826 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6827}
6828testcase TC_encr_cmd_a53() runs on test_CT {
6829 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6830 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6831 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6832}
Eric Wildb9260392021-05-15 19:48:22 +02006833testcase TC_encr_cmd_a54() runs on test_CT {
6834 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6835 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
6836 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6837}
Harald Weltee613f962018-04-18 22:38:16 +02006838
6839private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6840 var LapdmFrame lf;
6841 var octetstring reenc;
6842
6843 /* decode the LAPDm frame */
6844 if (ischosen(exp_match.ab)) {
6845 lf.ab := dec_LapdmFrameAB(enc);
6846 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006848 }
6849
6850 /* check if decoder result matches expectation */
6851 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006853 } else {
6854 log(name, ": matched");
6855 setverdict(pass);
6856 }
6857
6858 /* test if re-encoded frame equals original input */
6859 reenc := enc_LapdmFrame(lf);
6860 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006861 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006862 } else {
6863 setverdict(pass);
6864 }
6865}
6866
6867testcase TC_lapdm_selftest() runs on test_CT {
6868 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6869 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6870 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6871 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6872 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6873 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6874 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6875}
6876
Stefan Sperling4880be42018-08-07 18:12:59 +02006877/***********************************************************************
6878 * DTX Related (see GSM 05.08, section 8.3)
6879 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006880private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006881 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02006882 var GsmFrameNumber first_fn;
6883 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006884 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006885 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006886 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6887 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006888 const integer frame_dtx_tchf_mod := 104;
6889 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6890 * which operates in terms of blocks rather than frames. */
6891 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6892 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006893 timer T := 5.0;
6894
6895 f_l1_tune(L1CTL);
6896 RSL.clear;
6897 L1CTL.clear;
6898
6899 /* activate TCHF signalling channel */
6900 f_est_dchan(false);
6901
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006902 /* A template for matching dummy LAPDm func=UA frames */
6903 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
6904 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
6905 l2_data := f_pad_oct('030301'O, 23, '2B'O));
6906
Stefan Sperling4880be42018-08-07 18:12:59 +02006907 T.start;
6908 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006909 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02006910 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02006911
6912 if (is_first_frame) {
6913 is_first_frame := false;
6914 first_fn := dl.dl_info.frame_nr;
6915 }
6916
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006917 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006918 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006919 T.stop;
6920 f_rsl_chan_deact();
6921 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006922
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006923 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
6924 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006925
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006926 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006927 setverdict(fail, "Not enough fill frames received: ",
6928 nfill_frames, " out of ", expected_fill_frames);
6929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006930 } else {
6931 setverdict(pass);
6932 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006933 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006934 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6935 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6936 * we should only see the subset of frames numbers which correspond to a block boundary.
6937 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6938 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6939 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006940 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006941 repeat;
6942 }
6943 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006944 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
6945 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6946 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006947 f_rsl_chan_deact();
6948 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02006949 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006950 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006951 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006952 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006953 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006954
6955 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006956 /* TCH/F: we expect 24 fill frames for every 104 frames. */
6957 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006958 /* TCH/H: we expect 2 fill frames for every 104 frames. */
6959 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
6960 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006961 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
6962 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006963 case else {
6964 /* This shall not happen, just to be sure */
6965 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6966 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006967 }
6968
6969 f_rsl_chan_deact();
6970 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006971
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006972 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006973 setverdict(pass);
6974 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006975 setverdict(fail, "Not enough fill frames received: ",
6976 nfill_frames, " out of ", expected_fill_frames);
6977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006978 }
6979 } else {
6980 repeat;
6981 }
6982 }
6983 }
6984 [] L1CTL.receive { repeat; }
6985 [] T.timeout {
6986 f_rsl_chan_deact();
6987 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006989 }
6990 }
6991}
6992
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006993private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006994 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02006995 var ConnHdlr vc_conn;
6996 var ConnHdlrPars pars;
6997 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006998 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006999 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02007000 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07007001 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02007002 if (dtxd) {
7003 if (i >= 4) { /* DTX is only allowed on TCH/F */
7004 break;
7005 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007006 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007007 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007008 vc_conn.done;
7009 }
7010}
7011
7012/* Verify that L2 fill frames are sent on TCH in signaling mode if
7013 * there is nothing to transmit while DTX is disabled on downlink. */
7014testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7015 f_tch_sign_l2_fill_frame(false);
7016}
7017
7018/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7019 * there is nothing to transmit while DTX is enabled on downlink. */
7020testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7021 f_tch_sign_l2_fill_frame(true);
7022}
Harald Welte0472ab42018-03-12 15:02:26 +01007023
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007024testcase TC_chopped_ipa_ping() runs on test_CT {
7025 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7026}
7027
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007028testcase TC_chopped_ipa_payload() runs on test_CT {
7029 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7030}
7031
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007032
7033/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7034 * Return value: Measurement Report to be sent (encoded octetstring). */
7035type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7036 runs on ConnHdlr return octetstring;
7037
7038private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7039runs on ConnHdlr {
7040 var L1ctlDlMessage l1_dl;
7041 var SacchL1Header l1h;
7042 var octetstring l2;
7043
7044 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7045 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7046 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7047 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7048
7049 /* Pass it to the user specified call-back function */
7050 l2 := cb.apply(l1h, num_blocks);
7051 /* Send a Measurement Report generated by the call-back */
7052 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7053 l1_dl.dl_info.link_id,
7054 l1h, l2));
7055
7056 /* Shall we keep going? */
7057 num_blocks := num_blocks - 1;
7058 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7059 if (num_blocks > 0) { repeat; }
7060 }
7061 [] L1CTL.receive { repeat; }
7062}
7063
7064private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7065runs on ConnHdlr return octetstring {
7066 /* Command the L1 to apply received parameters */
7067 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7068
7069 /* Dummy measurement report (the results are invalid) */
7070 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7071}
7072
7073private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7074runs on ConnHdlr return octetstring {
7075 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7076 setverdict(fail, "Unexpected MS Power level change: ",
7077 g_pars.l1_pars.ms_power_level, " -> ",
7078 l1h.ms_power_lvl);
7079 }
7080
7081 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7082}
7083
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007084private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7085runs on ConnHdlr return octetstring {
7086 /* UL RSSI oscillation driven by SACCH block number */
7087 if (num_blocks rem 2 == 0) {
7088 f_trxc_fake_rssi(-100);
7089 } else {
7090 f_trxc_fake_rssi(-50);
7091 }
7092
7093 /* Make sure that MS power level remains constant */
7094 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7095}
7096
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007097/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7098private function f_TC_ms_pwr_ctrl_constant(charstring id)
7099runs on ConnHdlr {
7100 var integer num_blocks := 8;
7101 timer T := int2float(num_blocks);
7102
7103 f_l1_tune(L1CTL);
7104 RSL.clear;
7105
7106 /* These IEs are needed for autonomous MS power control */
7107 var template (value) RSL_IE_List ies := {
7108 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7109 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7110 }),
7111 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7112 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7113 })
7114 };
7115
7116 /* Ensure that 'rx-current' equals 'rx-target' */
7117 f_trxc_fake_rssi(mp_uplink_power_target);
7118
7119 /* Establish a dedicated channel */
7120 f_est_dchan(more_ies := valueof(ies));
7121
7122 L1CTL.clear;
7123 T.start;
7124 alt {
7125 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7126 [] T.timeout {
7127 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7128 num_blocks, " were not handled");
7129 }
7130 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007131
7132 /* Release the channel */
7133 f_rsl_chan_deact();
7134 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007135}
7136testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7137 var ConnHdlr vc_conn;
7138 var ConnHdlrPars pars;
7139
7140 f_init();
7141
7142 /* Explicitly configure the Uplink power target (in dBm) */
7143 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7144
7145 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7146 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7147 log(testcasename(), ": starting on ", pars.chan_nr);
7148
7149 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7150 pars, trxc_comp := true);
7151 vc_conn.done;
7152 }
7153
7154 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7156}
7157
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007158/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7159private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7160runs on ConnHdlr {
7161 var integer num_blocks := 16;
7162 timer T := int2float(num_blocks);
7163
7164 f_l1_tune(L1CTL);
7165 RSL.clear;
7166
7167 /* These IEs are needed for autonomous MS power control */
7168 var template (value) RSL_IE_List ies := {
7169 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7170 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7171 }),
7172 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7173 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7174 })
7175 };
7176
7177 /* Ensure that 'rx-current' equals 'rx-target' */
7178 f_trxc_fake_rssi(mp_uplink_power_target);
7179
7180 /* Establish a dedicated channel */
7181 f_est_dchan(more_ies := valueof(ies));
7182
7183 L1CTL.clear;
7184 T.start;
7185 alt {
7186 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7187 [] T.timeout {
7188 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7189 num_blocks, " were not handled");
7190 }
7191 }
Vadim Yanitskiy6b4404a2021-06-17 17:22:56 +02007192
7193 /* Release the channel */
7194 f_rsl_chan_deact();
7195 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007196}
7197testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7198 var ConnHdlr vc_conn;
7199 var ConnHdlrPars pars;
7200
7201 f_init();
7202
7203 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7204 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7205 /* Explicitly configure the Uplink power range (target and delte) */
7206 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7207 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7208
7209 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7210 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7211 log(testcasename(), ": starting on ", pars.chan_nr);
7212
7213 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7214 pars, trxc_comp := true);
7215 vc_conn.done;
7216 }
7217
7218 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7220}
7221
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007222private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7223 var template L1ctlDlMessage tr_bad_frame;
7224 var L1ctlDlMessage l1_dl;
7225 timer T := 8.0;
7226
7227 f_l1_tune(L1CTL);
7228 RSL.clear;
7229
7230 f_est_dchan();
7231
7232 /* There may be a few errors right after the channel activation */
7233 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7234 L1CTL.clear;
7235
7236 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7237 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7238 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7239 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7240 tr_bad_frame.payload := ?;
7241
7242 T.start;
7243 alt {
7244 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7245 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7246 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7247 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7248 }
7249 [] as_l1_sacch();
7250 [] L1CTL.receive { repeat; }
7251 [] T.timeout {
7252 /* We're done, break the loop */
7253 setverdict(pass);
7254 }
7255 }
7256
7257 f_rsl_chan_deact();
7258 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7259}
7260testcase TC_speech_no_rtp_tchf() runs on test_CT {
7261 var ConnHdlr vc_conn;
7262 var ConnHdlrPars pars;
7263
7264 f_init();
7265
7266 /* TS1, TCH/F, V1 (FR codec) */
7267 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7268 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7269 vc_conn.done;
7270}
7271testcase TC_speech_no_rtp_tchh() runs on test_CT {
7272 var ConnHdlr vc_conn;
7273 var ConnHdlrPars pars;
7274
7275 f_init();
7276
7277 /* TS5, TCH/H, V1 (HR codec) */
7278 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7279 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7280 vc_conn.done;
7281}
7282
Harald Welte0472ab42018-03-12 15:02:26 +01007283/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7284/* protocol error as per 44.006 */
7285/* link layer failure (repetition of I-frame N200 times without ACK */
7286/* repetition of SABM or DISC N200 times without ACK */
7287/* receptiom of SABM in multi-frame established state */
7288
7289
Harald Welte68e495b2018-02-25 00:05:57 +01007290/* TODO Areas:
7291
7292* channel activation
7293** with BS_Power / MS_Power, bypassing power control loop
7294** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007295** with timing advance from initial activation on
7296* mode modify
7297** encryption
7298** multirate
7299* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007300** unsupported algorithm
7301* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007302* BS Power Control
7303* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007304* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007305* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007306** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007307* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007308** DATA_IND from BTS->PCU
7309** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007310
7311*/
Harald Welte70767382018-02-21 12:16:40 +01007312
7313control {
7314 execute( TC_chan_act_stress() );
7315 execute( TC_chan_act_react() );
7316 execute( TC_chan_deact_not_active() );
7317 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007318 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007319 execute( TC_sacch_filling() );
7320 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007321 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007322 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007323 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007324 execute( TC_sacch_chan_act_ho_async() );
7325 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007326 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007327 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007328 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007329 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007330 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007331 execute( TC_rach_load_idle_thresh0() );
7332 execute( TC_rach_load_idle_below_thresh() );
7333 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007334 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02007335 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007336 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02007337 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07007338 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01007339 execute( TC_meas_res_sign_tchf() );
7340 execute( TC_meas_res_sign_tchh() );
7341 execute( TC_meas_res_sign_sdcch4() );
7342 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007343 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007344 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007345 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007346 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007347 execute( TC_rsl_bs_pwr_static_ass() );
7348 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007349 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007350 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007351 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007352 execute( TC_rsl_ms_pwr_dyn_up() );
7353 execute( TC_rsl_ms_pwr_dyn_down() );
7354 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7355 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007356 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007357 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007358 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007359 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007360 execute( TC_paging_imsi_80percent() );
7361 execute( TC_paging_tmsi_80percent() );
7362 execute( TC_paging_imsi_200percent() );
7363 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007364 execute( TC_rsl_protocol_error() );
7365 execute( TC_rsl_mand_ie_error() );
7366 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007367 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007368 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007369 execute( TC_si_sched_2bis() );
7370 execute( TC_si_sched_2ter() );
7371 execute( TC_si_sched_2ter_2bis() );
7372 execute( TC_si_sched_2quater() );
7373 execute( TC_si_sched_13() );
7374 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007375 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007376 execute( TC_ipa_crcx_twice_not_active() );
7377 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007378 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007379 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007380
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007381 if (mp_pcu_socket != "") {
7382 execute( TC_pcu_act_req() );
7383 execute( TC_pcu_act_req_wrong_ts() );
7384 execute( TC_pcu_act_req_wrong_bts() );
7385 execute( TC_pcu_act_req_wrong_trx() );
7386 execute( TC_pcu_deact_req() );
7387 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01007388 execute( TC_pcu_ver_si1() );
7389 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007390 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007391 if (mp_l1_supports_gprs) {
7392 execute( TC_pcu_data_req_pdtch() );
7393 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007394 execute( TC_pcu_data_req_wrong_bts() );
7395 execute( TC_pcu_data_req_wrong_trx() );
7396 execute( TC_pcu_data_req_wrong_ts() );
7397 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007398 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007399 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007400 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007401 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007402 execute( TC_pcu_data_req_imm_ass_pch() );
7403 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007404 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007405 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007406 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007407 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007408 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007409 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007410 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007411 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007412 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007413 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007414 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007415 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007416 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007417 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007418 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007419 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007420 execute( TC_dyn_osmo_pdch_act_deact() );
7421 execute( TC_dyn_osmo_pdch_double_act() );
7422 execute( TC_dyn_ipa_pdch_act_deact() );
7423 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01007424 execute( TC_pcu_info_ind_fh_params() );
7425 execute( TC_pcu_socket_nsvc_ipv4() );
7426 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01007427 execute( TC_pcu_socket_two_nsvc() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007428 } else {
7429 log("PCU socket path not available, skipping PCU tests");
7430 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007431
Harald Welte3d04ae62018-04-04 20:29:05 +02007432 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007433 execute( TC_dyn_osmo_pdch_tchf_act() );
7434 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007435 execute( TC_dyn_ipa_pdch_tchf_act() );
7436 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007437
7438 execute( TC_rll_est_ind() );
7439 execute( TC_rll_est_req_DCCH_3() );
7440 execute( TC_rll_est_req_ACCH_3() );
7441 execute( TC_rll_rel_ind_DCCH_0() );
7442 execute( TC_rll_rel_ind_DCCH_3() );
7443 execute( TC_rll_rel_ind_ACCH_0() );
7444 execute( TC_rll_rel_ind_ACCH_3() );
7445 execute( TC_rll_rel_req() );
7446 execute( TC_rll_unit_data_req_DCCH() );
7447 execute( TC_rll_unit_data_req_ACCH() );
7448 execute( TC_rll_unit_data_ind_DCCH() );
7449 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007450
7451 execute( TC_chan_act_a51() );
7452 execute( TC_chan_act_a52() );
7453 execute( TC_chan_act_a53() );
7454 execute( TC_encr_cmd_a51() );
7455 execute( TC_encr_cmd_a52() );
7456 execute( TC_encr_cmd_a53() );
7457
Harald Welteee25aae2019-05-19 14:32:37 +02007458 execute( TC_err_rep_wrong_mdisc() );
7459 execute( TC_err_rep_wrong_msg_type() );
7460 execute( TC_err_rep_wrong_sequence() );
7461
Harald Weltee613f962018-04-18 22:38:16 +02007462 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007463
7464 execute( TC_tch_sign_l2_fill_frame() );
7465 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007466
7467 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007468 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007469
7470 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007471 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007472
7473 execute( TC_speech_no_rtp_tchf() );
7474 execute( TC_speech_no_rtp_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007475}
7476
7477
7478}