blob: ee5258c36dd83671553edfee68d33c5ef44196f0 [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 }
3600 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003601 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003602 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003603 [] T_itv.timeout {
3604 /* Send paging cmds based on elapsed time */
3605 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3606 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003607 var MobileIdentityV mi;
3608
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003609 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003610 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003611 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003612 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003613 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003614 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003615
3616 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003617 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 +02003618
3619 st.num_paging_sent := st.num_paging_sent + 1;
3620 }
3621 if (st.num_paging_sent < pkt_total) {
3622 /* Wait for interval to next PAGING COMMAND */
3623 var float time_now := T_total.read;
3624 var float next_sched := int2float(st.num_paging_sent)*interval;
3625 if (next_sched > time_now) {
3626 T_itv.start(next_sched - time_now);
3627 } else {
3628 T_itv.start(0.0);
3629 }
3630 } else {
3631 /* We are done, no need to keep counting */
3632 T_total.stop;
3633 }
3634 }
3635 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003636 }
3637 }
3638
3639 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3640 timer T_wait := 18.0;
3641 T_wait.start;
3642 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003643 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003644 [] L1CTL.receive { repeat; }
3645 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003646 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3647 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003648 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003650 }
Harald Welte68e495b2018-02-25 00:05:57 +01003651 }
3652
3653 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3654 " rcvd_ids=", st.num_paging_rcv_ids);
3655 return st;
3656}
3657
3658/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3659 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3660 * - that CCCH LOAD IND (PCH) are being generated
3661 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3662testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003663 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003664 var PagingTestCfg cfg := {
3665 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003666 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003667 load_factor := 0.8,
3668 exp_load_ind := true,
3669 exp_overload := false,
3670 use_tmsi := false
3671 };
3672 var PagingTestState st := f_TC_paging(cfg);
3673 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003674 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3675 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003676 } else {
3677 setverdict(pass);
3678 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003679 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003680}
3681
3682/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3683 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3684 * - that CCCH LOAD IND (PCH) are being generated
3685 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3686testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003687 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003688 var PagingTestCfg cfg := {
3689 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003690 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003691 load_factor := 0.8,
3692 exp_load_ind := true,
3693 exp_overload := false,
3694 use_tmsi := true
3695 };
3696 var PagingTestState st := f_TC_paging(cfg);
3697 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3699 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003700 } else {
3701 setverdict(pass);
3702 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003704}
3705
3706/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3707 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3708 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3709 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3710testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003711 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003712 var PagingTestCfg cfg := {
3713 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003714 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003715 load_factor := 2.0,
3716 exp_load_ind := true,
3717 exp_overload := true,
3718 use_tmsi := false
3719 };
3720 var PagingTestState st := f_TC_paging(cfg);
3721 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3722 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003723 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003724 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003725 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 +01003726 } else {
3727 setverdict(pass);
3728 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003729 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003730}
3731
3732/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3733 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3734 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3735 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3736testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003737 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003738 var PagingTestCfg cfg := {
3739 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003740 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003741 load_factor := 2.0,
3742 exp_load_ind := true,
3743 exp_overload := true,
3744 use_tmsi := true
3745 };
3746 var PagingTestState st := f_TC_paging(cfg);
3747 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3748 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003749 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003750 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003751 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 +01003752 } else {
3753 setverdict(pass);
3754 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003755 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003756}
3757
3758
Harald Welte93640c62018-02-25 16:59:33 +01003759/***********************************************************************
3760 * Immediate Assignment / AGCH
3761 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003762private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003763 len := 0,
3764 ma := ''B
3765}
Harald Welte93640c62018-02-25 16:59:33 +01003766
Harald Weltee8d750e2018-06-10 21:41:35 +02003767private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3768 return int2str(num_tx) & " sent, "
3769 & int2str(num_rx) & " received, "
3770 & int2str(num_del) & " deleted";
3771}
3772
3773private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3774 var L1ctlDlMessage l1_dl;
3775 timer T := 10.0;
3776 var integer num_tx := 0;
3777 var integer num_rx := 0;
3778 var integer num_del := 0;
3779 var charstring res_str;
3780 var float rx_ratio;
3781
Harald Welte10474062019-05-30 16:48:17 +02003782 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003783 f_init_l1ctl();
3784 f_l1_tune(L1CTL);
3785
3786 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiy42d8bd52020-11-15 20:41:02 +07003787 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0),
Vadim Yanitskiy3191d732020-11-15 20:45:01 +07003788 mp_trx_pars[0].arfcn,
3789 mp_tsc_def));
Harald Weltee8d750e2018-06-10 21:41:35 +02003790 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3791 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003792 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003793 num_tx := num_tx+1;
3794 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003795 }
3796 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003797 T.start;
3798 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003799 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003800 num_del := num_del+1;
3801 repeat;
3802 }
3803 [] RSL_CCHAN.receive {
3804 repeat;
3805 }
3806 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003807 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3808 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3809 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003810 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003811 } else {
3812 num_rx := num_rx+1;
3813 }
3814 repeat;
3815 }
3816 [] L1CTL.receive { repeat; }
3817 [] T.timeout { }
3818 }
3819 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3820 log("AGCH test: " & res_str);
3821 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003823 }
3824 rx_ratio := int2float(num_rx) / int2float(num_tx);
3825 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003826 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 +02003827 } else {
3828 setverdict(pass);
3829 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003830 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003831}
3832
Harald Weltee8d750e2018-06-10 21:41:35 +02003833/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3834testcase TC_imm_ass_1000_20ms() runs on test_CT {
3835 f_TC_imm_ass(1000, 0.02, 0.25);
3836}
3837
3838/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3839testcase TC_imm_ass_200_0ms() runs on test_CT {
3840 f_TC_imm_ass(200, 0.0, 0.05);
3841}
3842
3843/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3844testcase TC_imm_ass_200_76ms() runs on test_CT {
3845 f_TC_imm_ass(150, 0.076, 1.00);
3846}
3847
3848
3849
Harald Welte48494ca2018-02-25 16:59:50 +01003850/***********************************************************************
3851 * BCCH
3852 ***********************************************************************/
3853
3854/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003855private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003856 GsmFrameNumber frame_number,
3857 SystemInformation si
3858}
3859
3860/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003861private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003862
3863/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003864private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003865
3866/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003867private function f_si_vecslot_contains(SystemInformationVector arr,
3868 RrMessageType key,
3869 boolean bcch_ext := false)
3870return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003871 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3872 var integer fn_mod51 := arr[i].frame_number mod 51;
3873 if (not bcch_ext and fn_mod51 == 2 or
3874 bcch_ext and fn_mod51 == 6) {
3875 if (arr[i].si.header.message_type == key) {
3876 return true;
3877 }
3878 }
3879 }
3880 return false;
3881}
3882
3883/* 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 +07003884private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3885 integer tc, RrMessageType key,
3886 boolean ext_bcch := false)
3887{
Harald Welte48494ca2018-02-25 16:59:50 +01003888 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003890 }
3891}
3892
3893/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003894private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3895 RrMessageType key)
3896return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003897 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3898 if (f_si_vecslot_contains(arr[tc], key) or
3899 f_si_vecslot_contains(arr[tc], key, true)) {
3900 return true;
3901 }
3902 }
3903 return false;
3904}
3905
3906/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003907private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3908 RrMessageType key,
3909 boolean bcch_ext := false,
3910 integer n := 1, integer m := 4)
3911return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003912 var integer count := 0;
3913 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003914 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3915 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003916 }
3917 for (var integer i:= 0; i < m; i := i + 1) {
3918 var integer fn_mod51 := arr[i].frame_number mod 51;
3919 if (not bcch_ext and fn_mod51 == 2 or
3920 bcch_ext and fn_mod51 == 6) {
3921 if (arr[i].si.header.message_type == key) {
3922 count := count + 1;
3923 }
3924 }
3925 }
3926 if (count >= n) {
3927 return true;
3928 } else {
3929 return false;
3930 }
3931}
3932
3933/* 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 +07003934private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3935 integer tc, RrMessageType key,
3936 boolean ext_bcch := false,
3937 integer n, integer m)
3938{
Harald Welte48494ca2018-02-25 16:59:50 +01003939 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003941 }
3942}
3943
3944/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003945private function f_si_vecslot_contains_only(SystemInformationVector arr,
3946 RrMessageType key,
3947 boolean bcch_ext := false)
3948return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003949 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3950 var integer fn_mod51 := arr[i].frame_number mod 51;
3951 if (not bcch_ext and fn_mod51 == 2 or
3952 bcch_ext and fn_mod51 == 6) {
3953 if (arr[i].si.header.message_type != key) {
3954 return false;
3955 }
3956 }
3957 }
3958 return true;
3959}
3960
3961/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003962private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3963 integer tc, RrMessageType key,
3964 boolean ext_bcch := false)
3965{
Harald Welte48494ca2018-02-25 16:59:50 +01003966 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003967 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003968 }
3969}
3970
3971/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003972private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003973 boolean bcch_extended,
3974 boolean si1_present,
3975 boolean si2bis_present,
3976 boolean si2ter_present,
3977 boolean si2quater_present,
3978 boolean si7_present,
3979 boolean si8_present,
3980 boolean si9_present,
3981 boolean si13_present,
3982 boolean si13alt_present,
3983 boolean si15_present,
3984 boolean si16_present,
3985 boolean si17_present,
3986 boolean si2n_present,
3987 boolean si21_present,
3988 boolean si22_present
3989}
3990
3991/* 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 +07003992private function f_validate_si_scheduling(SystemInformationConfig cfg,
3993 SystemInformationVectorPerTc si_per_tc)
3994{
Harald Welte48494ca2018-02-25 16:59:50 +01003995 var integer i;
3996 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3997 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003998 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003999 }
4000 }
4001 if (cfg.si1_present) {
4002 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
4003 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
4004 * when TC = 0, it can assume that System Information Type 1 is not in use. */
4005 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4006 /* make sure *ALL* contain SI1 */
4007 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
4008 }
4009 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
4010 /* iii) A SI 2 message will be sent at least every time TC = 1 */
4011 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
4012 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
4013 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
4014 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
4015
4016 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
4017 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
4018 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
4019 * consecutive occurrences of TC = 4. */
4020 if (cfg.si2bis_present and not cfg.si2ter_present) {
4021 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4022 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
4023 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
4024 } else if (cfg.si2ter_present and cfg.si2bis_present) {
4025 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
4026 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
4027 }
4028
4029 if (cfg.si7_present or cfg.si8_present) {
4030 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
4031 * if System Information type 4 does not contain all information needed for cell
4032 * selection and reselection. */
4033 if (not cfg.bcch_extended) {
4034 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
4035 }
4036 if (cfg.si7_present) {
4037 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
4038 }
4039 if (cfg.si8_present) {
4040 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
4041 }
4042 }
4043
4044 if (cfg.si2quater_present) {
4045 /* iii) System information type 2 quater is sent if needed, as determined by the system
4046 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
4047 * and 2ter are used, otherwise it shall be sent at least once within any of 4
4048 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
4049 * within any of 4 consecutive occurrences of TC = 5. */
4050 if (not (cfg.bcch_extended)) {
4051 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
4052 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
4053 } else {
4054 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
4055 }
4056 } else {
4057 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
4058 }
4059 }
4060 if (cfg.si9_present) {
4061 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
4062 * in system information type 3 as defined in 3GPP TS 44.018. */
4063 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
4064 }
4065 if (cfg.si13_present) {
4066 /* vii) System Information type 13 is only related to the GPRS service. System Information
4067 * Type 13 need only be sent if GPRS support is indicated in one or more of System
4068 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
4069 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
4070 * In the case that the message is sent on the BCCH Norm, it is sent at least once
4071 * within any of 4 consecutive occurrences of TC=4. */
4072 if (not cfg.bcch_extended) {
4073 log("not-bccch-extended");
4074 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
4075 } else {
4076 log("bccch-extended");
4077 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
4078 }
4079 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004081 }
4082 }
4083 if (cfg.si16_present or cfg.si17_present) {
4084 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
4085 * should not be sent in a cell where network sharing is used (see rule xv). */
4086 if (cfg.si22_present) {
4087 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4088 }
4089 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004091 }
4092 if (not cfg.bcch_extended) {
4093 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
4094 }
4095 if (cfg.si16_present) {
4096 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
4097 }
4098 if (cfg.si17_present) {
4099 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
4100 }
4101 }
4102
4103 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
4104 * broadcast information. The frequency with which they are sent is determined by the
4105 * system operator. System Information type 9 identifies the scheduling of System
4106 * Information type 18 and 20 messages. */
4107
4108 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
4109 * Information Type 19 is present, then its scheduling shall be indicated in System
4110 * Information Type 9. */
4111
4112 if (cfg.si15_present) {
4113 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
4114 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
4115 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
4116 * 4 consecutive occurrences of TC = 1. */
4117 if (not cfg.bcch_extended) {
4118 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
4119 } else {
4120 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
4121 }
4122 }
4123 if (cfg.si13alt_present) {
4124 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
4125 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
4126 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
4127 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
4128 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
4129 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
4130 * of TC = 4. */
4131 if (cfg.si13_present) {
4132 testcase.stop("Error: Cannot have SI13alt and SI13");
4133 }
4134 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004135 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01004136 }
4137 if (not cfg.bcch_extended) {
4138 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
4139 } else {
4140 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
4141 }
4142 }
4143 if (cfg.si2n_present) {
4144 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
4145 * as determined by the system operator. In the case that the message is sent on the
4146 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
4147 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
4148 * consecutive occurrences of TC = 4. */
4149 if (not cfg.bcch_extended) {
4150 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
4151 } else {
4152 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
4153 }
4154 }
4155 if (cfg.si21_present) {
4156 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
4157 * determined by the system operator. If Extended Access Barring is in use in the cell
4158 * then this message is sent at least once within any of 4 consecutive occurrences of
4159 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
4160 * cell then this message shall only be sent on BCCH Ext. */
4161 if (not cfg.bcch_extended) {
4162 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
4163 } else {
4164 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
4165 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01004167 }
4168 }
4169 }
4170 if (cfg.si22_present) {
4171 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
4172 * should not be sent in a cell where SoLSA is used (see rule viii). System
4173 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
4174 * =2 and TC=6. */
4175 if (cfg.si16_present or cfg.si17_present) {
4176 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
4177 }
4178 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
4179 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004180 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01004181 }
4182 if (not cfg.bcch_extended) {
4183 testcase.stop("Error: SI22 requires BCCH Extd!");
4184 } else {
4185 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
4186 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
4187 }
4188 }
4189}
4190
4191/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07004192private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
4193return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01004194 timer T := duration;
4195 var SystemInformationVectorPerTc si_per_tc;
4196 var L1ctlDlMessage l1_dl;
4197
4198 /* initialize all per-TC vectors empty */
4199 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4200 si_per_tc[i] := {};
4201 }
4202
4203 /* flush all previous L1 queued msgs */
4204 pt.clear;
4205
4206 T.start;
4207 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004208 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004209 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
4210 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
4211 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01004212 repeat;
4213 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07004214
Harald Welte48494ca2018-02-25 16:59:50 +01004215 var integer tc := f_gsm_compute_tc(sig.frame_number);
4216 log("SI received at TC=", tc, ": ", sig.si);
4217 /* append to the per-TC bucket */
4218 si_per_tc[tc] := si_per_tc[tc] & { sig };
4219 repeat;
4220 }
4221 [] pt.receive { repeat; }
4222 [] T.timeout { }
4223 }
4224
4225 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4226 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4227 }
4228 log("si_per_tc=", si_per_tc);
4229 return si_per_tc;
4230}
4231
4232/* helper function: Set given SI via RSL + validate scheduling.
4233 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004234private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004235 var SystemInformationVectorPerTc si_per_tc;
4236 f_init_l1ctl();
4237 f_l1_tune(L1CTL);
4238
4239 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004240 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004241 f_validate_si_scheduling(si_cfg, si_per_tc);
4242
4243 setverdict(pass);
4244}
4245
4246testcase TC_si_sched_default() runs on test_CT {
4247 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004248 /* 2+3+4 are mandatory and set in f_init() */
4249 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004250 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004251}
4252
4253testcase TC_si_sched_1() runs on test_CT {
4254 f_init();
4255 si_cfg.si1_present := true;
4256 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004257 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004259}
4260
4261testcase TC_si_sched_2bis() runs on test_CT {
4262 f_init();
4263 si_cfg.si2bis_present := true;
4264 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4265 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004267}
4268
4269testcase TC_si_sched_2ter() runs on test_CT {
4270 f_init();
4271 si_cfg.si2ter_present := true;
4272 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4273 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004274 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004275}
4276
4277testcase TC_si_sched_2ter_2bis() runs on test_CT {
4278 f_init();
4279 si_cfg.si2bis_present := true;
4280 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4281 si_cfg.si2ter_present := true;
4282 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4283 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004285}
4286
4287testcase TC_si_sched_2quater() runs on test_CT {
4288 f_init();
4289 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004290 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004291 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004292 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004293}
4294
4295testcase TC_si_sched_13() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004296 /* NOTE: PCUIF connection is not used in this test case, but
4297 * without it the IUT would not broadcast SI13 (see OS#3075). */
4298 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004299 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004300 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004301 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004302 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004303}
4304
4305testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004306 /* NOTE: PCUIF connection is not used in this test case, but
4307 * without it the IUT would not broadcast SI13 (see OS#3075). */
4308 f_init_with_pcuif();
Harald Welte48494ca2018-02-25 16:59:50 +01004309 si_cfg.si2bis_present := true;
4310 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4311 si_cfg.si2ter_present := true;
4312 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4313 si_cfg.si2quater_present := true;
Vadim Yanitskiy3bb3b602020-10-24 21:24:05 +07004314 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607b10004864982eddb8d555867ee3c95540b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004315 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004316 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004317 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004319}
4320
4321
Harald Welte68e495b2018-02-25 00:05:57 +01004322testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004323 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004324 /* FIXME: enable / disable individual BCCH info */
4325 //ts_RSL_BCCH_INFO(si_type, info);
4326 /* expect no ERROR REPORT after either of them *
4327 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004329}
4330
Harald Welte93640c62018-02-25 16:59:33 +01004331/***********************************************************************
4332 * Low-Level Protocol Errors / ERROR REPORT
4333 ***********************************************************************/
4334
Harald Welte01d982c2018-02-25 01:31:40 +01004335private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4336 timer T := 5.0;
4337 T.start;
4338 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004339 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004340 setverdict(pass);
4341 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004342 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004344 }
4345 [] RSL_CCHAN.receive {
4346 repeat;
4347 }
4348 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004349 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004350 }
4351 }
4352}
4353
4354/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4355testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004356 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004357 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4358 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004359 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004360
4361 f_exp_err_rep(RSL_ERR_PROTO);
4362}
4363
4364/* Provoke a mandatory IE error and match on ERROR REPORT */
4365testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004366 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004367
4368 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4369 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004370 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004371
4372 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4373}
4374
4375/* Provoke an IE content error and match on ERROR REPORT */
4376testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004377 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004378 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4379 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004380 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004381
4382 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4383}
4384
Harald Welteee25aae2019-05-19 14:32:37 +02004385/* attempt to activate channel with wrong RSL Message Discriminator IE */
4386function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4387 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4388 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4389 RSL.send(rsl);
4390 f_rslem_unregister(0, g_chan_nr);
4391}
4392testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4393 var ConnHdlr vc_conn;
4394 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4395
Harald Welte10474062019-05-30 16:48:17 +02004396 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004397
4398 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4399 vc_conn.done;
4400 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4401
4402 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4403}
4404
4405/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004406private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004407 var template (value) RSL_Message rsl_tx;
4408 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4409 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4410 RSL.send(rsl_tx);
4411 f_rslem_unregister(0, g_chan_nr);
4412}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004413private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004414 var template (value) RSL_Message rsl_tx;
4415 /* we first have to activate the dedicated channel */
4416 f_rsl_chan_act(g_pars.chan_mode);
4417 /* ... to then send an invalid RLL message */
4418 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4419 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4420 RSL.send(rsl_tx);
4421 f_rslem_unregister(0, g_chan_nr);
4422}
4423testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4424 var ConnHdlr vc_conn;
4425 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4426 var template (value) RSL_Message rsl_tx;
4427
Harald Welte10474062019-05-30 16:48:17 +02004428 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004429
4430 /* Common Channel with wrong message type */
4431 RSL_CCHAN.clear;
4432 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4433 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004434 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004435 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4436
4437 /* TRX Management */
4438 RSL_CCHAN.clear;
4439 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4440 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004441 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004442 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4443
4444 /* Dedicated Channel */
4445 RSL_CCHAN.clear;
4446 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4447 vc_conn.done;
4448 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4449
4450 /* RLL */
4451 RSL_CCHAN.clear;
4452 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4453 vc_conn.done;
4454 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4455}
4456
4457/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004458private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004459 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4460 f_rslem_unregister(0, g_chan_nr);
4461}
4462testcase TC_err_rep_wrong_sequence() runs on test_CT {
4463 var ConnHdlr vc_conn;
4464 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4465
Harald Welte10474062019-05-30 16:48:17 +02004466 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004467
4468 RSL_CCHAN.clear;
4469 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4470 vc_conn.done;
4471 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4472}
4473
Harald Welte93640c62018-02-25 16:59:33 +01004474/***********************************************************************
4475 * IPA CRCX/MDCX/DLCS media stream handling
4476 ***********************************************************************/
4477
Harald Weltea871a382018-02-25 02:03:14 +01004478/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004479private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004480 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4481 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004482}
4483testcase TC_ipa_dlcx_not_active() runs on test_CT {
4484 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004485 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004486 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4487 vc_conn.done;
4488}
Harald Welte68e495b2018-02-25 00:05:57 +01004489
Harald Weltea3f1df92018-02-25 12:49:55 +01004490/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004491private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004492 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4493 "IPA CRCX ACK");
4494 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4495 "IPA CRCX NACK");
4496}
4497testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4498 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004499 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004500 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4501 vc_conn.done;
4502}
4503
4504/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004505private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004506 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4507 "IPA CRCX ACK");
4508 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4509 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4510 var uint7_t rtp_pt2 := f_rnd_int(127);
4511 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4512 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4513 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4514 "IPA MDCX ACK");
4515 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4516 "IPA DLCX ACK");
4517}
4518testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4519 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004520 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004521 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4522 vc_conn.done;
4523}
4524
Harald Welte3ae11da2018-02-25 13:36:06 +01004525/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004526private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004527 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4528 "IPA CRCX ACK");
4529 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4530 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4531 var uint7_t rtp_pt2 := f_rnd_int(127);
4532 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4533 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4534 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4535 "IPA MDCX ACK");
4536 /* Second MDCX */
4537 remote_ip := f_rnd_int(c_UINT32_MAX);
4538 remote_port := f_rnd_int(c_UINT16_MAX);
4539 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4540 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4541 "IPA MDCX ACK");
4542 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4543 "IPA DLCX ACK");
4544}
4545testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4546 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004547 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004548 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4549 vc_conn.done;
4550}
4551
Harald Welte9912eb52018-02-25 13:30:15 +01004552/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004553private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004554 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4555 "IPA CRCX NACK");
4556}
4557testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4558 var ConnHdlrPars pars;
4559 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004560 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004561
4562 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4563 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4564 vc_conn.done;
4565
4566 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), 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
Harald Weltea3f1df92018-02-25 12:49:55 +01004571
Harald Welte883340c2018-02-28 18:59:29 +01004572/***********************************************************************
4573 * PCU Socket related tests
4574 ***********************************************************************/
4575
Harald Welte07bd2d22019-05-25 11:03:30 +02004576/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004577friend 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 +01004578runs on test_CT {
4579 timer T := 3.0;
4580
4581 /* we don't expect any RTS.req before PDCH are active */
4582 T.start;
4583 alt {
4584 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004585 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004586 }
4587 [] PCU.receive { repeat; }
4588 [] T.timeout { }
4589 }
4590
4591 /* Send PDCH activate request for known PDCH timeslot */
4592 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4593
4594 /* we now expect RTS.req for this timeslot (only) */
4595 T.start;
4596 alt {
4597 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4598 setverdict(pass);
4599 }
4600 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4601 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004603 }
4604 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004606 }
4607 [] PCU.receive { repeat; }
4608 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004609 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004610 }
4611 [not exp_success] T.timeout {
4612 setverdict(pass);
4613 }
4614 }
4615}
4616
Harald Welte07bd2d22019-05-25 11:03:30 +02004617/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004618friend 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 +01004619runs on test_CT {
4620 timer T := 3.0;
4621
4622 /* Send PDCH activate request for known PDCH timeslot */
4623 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 +02004624 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4625 * when it will actually have been executed in the BTS */
4626 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004627 PCU.clear;
4628 /* we now expect no RTS.req for this timeslot */
4629 T.start;
4630 alt {
4631 [] 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 +02004632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004633 }
4634 [] PCU.receive { repeat; }
4635 [] T.timeout {
4636 setverdict(pass);
4637 }
4638 }
4639}
4640
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004641friend function f_init_with_pcuif() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004642 f_init();
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01004643 map(self:PCU, system:PCU);
4644 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
Max2c6f5632019-03-18 17:25:17 +01004645 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4646}
4647
Harald Welte883340c2018-02-28 18:59:29 +01004648/* PDCH activation via PCU socket; check for presence of RTS.req */
4649testcase TC_pcu_act_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004650 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004651
Harald Welte883340c2018-02-28 18:59:29 +01004652 f_TC_pcu_act_req(0, 0, 7, true);
4653}
4654
4655/* PDCH activation via PCU socket on non-PDCU timeslot */
4656testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004657 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004658
Harald Welte883340c2018-02-28 18:59:29 +01004659 f_TC_pcu_act_req(0, 0, 1, false);
4660}
4661
4662/* PDCH activation via PCU socket on wrong BTS */
4663testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004664 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004665
Harald Welte883340c2018-02-28 18:59:29 +01004666 f_TC_pcu_act_req(23, 0, 7, false);
4667}
4668
4669/* PDCH activation via PCU socket on wrong TRX */
4670testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004671 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004672
Harald Welte883340c2018-02-28 18:59:29 +01004673 f_TC_pcu_act_req(0, 23, 7, false);
4674}
4675
4676/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4677testcase TC_pcu_deact_req() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004678 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004679
Harald Welte883340c2018-02-28 18:59:29 +01004680 /* Activate PDCH */
4681 f_TC_pcu_act_req(0, 0, 7, true);
4682 f_sleep(1.0);
4683 /* and De-Activate again */
4684 f_TC_pcu_deact_req(0, 0, 7);
4685}
4686
4687/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4688testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004689 f_init_with_pcuif();
Max2c6f5632019-03-18 17:25:17 +01004690
Harald Welte883340c2018-02-28 18:59:29 +01004691 f_TC_pcu_deact_req(0, 0, 1);
4692}
4693
4694/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
Philipp Maier94c08482021-02-01 17:36:05 +01004695function f_TC_pcu_ver_siXX(octetstring si, RSL_IE_SysinfoType rsl_si_type) runs on test_CT {
Harald Welte883340c2018-02-28 18:59:29 +01004696 var PCUIF_send_data sd;
4697 timer T:= 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004698 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01004699
4700 /* Set SI13 via RSL */
Philipp Maier94c08482021-02-01 17:36:05 +01004701 f_rsl_bcch_fill_raw(rsl_si_type, si);
Max2c6f5632019-03-18 17:25:17 +01004702
Harald Welte883340c2018-02-28 18:59:29 +01004703 T.start;
4704 alt {
4705 [] 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 +01004706 if (substr(sd.data.u.data_ind.data, 0, lengthof(si)) == si) {
Harald Welte883340c2018-02-28 18:59:29 +01004707 setverdict(pass);
4708 } else {
4709 repeat;
4710 }
4711 }
4712 [] PCU.receive { repeat; }
4713 [] T.timeout {
Philipp Maier94c08482021-02-01 17:36:05 +01004714 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI");
Harald Welte883340c2018-02-28 18:59:29 +01004715 }
4716 }
4717}
4718
Philipp Maier94c08482021-02-01 17:36:05 +01004719/* Test the PCU->BTS Version and BTS->PCU SI1 handshake */
4720testcase TC_pcu_ver_si1() runs on test_CT {
4721 const octetstring si1 := '550111132A252B27CC29AA11BB33CC'O;
4722 f_TC_pcu_ver_siXX(si1, RSL_SYSTEM_INFO_1);
4723}
4724
4725/* Test the PCU->BTS Version and BTS->PCU SI3 handshake */
4726testcase TC_pcu_ver_si3() runs on test_CT {
4727 const octetstring si3 := '49012223242526272929AABBCC'O;
4728 f_TC_pcu_ver_siXX(si3, RSL_SYSTEM_INFO_3);
4729}
4730
4731/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4732testcase TC_pcu_ver_si13() runs on test_CT {
4733 const octetstring si13 := '01010203040506070909'O;
4734 f_TC_pcu_ver_siXX(si13, RSL_SYSTEM_INFO_13);
4735}
4736
Harald Welte883340c2018-02-28 18:59:29 +01004737private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4738
4739/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004740friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004741 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4742runs on test_CT
4743{
4744 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4745 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4746}
4747
4748/* 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 +02004749friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4750 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004751runs on test_CT
4752{
4753 var PCUIF_send_data sd;
4754
4755 timer T := 3.0;
4756 T.start;
4757 alt {
4758 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4759 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4760 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4761 sd.data.u.rts_req.fn, sapi, data);
4762 }
4763 [] PCU.receive { repeat; }
4764 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004765 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004766 }
4767 }
4768}
4769
4770/* Send DATA.req on invalid BTS */
4771testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004772 var TfiUsfArr tua := f_TfiUsfArrInit();
4773 var octetstring data := '0000'O & f_rnd_octstring(21);
4774
4775 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004776
Harald Welte883340c2018-02-28 18:59:29 +01004777 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004778 f_TfiUsfArrSet(tua, 7, 0);
4779 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4780 f_sleep(1.0);
4781
4782 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004783}
4784
4785/* Send DATA.req on invalid TRX */
4786testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004787 var TfiUsfArr tua := f_TfiUsfArrInit();
4788 var octetstring data := '0000'O & f_rnd_octstring(21);
4789
4790 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004791
Harald Welte883340c2018-02-28 18:59:29 +01004792 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004793 f_TfiUsfArrSet(tua, 7, 0);
4794 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4795 f_sleep(1.0);
4796
4797 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004798}
4799
4800/* Send DATA.req on invalid timeslot */
4801testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004802 var TfiUsfArr tua := f_TfiUsfArrInit();
4803 var octetstring data := '0000'O & f_rnd_octstring(21);
4804
4805 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004806
Harald Welte883340c2018-02-28 18:59:29 +01004807 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004808 f_TfiUsfArrSet(tua, 7, 0);
4809 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4810 f_sleep(1.0);
4811
4812 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004813}
4814
4815/* Send DATA.req on timeslot that hasn't been activated */
4816testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004817 var TfiUsfArr tua := f_TfiUsfArrInit();
4818 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004819
Harald Welte7162a612019-05-26 12:56:09 +02004820 f_virtphy_common();
4821
4822 f_TfiUsfArrSet(tua, 7, 0);
4823 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4824 f_sleep(1.0);
4825
4826 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004827}
4828
Harald Weltead033dc2019-05-25 17:28:16 +02004829private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004830 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4831 boolean wait_rts := true)
4832runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004833 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004834 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004835
4836 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004837 if (wait_rts) {
4838 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4839 } else {
4840 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4841 }
Harald Weltead033dc2019-05-25 17:28:16 +02004842
4843 T.start;
4844 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004845 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004846 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4847 setverdict(pass);
4848 }
Harald Welte7162a612019-05-26 12:56:09 +02004849 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4850 setverdict(fail, "Received unexpected ", rx_dl);
4851 }
Harald Weltead033dc2019-05-25 17:28:16 +02004852 [] L1CTL.receive {
4853 repeat;
4854 }
Harald Welte7162a612019-05-26 12:56:09 +02004855 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004856 setverdict(fail, "Timeout waiting for ", data);
4857 }
Harald Welte7162a612019-05-26 12:56:09 +02004858 [not expect_data] T.timeout {
4859 setverdict(pass);
4860 }
Harald Weltead033dc2019-05-25 17:28:16 +02004861 }
4862}
4863
4864private function f_disable_dynamic_ts() runs on test_CT
4865{
4866 f_init_vty_bsc();
4867 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4868 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4869 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4870 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004871 f_init_with_pcuif();
Harald Weltead033dc2019-05-25 17:28:16 +02004872}
4873
4874private function f_virtphy_common() runs on test_CT {
4875 f_disable_dynamic_ts();
4876 f_init_l1ctl();
4877 f_l1_tune(L1CTL);
4878}
4879
4880testcase TC_pcu_data_req_pdtch() runs on test_CT {
4881 var TfiUsfArr tua := f_TfiUsfArrInit();
4882 var octetstring data := '0000'O & f_rnd_octstring(21);
4883
4884 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004885
Harald Welte883340c2018-02-28 18:59:29 +01004886 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004887 f_TfiUsfArrSet(tua, 7, 0);
4888 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4889 f_sleep(1.0);
4890
4891 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004892}
4893
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004894/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004895testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004896 var TfiUsfArr tua := f_TfiUsfArrInit();
4897 var octetstring data := '0000'O & f_rnd_octstring(21);
4898
4899 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004900
Harald Welte883340c2018-02-28 18:59:29 +01004901 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004902 f_TfiUsfArrSet(tua, 7, 0);
4903 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4904 f_sleep(1.0);
4905
4906 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004907}
4908
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004909private function f_TC_pcu_ptcch_ul(uint16_t ra)
4910runs on test_CT {
4911 var template PCUIF_Message pcu_rach_ind;
4912 var PCUIF_send_data sd;
4913 var GsmFrameNumber fn;
4914 timer T;
4915
4916 /* Send an Access Burst on PTCCH/U over the Um-interface */
4917 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4918 chan_nr := ts_RslChanNr_PDCH(7),
4919 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4920
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004921 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4922 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004923
4924 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4925 T.start(52.0 * 4.615 / 1000.0);
4926 alt {
4927 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4928 log("Rx an Access Burst on the PCU interface: ", sd.data);
4929 setverdict(pass);
4930 T.stop;
4931 }
4932 [] PCU.receive { repeat; }
4933 [] T.timeout {
4934 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4935 /* Keep going, that's not the end of the world */
4936 }
4937 }
4938}
4939
4940testcase TC_pcu_ptcch() runs on test_CT {
4941 var L1ctlDlMessage dl;
4942 var octetstring data;
4943 timer T;
4944
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01004945 f_init_with_pcuif();
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004946 f_init_l1ctl();
4947 f_l1_tune(L1CTL);
4948
4949 /* Activate PDCH channel on TS7 */
4950 f_TC_pcu_act_req(0, 0, 7, true);
4951
4952 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004953 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004954 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004955 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004956 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004957
4958 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4959 for (var integer i := 0; i < 16; i := i + 1) {
4960 log("Sending an Access Burst towards the L1CTL interface");
4961 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4962 }
4963
4964 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4965 data := f_rnd_octstring(23);
4966
4967 /* Verify PTCCH/D: send a random data block, make sure it's received */
4968 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4969 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4970
4971 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4972 * let's give it more time in case if we miss the beginning. */
4973 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4974 alt {
4975 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4976 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4977 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4978 frame := data)) -> value dl {
4979 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4980 setverdict(pass);
4981 T.stop;
4982 }
4983 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4984 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4985 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4986 l2_data := data)) -> value dl {
4987 log("Rx PTCCH/D data block on L1CTL: ", dl);
4988 setverdict(pass);
4989 T.stop;
4990 }
4991 [] L1CTL.receive { repeat; }
4992 [] T.timeout {
4993 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4994 }
4995 }
4996}
4997
Harald Welte883340c2018-02-28 18:59:29 +01004998/* Send AGCH from PCU; check it appears on Um side */
4999testcase TC_pcu_data_req_agch() runs on test_CT {
5000 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005001 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005002 f_init_l1ctl();
5003 f_l1_tune(L1CTL);
5004
5005 f_TC_pcu_act_req(0, 0, 7, true);
5006 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
5007
5008 T.start;
5009 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005010 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01005011 setverdict(pass);
5012 }
5013 [] L1CTL.receive { repeat; }
5014 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005015 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005016 }
5017 }
5018}
5019
Harald Welte928622b2019-05-26 13:22:59 +02005020/* Send AGCH from PCU; check it appears on Um side */
5021testcase TC_pcu_data_req_pch() runs on test_CT {
5022 timer T := 3.0;
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005023 f_init_with_pcuif();
Harald Welte928622b2019-05-26 13:22:59 +02005024 f_init_l1ctl();
5025 f_l1_tune(L1CTL);
5026
5027 f_TC_pcu_act_req(0, 0, 7, true);
5028 /* three characters prefix: last 3 digits of IMSI as ASCII */
5029 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
5030
5031 T.start;
5032 alt {
5033 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
5034 setverdict(pass);
5035 }
5036 [] L1CTL.receive { repeat; }
5037 [] T.timeout {
5038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
5039 }
5040 }
5041}
5042
Harald Welte883340c2018-02-28 18:59:29 +01005043/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
5044testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
5045 var octetstring imm_ass := f_rnd_octstring(23);
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005046 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005047 f_init_l1ctl();
5048 f_l1_tune(L1CTL);
5049
5050 /* append 3 last imsi digits so BTS can compute pagng group */
5051 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
5052
5053 timer T := 0.5;
5054 T.start;
5055 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01005056 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01005057 /* TODO: verify paging group */
5058 setverdict(pass);
5059 }
5060 [] L1CTL.receive { repeat; }
5061 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01005063 }
5064 }
5065}
5066
5067/* Send RACH from Um side, expect it to show up on PCU socket */
5068testcase TC_pcu_rach_content() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005069 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005070 f_init_l1ctl();
5071 f_l1_tune(L1CTL);
5072
5073 var GsmFrameNumber fn_last := 0;
5074 for (var integer i := 0; i < 1000; i := i+1) {
5075 var OCT1 ra := f_rnd_ra_ps();
5076 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
5077 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005078 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01005079 }
5080 fn_last := fn;
5081
5082 timer T := 2.0;
5083 T.start;
5084 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005085 [] 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 +01005086 T.stop;
5087 }
5088 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005089 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005090 }
5091 [] PCU.receive { repeat; }
5092 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005093 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01005094 }
5095 }
5096 }
5097 setverdict(pass);
5098}
5099
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005100/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
5101 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
5102testcase TC_pcu_ext_rach_content() runs on test_CT {
5103 var template PCUIF_Message pcu_rach_ind;
5104 var GsmFrameNumber fn_last := 0;
5105 var L1ctlRachSynchSeq synch_seq;
5106 var PCUIF_BurstType pcu_bt;
5107 var GsmFrameNumber fn;
5108 var BIT11 ra11;
5109
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005110 f_init_with_pcuif();
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005111 f_init_l1ctl();
5112 f_l1_tune(L1CTL);
5113
5114 for (var integer i := 0; i < 1000; i := i+1) {
5115 /* We need to test both TS1 & TS2 */
5116 if (i rem 2 == 0) {
5117 synch_seq := RACH_SYNCH_SEQ_TS1;
5118 pcu_bt := BURST_TYPE_1;
5119 } else {
5120 synch_seq := RACH_SYNCH_SEQ_TS2;
5121 pcu_bt := BURST_TYPE_2;
5122 }
5123
5124 ra11 := f_rnd_ra11_ps();
5125 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
5126 if (fn == fn_last) {
5127 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5128 "Two RACH in same FN?!?");
5129 }
5130 fn_last := fn;
5131
5132 /* Compose the expected message */
5133 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07005134 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005135 ra := bit2int(ra11),
5136 is_11bit := 1,
5137 burst_type := pcu_bt,
5138 fn := fn);
5139
5140 timer T := 2.0;
5141 T.start;
5142 alt {
5143 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
5144 T.stop;
5145 }
5146 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
5147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
5148 }
5149 [] PCU.receive { repeat; }
5150 [] T.timeout {
5151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
5152 }
5153 }
5154 }
5155 setverdict(pass);
5156}
5157
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005158private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
5159runs on test_CT {
5160 var template PCUIF_send_data sdt;
5161 var PCUIF_send_data sd;
5162 var int16_t lqual_cb;
5163 timer T := 1.0;
5164
5165 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
5166 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
5167
5168 /* Send a random PDTCH frame over Um */
5169 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
5170 '0000'O & f_rnd_octstring(21)));
5171
5172 T.start;
5173 alt {
5174 /* If expected link quality is above the threshold */
5175 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
5176 lqual_cb := sd.data.u.data_ind.lqual_cb;
5177 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
5178
5179 /* Make sure the actual link quality matches the expected value */
5180 if (not match(lqual_cb, lqual_cb_exp)) {
5181 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
5182 "expected value ", lqual_cb_exp));
5183 } else {
5184 setverdict(pass);
5185 }
5186 }
5187 /* If expected link quality is below the threshold */
5188 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
5189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5190 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
5191 }
5192 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
5193 [] PCU.receive { repeat; }
5194 [lqual_cb_exp < thresh] T.timeout {
5195 log("Rx nothing, as expected");
5196 setverdict(pass);
5197 }
5198 [lqual_cb_exp >= thresh] T.timeout {
5199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5200 "Timeout waiting for PCUIF_DATA.ind");
5201 }
5202 }
5203}
5204
5205/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
5206testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005207 f_init_with_pcuif();
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005208 PCU.clear;
5209
5210 f_init_l1ctl();
5211 f_l1_tune(L1CTL);
5212
5213 /* Activate a PDCH channel on TS7 */
5214 f_TC_pcu_act_req(0, 0, 7, true);
5215
5216 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005217 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07005218 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005219 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07005220 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07005221
5222 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
5223 for (var int16_t i := -256; i <= 1280; i := i + 128) {
5224 var TrxcMessage ret;
5225
5226 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
5227 valueof(ts_TRXC_FAKE_CI(i)));
5228
5229 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
5230 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
5231 }
5232}
5233
Harald Welte883340c2018-02-28 18:59:29 +01005234/* Send PAGING via RSL, expect it to shw up on PCU socket */
5235testcase TC_pcu_paging_from_rsl() runs on test_CT {
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005236 f_init_with_pcuif();
Harald Welte883340c2018-02-28 18:59:29 +01005237
5238 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005239 var MobileIdentityLV mi_lv;
5240 var octetstring mi_lv_enc;
5241 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005242 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005243
Harald Welte883340c2018-02-28 18:59:29 +01005244 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005245 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005246 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005247 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005248 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005249
5250 /* Fancy encoding for PCUIF */
5251 mi_lv := valueof(ts_MI_LV(mi));
5252 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5253 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005254
5255 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005256 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005257 T.start;
5258 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005259 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005260 }
5261 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005263 }
5264 [] PCU.receive { repeat; }
5265 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005267 }
5268 }
5269 }
5270 setverdict(pass);
5271}
5272
Harald Welted66c9b82019-05-25 09:03:15 +02005273/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5274testcase TC_pcu_time_ind() runs on test_CT {
5275 var PCUIF_send_data pcu_sd;
5276 var integer num_time_ind := 0;
5277 var integer first_fn, last_fn;
5278 var float test_duration := 5.0;
5279 timer T;
5280
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005281 f_init_with_pcuif();
Harald Welted66c9b82019-05-25 09:03:15 +02005282 f_TC_pcu_act_req(0, 0, 7, true);
5283
5284 PCU.clear;
5285 T.start(test_duration);
5286 alt {
5287 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5288 num_time_ind := num_time_ind + 1;
5289 if (not isbound(first_fn)) {
5290 first_fn := pcu_sd.data.u.time_ind.fn;
5291 }
5292 last_fn := pcu_sd.data.u.time_ind.fn;
5293 repeat;
5294 }
5295 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5296 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5297 repeat;
5298 }
5299 [] PCU.receive {
5300 repeat;
5301 }
5302 [] T.timeout {}
5303 }
5304 var integer fn_expired := last_fn - first_fn;
5305 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5306
5307 /* verify the number of frames expired matches our expectation */
5308 const float c_GSM_FN_DURATION_MS := 4.61538;
5309 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005310 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005311 if (not match(fn_expired, t_fn_expected)) {
5312 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5313 }
5314
5315 /* There are three TIME.ind in every fn MOD 13 */
5316 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5317 /* Add some tolerance */
5318 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5319 if (not match(num_time_ind, t_time_ind_exp)) {
5320 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5321 }
5322
5323 setverdict(pass);
5324}
5325
Harald Welte4832c862019-05-25 14:57:18 +02005326/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5327testcase TC_pcu_rts_req() runs on test_CT {
5328 var PCUIF_send_data pcu_sd;
5329 var integer first_fn, last_fn;
5330 var integer num_rts_pdtch := 0;
5331 var integer num_rts_ptcch := 0;
5332 var float test_duration := 5.0;
5333 timer T;
5334
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005335 f_init_with_pcuif();
Harald Welte4832c862019-05-25 14:57:18 +02005336 f_TC_pcu_act_req(0, 0, 7, true);
5337
5338 PCU.clear;
5339 T.start(test_duration);
5340 alt {
5341 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5342 -> value pcu_sd {
5343 num_rts_pdtch := num_rts_pdtch + 1;
5344 if (not isbound(first_fn)) {
5345 first_fn := pcu_sd.data.u.rts_req.fn;
5346 }
5347 last_fn := pcu_sd.data.u.rts_req.fn;
5348 repeat;
5349 }
5350 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5351 -> value pcu_sd {
5352 num_rts_ptcch := num_rts_ptcch + 1;
5353 if (not isbound(first_fn)) {
5354 first_fn := pcu_sd.data.u.rts_req.fn;
5355 }
5356 last_fn := pcu_sd.data.u.rts_req.fn;
5357 repeat;
5358 }
5359 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5360 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5361 repeat;
5362 }
5363 [] PCU.receive {
5364 repeat;
5365 }
5366 [] T.timeout {}
5367 }
5368 var integer fn_expired := last_fn - first_fn;
5369 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5370 ", num_rts_ptcch=", num_rts_ptcch);
5371
5372 /* verify the number of frames expired matches our expectation */
5373 const float c_GSM_FN_DURATION_MS := 4.61538;
5374 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005375 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005376 if (not match(fn_expired, t_fn_expected)) {
5377 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5378 }
5379
5380 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5381 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5382 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5383 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5384 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5385 t_ptcch_exp);
5386 }
5387
5388 /* We have 12 PDTCH blocks every 52-multiframe */
5389 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5390 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5391 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5392 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5393 t_pdtch_exp);
5394 }
5395
5396 setverdict(pass);
5397}
5398
Harald Welte07bd2d22019-05-25 11:03:30 +02005399/* test for generating Abis side OML ALERT from the PCU */
5400testcase TC_pcu_oml_alert() runs on test_CT {
5401 var PCUIF_send_data pcu_sd;
5402 var integer num_time_ind := 0;
5403 var integer first_fn, last_fn;
5404 var float test_duration := 5.0;
5405 timer T;
5406
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005407 f_init_with_pcuif();
Harald Welte07bd2d22019-05-25 11:03:30 +02005408 f_TC_pcu_act_req(0, 0, 7, true);
5409
5410 /* re-connect CTRL port from BTS to BSC */
5411 f_ipa_ctrl_stop();
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01005412 f_ipa_ctrl_start_client(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
Harald Welte07bd2d22019-05-25 11:03:30 +02005413
5414 /* Send that OML Alert */
5415 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5416
5417 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5418 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5419 setverdict(pass);
5420}
5421
Harald Welteeaa9a862019-05-26 23:01:08 +02005422/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5423private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5424 var PCUIF_Message first_info;
5425 var integer pcu_conn_id := -1;
5426 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5427 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5428 var OCT4 tlli := '01020304'O;
5429 var OCT1 cause := '23'O;
5430 timer T := 5.0;
5431
5432 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5433
5434 f_l1_tune(L1CTL);
5435 RSL.clear;
5436
5437 f_est_dchan();
5438 L1CTL.clear;
5439
5440 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5441
5442 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5443 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5444 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5445
5446 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5447 T.start;
5448 alt {
5449 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5450 setverdict(pass);
5451 }
5452 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5453 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5454 }
5455 [] PCU.receive {
5456 repeat;
5457 }
5458 [] T.timeout {
5459 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5460 }
5461 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005462
5463 /* release the channel */
5464 f_rsl_chan_deact();
5465 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5466 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005467}
5468testcase TC_pcu_rr_suspend() runs on test_CT {
5469 var ConnHdlrPars pars;
5470 var ConnHdlr vc_conn;
5471
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005472 f_init_with_pcuif();
Harald Welteeaa9a862019-05-26 23:01:08 +02005473
5474 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5475 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5476 vc_conn.done;
5477}
Harald Welte07bd2d22019-05-25 11:03:30 +02005478
Harald Weltea2e0e942019-05-27 18:12:53 +02005479/* Ensure that PCUIF socket can accept only a single connection */
5480testcase TC_pcu_socket_connect_multi() runs on test_CT {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005481 var boolean connected := false;
5482 var UD_connect_result cr;
5483 var integer cid;
Harald Weltea2e0e942019-05-27 18:12:53 +02005484 timer T := 5.0;
5485
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005486 var template UD_Result tr_ok := { result_code := SUCCESS, err := omit };
5487 var template UD_Result tr_err := { result_code := ERROR, err := ? };
5488
Harald Weltea2e0e942019-05-27 18:12:53 +02005489 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005490 f_init_with_pcuif();
Harald Weltea2e0e942019-05-27 18:12:53 +02005491
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005492 /* try to establish a second connection */
Harald Weltea2e0e942019-05-27 18:12:53 +02005493 PCU.send(UD_connect:{mp_pcu_socket, -1});
5494 T.start;
5495 alt {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005496 /* the IUT will first accept() the new connection, and close() it immediately */
5497 [not connected] PCU.receive(UD_connect_result:{ id := ?, result := tr_ok }) -> value cr {
5498 log("BTS has accept()ed connection");
5499 connected := true;
5500 cid := cr.id;
5501 repeat;
5502 }
5503 [connected] PCU.receive(UD_connect_result:{ id := cid, result := tr_err }) {
5504 log("BTS has close()d connection");
Harald Weltea2e0e942019-05-27 18:12:53 +02005505 setverdict(pass);
5506 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005507 /* ignore other messages related to the first connection */
5508 [] PCU.receive { repeat; }
Harald Weltea2e0e942019-05-27 18:12:53 +02005509 [] T.timeout {
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005510 setverdict(fail, "Timeout waiting for connection result");
Harald Weltea2e0e942019-05-27 18:12:53 +02005511 }
5512 }
Vadim Yanitskiy94bbe992021-03-23 07:23:34 +01005513
Harald Weltea2e0e942019-05-27 18:12:53 +02005514 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5515}
5516
Harald Weltec8effb72019-05-27 18:23:04 +02005517/* Ensure that PCUIF socket can disconnect + reconnect */
5518testcase TC_pcu_socket_reconnect() runs on test_CT {
5519 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005520 f_init_with_pcuif();
Harald Weltec8effb72019-05-27 18:23:04 +02005521
5522 f_sleep(1.0);
5523
5524 f_pcuif_close(PCU, g_pcu_conn_id);
5525 g_pcu_conn_id := -1;
5526
5527 f_sleep(1.0);
5528
5529 /* re-connect */
5530 PCU.clear;
5531 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5532 setverdict(pass);
5533
5534 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5535}
5536
Harald Weltebe030482019-05-27 22:29:35 +02005537/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005538private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5539runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005540 var L1ctlDlMessage l1_dl;
5541 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005542 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005543 timer T := 5.0;
5544 T.start;
5545 alt {
5546 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005547 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5548 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005549 repeat;
5550 }
5551 }
5552 [] pt.receive {
5553 repeat;
5554 }
5555 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005556 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5557 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005558 }
5559 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005560 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005561}
5562
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005563/* Check if GPRS Indicator is present in RR System Information of a given type */
5564private function f_si_has_gprs_indicator(RrMessageType si_type)
5565runs on test_CT return boolean {
5566 var SystemInformation si := f_get_si(L1CTL, si_type);
5567
5568 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005569 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005570 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005571 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005572 }
5573
5574 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5575 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005576}
5577
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005578/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5579private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5580runs on test_CT {
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005581 f_init();
Harald Weltebe030482019-05-27 22:29:35 +02005582 f_init_l1ctl();
5583 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005584 f_sleep(2.0);
5585 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005586
5587 if (f_si_has_gprs_indicator(si_type)) {
5588 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005589 } else {
5590 setverdict(pass);
5591 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005592
Harald Weltebe030482019-05-27 22:29:35 +02005593 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5594}
5595
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005596testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5597 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5598}
Harald Weltebe030482019-05-27 22:29:35 +02005599
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005600testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5601 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5602}
5603
5604/* Ensure that GPRS capability is advertised after PCU socket connect */
5605private function f_TC_pcu_socket_connect(RrMessageType si_type)
5606runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005607 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005608 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005609 f_init_l1ctl();
5610 f_l1_tune(L1CTL);
5611
5612 f_sleep(2.0);
5613 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005614
5615 if (not f_si_has_gprs_indicator(si_type)) {
5616 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005617 } else {
5618 setverdict(pass);
5619 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005620
Harald Weltebe030482019-05-27 22:29:35 +02005621 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5622}
5623
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005624testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5625 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5626}
Harald Weltebe030482019-05-27 22:29:35 +02005627
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005628testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5629 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5630}
5631
5632/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5633private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5634runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005635 /* this (among other things) establishes the first connection to the PCUIF socket */
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005636 f_init_with_pcuif();
Harald Weltebe030482019-05-27 22:29:35 +02005637 f_init_l1ctl();
5638 f_l1_tune(L1CTL);
5639
5640 f_pcuif_close(PCU, g_pcu_conn_id);
5641 g_pcu_conn_id := -1;
5642
5643 f_sleep(1.0);
5644
5645 /* re-connect */
5646 PCU.clear;
5647 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5648
5649 f_sleep(2.0);
5650 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005651
5652 if (f_si_has_gprs_indicator(si_type)) {
5653 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005654 } else {
5655 setverdict(pass);
5656 }
5657
5658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5659}
5660
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005661testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5662 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5663}
5664
5665testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5666 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5667}
5668
Oliver Smithf5239c72019-08-28 10:01:25 +02005669/* 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) */
5670testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5671 var SystemInformation si3 := valueof(ts_SI3_default);
5672
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005673 f_init_with_pcuif();
Oliver Smithf5239c72019-08-28 10:01:25 +02005674
Harald Welte76220222020-10-11 20:32:44 +02005675 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5676 * information */
5677 timer T := 2.0;
5678 T.start;
5679 alt {
5680 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5681 [] T.timeout {}
5682 }
5683
Oliver Smithf5239c72019-08-28 10:01:25 +02005684 /* Verify cell_id */
5685 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5686 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5687 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005688 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5689 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5690 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005691 }
5692
5693 /* Verify LAC */
5694 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5695 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5696 if (lac_si3 != lac_pcu) {
5697 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5698 }
5699
5700 setverdict(pass);
5701}
Harald Welted66c9b82019-05-25 09:03:15 +02005702
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005703/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5704testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5705 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005706 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005707
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005708 f_init_with_pcuif();
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005709
5710 info_ind := g_pcu_last_info.u.info_ind;
5711
5712 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5713 for (var integer tn := 0; tn < 8; tn := tn + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005714 if (info_ind.trx[i].pdch_mask[tn] != '1'B) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005715 /* Skip inactive timeslots */
5716 continue;
5717 }
5718
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005719 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005720 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005721 else
5722 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005723
5724 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005725 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005726 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005727 hsn := fhp.maio_hsn.hsn,
5728 maio := fhp.maio_hsn.maio,
5729 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005730 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005731 } else {
5732 tr_ts := tr_PCUIF_InfoTrxTsH0;
5733 }
5734
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005735 var PCUIF_InfoTrxTs ts := info_ind.trx[i].ts[tn];
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005736 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5737 if (not match(ts, tr_ts)) {
5738 setverdict(fail, "Hopping parameters do not match: ",
5739 "received ", ts, " vs expected ", tr_ts);
5740 } else {
5741 setverdict(pass);
5742 }
5743 }
5744 }
5745}
5746
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005747/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02005748testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5749 f_init_vty_bsc();
5750 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5751 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5752
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005753 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02005754
5755 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005756 var template PCUIF_RemoteAddr tr_remote_addr := {
5757 addr_type := { PCUIF_ADDR_TYPE_IPV4, ? },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01005758 addr := { f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O), ? }
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005759 };
Alexander Couzens5283f552020-07-28 15:39:04 +02005760
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005761 if (not match(remote_addr, tr_remote_addr)) {
5762 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02005763 }
5764
5765 setverdict(pass);
5766}
5767
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005768/* Verify IPv4 NSVC address in the INFO.ind message */
Alexander Couzens5283f552020-07-28 15:39:04 +02005769testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5770 f_init_vty_bsc();
5771 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5772
Vadim Yanitskiyec9e9812021-03-21 23:02:44 +01005773 f_init_with_pcuif();
Alexander Couzens5283f552020-07-28 15:39:04 +02005774
5775 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005776 var template PCUIF_RemoteAddr tr_remote_addr := {
5777 addr_type := { PCUIF_ADDR_TYPE_IPV6, ? },
5778 addr := { f_inet6_addr("fd00::ca:ff:ee"), ? }
5779 };
Alexander Couzens5283f552020-07-28 15:39:04 +02005780
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005781 if (not match(remote_addr, tr_remote_addr)) {
5782 setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr);
Alexander Couzens5283f552020-07-28 15:39:04 +02005783 }
5784
5785 setverdict(pass);
5786}
5787
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005788/* Verify coding of two NSVCs in the INFO.ind message */
5789testcase TC_pcu_socket_two_nsvc() runs on test_CT {
5790 f_init_vty_bsc();
5791
5792 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 nsvci 1234");
5793 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 local udp port 1234");
5794 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5795 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote udp port 1234");
5796
5797 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 nsvci 5678");
5798 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 local udp port 5678");
5799 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote ip fd00::ca:ff:ee");
5800 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 1 remote udp port 5678");
5801
Vadim Yanitskiyc1981b72021-03-23 03:01:49 +01005802 f_init_with_pcuif();
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005803
5804 var PCUIF_info_ind info_ind := g_pcu_last_info.u.info_ind;
5805 var PCUIF_RemoteAddr remote_addr := info_ind.remote_addr;
5806 var template PCUIF_RemoteAddr tr_remote_addr := {
5807 addr_type := { PCUIF_ADDR_TYPE_IPV4, PCUIF_ADDR_TYPE_IPV6 },
Vadim Yanitskiy216021a2021-03-24 15:51:06 +01005808 addr := {
5809 f_pad_oct(f_inet_addr("127.127.127.127"), 16, '00'O),
5810 f_inet6_addr("fd00::ca:ff:ee")
5811 }
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01005812 };
5813
5814 if (not match(info_ind.nsvci, { 1234, 5678 }))
5815 { setverdict(fail, "NSVCI ", info_ind.nsvci, " does not match { 1234, 5678 }"); }
5816 if (not match(remote_addr, tr_remote_addr))
5817 { setverdict(fail, "NSVC address ", remote_addr, " does not match ", tr_remote_addr); }
5818 if (not match(info_ind.local_port, { 1234, 5678 }))
5819 { setverdict(fail, "NSVC lport ", info_ind.local_port, " does not match { 1234, 5678 }"); }
5820 if (not match(info_ind.remote_port, { 1234, 5678 }))
5821 { setverdict(fail, "NSVC rport ", info_ind.remote_port, " does not match { 1234, 5678 }"); }
5822
5823 setverdict(pass);
5824}
5825
Harald Welte3d04ae62018-04-04 20:29:05 +02005826/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005827 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005828 ***********************************************************************/
5829
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005830private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5831 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005832runs on ConnHdlr {
5833 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005834
5835 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01005836 var BIT8 pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005837 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5838 repeat;
5839 }
5840 }
5841}
5842
5843private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5844runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005845 /* Expect BTS to immediately acknowledge activation as PDCH */
5846 PCU.clear;
5847 f_rsl_chan_act(g_pars.chan_mode);
5848 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005849 timer T_wait := 2.0;
5850 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005851 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005852 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005853 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005854 [] T_wait.timeout {
5855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5856 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5857 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005858 }
5859 /* try to activate this PDCH from the PCU point of view */
5860 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5861 /* FIXME: is there a response? */
5862}
5863
5864private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5865runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005866 /* Send RSL CHAN REL (deactivate) */
5867 PCU.clear;
5868 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5869 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005870 timer T_wait := 2.0;
5871 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005872 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005873 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005874 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005875 [] T_wait.timeout {
5876 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5877 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5878 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005879 }
5880 /* Emulate PCU asking BTS to deactivate PDCH */
5881 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5882 alt {
5883 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5884 setverdict(pass);
5885 }
5886 [] RSL.receive { repeat; }
5887 }
5888}
5889
5890/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005891private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005892 var PCUIF_Message first_info;
5893 var integer ts_nr := g_chan_nr.tn;
5894 var integer trx_nr := 0;
5895 var integer bts_nr := 0;
5896 var integer pcu_conn_id := -1;
5897
5898 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5899
5900 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5901 f_sleep(3.0);
5902 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5903 setverdict(pass);
5904}
5905testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5906 var ConnHdlrPars pars;
5907 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005908 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005909
5910 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5911 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5912 vc_conn.done;
5913}
5914
5915/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005916private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005917 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005918 var integer pcu_conn_id := -1;
5919
5920 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5921
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005922 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5923 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5924 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005925 setverdict(pass);
5926}
5927testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5928 var ConnHdlrPars pars;
5929 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005930 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005931
5932 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5933 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5934 vc_conn.done;
5935}
5936
5937/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005938private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005939 var PCUIF_Message first_info;
5940 var integer ts_nr := g_chan_nr.tn;
5941 var integer trx_nr := 0;
5942 var integer bts_nr := 0;
5943 var integer pcu_conn_id := -1;
5944
5945 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5946
5947 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005948 /* Send a second Chan Activ and expect it to be NACKed */
5949 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5950 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005951 setverdict(pass);
5952}
5953testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5954 var ConnHdlrPars pars;
5955 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005956 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005957
5958 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5959 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5960 vc_conn.done;
5961}
5962
5963/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005964private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005965 var PCUIF_Message first_info;
5966 var integer ts_nr := g_chan_nr.tn;
5967 var integer trx_nr := 0;
5968 var integer bts_nr := 0;
5969 var integer pcu_conn_id := -1;
5970 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5971
5972 /* register for the TCH/F channel number */
5973 f_rslem_register(0, chan_nr);
5974
5975 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5976
5977 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5978 "RSL CHAN ACT");
5979 setverdict(pass);
5980}
5981testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5982 var ConnHdlrPars pars;
5983 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005984 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005985
5986 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5987 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5988 vc_conn.done;
5989}
5990
5991/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005992private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005993 var PCUIF_Message first_info;
5994 var integer ts_nr := g_chan_nr.tn;
5995 var integer trx_nr := 0;
5996 var integer bts_nr := 0;
5997 var integer pcu_conn_id := -1;
5998 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5999 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
6000
6001 /* register for the TCH/H channel numbers */
6002 f_rslem_register(0, chan_nr[0]);
6003 f_rslem_register(0, chan_nr[1]);
6004
6005 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6006
6007 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
6008 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
6009 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
6010 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
6011 setverdict(pass);
6012}
6013testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
6014 var ConnHdlrPars pars;
6015 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006016 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02006017
6018 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
6019 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
6020 vc_conn.done;
6021}
6022
Harald Welte9bbbfb52018-04-05 09:33:19 +02006023/***********************************************************************
6024 * IPA Style Dynamic Timeslot Support
6025 ***********************************************************************/
6026
6027private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6028runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006029 /* Expect BTS to immediately acknowledge activation as PDCH */
6030 PCU.clear;
6031 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6032 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006033 timer T_wait := 2.0;
6034 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006035 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006036 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006037 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006038 [] T_wait.timeout {
6039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6040 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
6041 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006042 }
6043 /* try to activate this PDCH from the PCU point of view */
6044 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6045 /* FIXME: is there a response? */
6046
6047 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
6048}
6049
6050private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
6051runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006052 /* Send RSL CHAN REL (deactivate) */
6053 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
6054 PCU.clear;
6055 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006056 timer T_wait := 2.0;
6057 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02006058 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07006059 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02006060 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01006061 [] T_wait.timeout {
6062 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6063 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
6064 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02006065 }
6066 /* Emulate PCU asking BTS to deactivate PDCH */
6067 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
6068 alt {
6069 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
6070 setverdict(pass);
6071 }
6072 [] RSL.receive { repeat; }
6073 }
6074}
6075
6076/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006077private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006078 var PCUIF_Message first_info;
6079 var integer ts_nr := g_chan_nr.tn;
6080 var integer trx_nr := 0;
6081 var integer bts_nr := 0;
6082 var integer pcu_conn_id := -1;
6083
6084 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6085
6086 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6087 f_sleep(3.0);
6088 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6089
6090 setverdict(pass);
6091
6092}
6093testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
6094 var ConnHdlrPars pars;
6095 var ConnHdlr vc_conn;
6096 f_init();
6097
6098 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6099 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
6100 vc_conn.done;
6101}
6102
6103/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006104private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006105 var PCUIF_Message first_info;
6106 var integer ts_nr := g_chan_nr.tn;
6107 var integer trx_nr := 0;
6108 var integer bts_nr := 0;
6109 var integer pcu_conn_id := -1;
6110
6111 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6112
6113 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6114 "RSL CHAN ACT");
6115 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6116 "RF CHAN REL", true);
6117 setverdict(pass);
6118}
6119testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
6120 var ConnHdlrPars pars;
6121 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006122 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006123
6124 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6125 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
6126 vc_conn.done;
6127}
6128
6129/* 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 +07006130private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006131 var PCUIF_Message first_info;
6132 var integer ts_nr := g_chan_nr.tn;
6133 var integer trx_nr := 0;
6134 var integer bts_nr := 0;
6135 var integer pcu_conn_id := -1;
6136
6137 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6138
6139 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
6140 "RSL CHAN ACT");
6141
6142 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
6143 alt {
6144 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
6145 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006146 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02006147 }
6148 [] RSL.receive { repeat; }
6149 }
6150
6151 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
6152 "RF CHAN REL", true);
6153 setverdict(pass);
6154}
6155testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
6156 var ConnHdlrPars pars;
6157 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006158 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006159
6160 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6161 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
6162 vc_conn.done;
6163}
6164
6165/* 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 +07006166private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02006167 var PCUIF_Message first_info;
6168 var integer ts_nr := g_chan_nr.tn;
6169 var integer trx_nr := 0;
6170 var integer bts_nr := 0;
6171 var integer pcu_conn_id := -1;
6172
6173 /* register for the TCH/F channel number */
6174 f_rslem_register(0, g_chan_nr);
6175
6176 f_init_pcu(PCU, id, pcu_conn_id, first_info);
6177
6178 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
6179
6180 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
6181 "RSL CHAN ACT");
6182
6183 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
6184
6185 setverdict(pass);
6186}
6187testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
6188 var ConnHdlrPars pars;
6189 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006190 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02006191
6192 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
6193 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
6194 vc_conn.done;
6195}
6196
6197
Harald Welte0472ab42018-03-12 15:02:26 +01006198/***********************************************************************
6199 * LAPDm / RLL related
6200 ***********************************************************************/
6201
6202private function f_tx_lapdm(template (value) LapdmFrame l,
6203 template (value) RslLinkId link_id) runs on ConnHdlr {
6204 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006205 var template (value) SacchL1Header l1h;
6206
6207 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01006208 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006209 /* Compose dummy L1 header */
6210 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
6211 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 +02006212 } else {
6213 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07006214 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 +01006215 }
Harald Welte0472ab42018-03-12 15:02:26 +01006216}
6217
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006218friend type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01006219 uint3_t sapi,
6220 RslLinkId link_id,
6221 octetstring l3,
6222 boolean exp
6223}
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006224friend type record of RllTestCase RllTestCases;
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006225friend template RllTestCase t_EITC(template (present) uint3_t sapi,
6226 template (present) RslLinkId id,
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006227 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01006228 sapi := sapi,
6229 link_id := id,
6230 l3 := l3,
6231 exp := exp
6232}
6233
6234/* execute the same callback function with a set of different parameters (tcs) on a
6235 * variety of logical channels */
6236private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
6237 var ConnHdlrPars pars;
6238 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02006239 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01006240
6241 /* test on each of the channels we have */
6242 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
6243 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6244
6245 /* test each of the test cases on the current channel */
6246 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
6247 pars.spec.rll := tcs[j];
6248 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
6249 vc_conn := f_start_handler(fn, pars);
6250 vc_conn.done;
6251 }
6252 }
6253
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01006255}
6256
6257/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
6258private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
6259 var RllTestCase tc := g_pars.spec.rll;
6260 timer T := 3.0;
6261
6262 f_l1_tune(L1CTL);
6263 RSL.clear;
6264
6265 /* activate the logical channel */
6266 f_est_dchan();
6267 L1CTL.clear;
6268
6269 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
6270 T.start;
6271 alt {
6272 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
6273 if (tc.exp) {
6274 setverdict(pass);
6275 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006276 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006277 }
6278 }
6279 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
6280 if (tc.exp) {
6281 setverdict(pass);
6282 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006284 }
6285 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006286 /* We also expect to receive the measurements */
6287 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006288 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006289 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006290 }
6291 [not tc.exp] T.timeout {
6292 setverdict(pass);
6293 }
6294 }
6295
6296 f_rsl_chan_deact();
6297 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6298 f_rslem_unregister(0, g_chan_nr);
6299}
6300testcase TC_rll_est_ind() runs on test_CT {
6301 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006302 /* SAPI0 establishment (contention resolution) */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006303 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006304 /* normal SAPI0 establishment */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006305 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006306 /* SAPI 3 doesn't support contention resolution */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006307 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), '01020304'O, false)),
6308 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), '01020304'O, false)),
Harald Welte0472ab42018-03-12 15:02:26 +01006309 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006310 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006311 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006312 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006313 };
6314 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6315}
6316
6317/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6318private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6319 var RllTestCase tc := g_pars.spec.rll;
6320 var L1ctlDlMessage dl;
6321 timer T := 3.0;
6322
6323 f_l1_tune(L1CTL);
6324 RSL.clear;
6325
6326 /* activate the logical channel */
6327 f_est_dchan();
6328 L1CTL.clear;
6329
6330 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6331 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6332 T.start;
6333 alt {
Vadim Yanitskiy0310f632021-06-01 01:22:24 +02006334 [] as_l1_exp_lapdm(tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O));
Harald Welte0472ab42018-03-12 15:02:26 +01006335 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006337 }
6338 }
6339
6340 f_rsl_chan_deact();
6341 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6342 f_rslem_unregister(0, g_chan_nr);
6343}
6344testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6345 var RllTestCases tcs := {
6346 /* normal SAPI3 establishment on main DCCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006347 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))//,
Harald Welte0472ab42018-03-12 15:02:26 +01006348 };
6349 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6350}
6351testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6352 var RllTestCases tcs := {
6353 /* normal SAPI3 establishment on SACCH */
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006354 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006355 }
6356 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6357}
6358
6359/* altstep to receive a LAPDm frame matching the given template */
Vadim Yanitskiy7368a102021-06-01 01:25:08 +02006360friend altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
Harald Welte0472ab42018-03-12 15:02:26 +01006361 var L1ctlDlMessage dl;
6362 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6363 var LapdmFrame lapdm;
6364 var octetstring l2 := dl.payload.data_ind.payload;
6365 if (dl.dl_info.link_id.c == SACCH) {
6366 /* remove L1 header */
6367 l2 := substr(l2, 2, lengthof(l2)-2);
6368 }
6369 if (ischosen(exp.ab)) {
6370 lapdm.ab := dec_LapdmFrameAB(l2);
6371 } else if (ischosen(exp.b4)) {
6372 lapdm.b4 := dec_LapdmFrameB4(l2);
6373 } else if (ischosen(exp.bbis)) {
6374 lapdm.bbis := dec_LapdmFrameBbis(l2);
6375 }
6376 log("Rx LAPDm ", lapdm);
6377 if (match(lapdm, exp)) {
6378 setverdict(pass);
6379 } else {
6380 repeat;
6381 }
6382 }
6383 [] L1CTL.receive { repeat; }
6384}
6385private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6386 timer T := t;
6387 T.start;
6388 alt {
6389 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006391 }
6392 [] as_l1_exp_lapdm(exp);
6393 }
6394}
6395
6396/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6397private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6398 /* send SABM from MS -> BTS */
6399 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6400 /* expect RLL EST IND on Abis */
6401 alt {
6402 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6403 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6404 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006406 }
6407 [] RSL.receive { repeat; }
6408 }
6409 /* expect UA from BTS -> MS */
6410 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6411}
6412
6413/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6414private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6415 var RllTestCase tc := g_pars.spec.rll;
6416
6417 f_l1_tune(L1CTL);
6418 RSL.clear;
6419
6420 /* activate the logical channel */
6421 f_est_dchan();
6422 L1CTL.clear;
6423
6424 /* first establish the link-layer */
6425 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6426
6427 /* then send the DISC */
6428 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6429 /* ... and expect the REL IND on the RSL side */
6430 alt {
6431 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6432 setverdict(pass);
6433 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006434 /* We also expect to receive the measurements */
6435 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006436 }
6437
6438 /* release the channel */
6439 f_rsl_chan_deact();
6440 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6441 f_rslem_unregister(0, g_chan_nr);
6442}
6443testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6444 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006445 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006446 };
6447 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6448}
6449
6450testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6451 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006452 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006453 };
6454 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6455}
6456testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6457 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006458 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006459 };
6460 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6461}
6462testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6463 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006464 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006465 };
6466 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6467}
6468
6469/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6470private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6471 var RllTestCase tc := g_pars.spec.rll;
6472 f_l1_tune(L1CTL);
6473 RSL.clear;
6474
6475 /* activate the logical channel */
6476 f_est_dchan();
6477 L1CTL.clear;
6478
6479 /* first establish the link-layer */
6480 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6481
6482 /* then send the REL REQ via RSL */
6483 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6484 /* ... and expect the DISC on the Um side */
6485 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006486 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006487 /* FIXME: send a UA in resposne to the DISC */
6488 }
6489 }
6490
6491 /* release the channel */
6492 f_rsl_chan_deact();
6493 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6494 f_rslem_unregister(0, g_chan_nr);
6495}
6496testcase TC_rll_rel_req() runs on test_CT {
6497 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006498 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), '01020304'O, true)),
6499 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), ''O, true)),
6500 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), ''O, true)),
6501 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), ''O, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006502 };
6503 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6504}
6505
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006506/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006507testcase TC_rll_data_req() runs on test_CT {
6508}
6509
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006510/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006511testcase TC_rll_data_ind() runs on test_CT {
6512}
6513
6514/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6515private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6516 var RllTestCase tc := g_pars.spec.rll;
6517
6518 f_l1_tune(L1CTL);
6519 RSL.clear;
6520
6521 f_est_dchan();
6522 L1CTL.clear;
6523
6524 /* Send UNITDATA REQ on RSL side */
6525 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6526 /* Expect it to arrive on the other side */
6527 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006528 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006529 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006530 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006531 }
6532
6533 /* release the channel */
6534 f_rsl_chan_deact();
6535 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6536 f_rslem_unregister(0, g_chan_nr);
6537}
6538testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6539 var octetstring l3 := f_rnd_octstring(15);
6540 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006541 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6542 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006543 };
6544 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6545}
6546testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6547 var octetstring l3 := f_rnd_octstring(19);
6548 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006549 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6550 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006551 };
6552 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6553}
6554
6555/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6556private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6557 var RllTestCase tc := g_pars.spec.rll;
6558
6559 f_l1_tune(L1CTL);
6560 RSL.clear;
6561
6562 f_est_dchan();
6563 L1CTL.clear;
6564
6565 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006566 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006567 /* Expdct RLL UNITDATA IND on RSL side */
6568 alt {
6569 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6570 setverdict(pass);
6571 }
6572 [] RSL.receive { repeat; }
6573 }
6574
6575 /* release the channel */
6576 f_rsl_chan_deact();
6577 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6578 f_rslem_unregister(0, g_chan_nr);
6579}
6580testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006581 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006582 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006583 valueof(t_EITC(0, ts_RslLinkID_DCCH(0), l3, true)),
6584 valueof(t_EITC(3, ts_RslLinkID_DCCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006585 };
6586 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6587}
6588testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6589 var octetstring l3 := f_rnd_octstring(18);
6590 var RllTestCases tcs := {
Vadim Yanitskiy1b9a7f62021-06-01 01:56:37 +02006591 valueof(t_EITC(0, ts_RslLinkID_SACCH(0), l3, true)),
6592 valueof(t_EITC(3, ts_RslLinkID_SACCH(3), l3, true))
Harald Welte0472ab42018-03-12 15:02:26 +01006593 };
6594 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6595}
6596
Harald Weltee613f962018-04-18 22:38:16 +02006597/***********************************************************************
6598 * Encryption Related
6599 ***********************************************************************/
6600
6601/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006602private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006603 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6604 if (link_id.c == SACCH) {
6605 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6606 } else {
6607 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6608 }
6609}
6610
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006611/* Expect (or not expect) other kinds of messages */
6612private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6613 [exp_any] RSL.receive { repeat; }
6614 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006616 }
6617}
6618
Harald Weltee613f962018-04-18 22:38:16 +02006619/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006620private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006621 RslLinkId link_id,
6622 octetstring l3,
6623 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006624 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006625) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006626 timer T := 3.0;
6627 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6628 T.start;
6629 /* Expect RLL UNITDATA IND on RSL side */
6630 alt {
6631 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6632 setverdict(pass);
6633 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006634 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006635 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006636 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006637 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006638 }
Harald Weltee613f962018-04-18 22:38:16 +02006639 }
6640}
6641
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006642/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6643private function f_data_mo(
6644 RslLinkId link_id,
6645 boolean p, uint3_t nr, uint3_t ns,
6646 octetstring l3,
6647 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006648 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006649) runs on ConnHdlr {
6650 timer T := 3.0;
6651 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6652 T.start;
6653 /* Expect RLL DATA IND on RSL side */
6654 alt {
6655 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6656 setverdict(pass);
6657 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006658 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006659 [] as_rsl_any_ind(exp_any);
6660 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006662 }
6663 }
6664}
6665
Harald Weltee613f962018-04-18 22:38:16 +02006666/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006667private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006668 f_l1_tune(L1CTL);
6669 f_est_dchan(true);
6670
6671 /* now we actually need to transmit some data both ways to check if the encryption works */
6672 var L1ctlDlMessage dl;
6673
Stefan Sperling603d98e2018-07-25 16:47:28 +02006674 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006675 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6676
6677 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6678 f_unitdata_mt(link_id, l3);
6679
6680 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6681 f_unitdata_mo(link_id, l3);
6682
6683 /* release the channel */
6684 f_rsl_chan_deact();
6685 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6686 f_rslem_unregister(0, g_chan_nr);
6687}
6688testcase TC_chan_act_a51() runs on test_CT {
6689 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6690 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6691 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6692}
6693testcase TC_chan_act_a52() runs on test_CT {
6694 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6695 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6696 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6697}
6698testcase TC_chan_act_a53() runs on test_CT {
6699 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6700 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6701 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6702}
Eric Wildb9260392021-05-15 19:48:22 +02006703testcase TC_chan_act_a54() runs on test_CT {
6704 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6705 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
6706 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6707}
Harald Weltee613f962018-04-18 22:38:16 +02006708
Eric Wildf1827a72019-05-28 17:37:35 +02006709/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6710 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 +07006711private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006712 f_l1_tune(L1CTL);
6713 f_est_dchan(true);
6714
6715 /* now we actually need to transmit some data both ways to check if the encryption works */
6716 var L1ctlDlMessage dl;
6717
6718 var octetstring l3 := f_rnd_octstring(20);
6719 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6720
6721 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6722 f_unitdata_mt(link_id, l3);
6723
6724 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6725 f_unitdata_mo(link_id, l3);
6726
6727 var RSL_Message rsl;
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006728 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, ts_RSL_ChanMode_SIGN));
Eric Wildf1827a72019-05-28 17:37:35 +02006729
6730 /* modify key to break proper encryption */
6731 g_pars.encr.key := f_rnd_octstring(8);
6732 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6733 rsl.ies := rsl.ies & { ei };
6734 RSL.send(rsl);
6735
6736 timer T0 := 1.0;
6737 T0.start;
6738 /* Expect RSL MODIFY ACK */
6739 alt {
6740 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6741 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6742 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6743 }
6744 [] T0.timeout {
6745 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6746 }
6747 }
6748
6749 var octetstring l3msg := f_rnd_octstring(15);
6750 timer T1 := 3.0;
6751 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6752 due to broken encryption */
6753 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6754 T1.start;
6755 alt {
6756 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6758 }
6759 [] T1.timeout {
6760 setverdict(pass);
6761 }
6762 }
6763
6764 /* release the channel */
6765 f_rsl_chan_deact();
6766 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6767 f_rslem_unregister(0, g_chan_nr);
6768}
6769testcase TC_rsl_modify_encr() runs on test_CT {
6770 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6771 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6772 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6773}
Harald Weltee613f962018-04-18 22:38:16 +02006774
6775/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006776private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006777 /* L3 payload doesn't matter, as it is passed transparently */
6778 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6779 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6780 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6781
6782 f_l1_tune(L1CTL);
6783
6784 /* first establish a dedicated channel in the clear */
6785 f_est_dchan(false);
6786
6787 /* Establish ABM */
6788 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6789
6790 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6791 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6792 /* expect the L3 to arrive still unencrypted on the MS side */
6793 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6794
6795 /* configure L1 to apply ciphering */
6796 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6797 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6798
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006799 /* send first ciphered I-frame in response and expect it on RSL */
6800 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006801
6802 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6803 * and hence enable encryption also on the downlink */
6804
6805 /* expect bi-directional communication work in encrypted mode */
6806 f_unitdata_mo(link_id, f_rnd_octstring(15));
6807 f_unitdata_mt(link_id, f_rnd_octstring(15));
6808
6809 /* release the channel */
6810 f_rsl_chan_deact();
6811 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6812 f_rslem_unregister(0, g_chan_nr);
6813}
6814testcase TC_encr_cmd_a51() runs on test_CT {
6815 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6816 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6817 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6818}
6819testcase TC_encr_cmd_a52() runs on test_CT {
6820 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6821 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6822 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6823}
6824testcase TC_encr_cmd_a53() runs on test_CT {
6825 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6826 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6827 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6828}
Eric Wildb9260392021-05-15 19:48:22 +02006829testcase TC_encr_cmd_a54() runs on test_CT {
6830 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6831 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_4, f_rnd_octstring(16)));
6832 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6833}
Harald Weltee613f962018-04-18 22:38:16 +02006834
6835private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6836 var LapdmFrame lf;
6837 var octetstring reenc;
6838
6839 /* decode the LAPDm frame */
6840 if (ischosen(exp_match.ab)) {
6841 lf.ab := dec_LapdmFrameAB(enc);
6842 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006844 }
6845
6846 /* check if decoder result matches expectation */
6847 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006848 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006849 } else {
6850 log(name, ": matched");
6851 setverdict(pass);
6852 }
6853
6854 /* test if re-encoded frame equals original input */
6855 reenc := enc_LapdmFrame(lf);
6856 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006857 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006858 } else {
6859 setverdict(pass);
6860 }
6861}
6862
6863testcase TC_lapdm_selftest() runs on test_CT {
6864 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6865 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6866 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6867 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6868 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6869 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6870 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6871}
6872
Stefan Sperling4880be42018-08-07 18:12:59 +02006873/***********************************************************************
6874 * DTX Related (see GSM 05.08, section 8.3)
6875 ***********************************************************************/
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006876private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006877 var L1ctlDlMessage dl;
Stefan Sperling4880be42018-08-07 18:12:59 +02006878 var GsmFrameNumber first_fn;
6879 var boolean is_first_frame := true;
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006880 var integer nfill_frames := 0;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006881 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006882 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6883 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006884 const integer frame_dtx_tchf_mod := 104;
6885 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6886 * which operates in terms of blocks rather than frames. */
6887 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6888 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006889 timer T := 5.0;
6890
6891 f_l1_tune(L1CTL);
6892 RSL.clear;
6893 L1CTL.clear;
6894
6895 /* activate TCHF signalling channel */
6896 f_est_dchan(false);
6897
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006898 /* A template for matching dummy LAPDm func=UA frames */
6899 var template L1ctlDlMessage tr_fill_frame := tr_L1CTL_DATA_IND(
6900 chan_nr := g_chan_nr, link_id := tr_RslLinkID_DCCH(?),
6901 l2_data := f_pad_oct('030301'O, 23, '2B'O));
6902
Stefan Sperling4880be42018-08-07 18:12:59 +02006903 T.start;
6904 alt {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006905 [] L1CTL.receive(tr_fill_frame) -> value dl {
Stefan Sperling4880be42018-08-07 18:12:59 +02006906 var GsmFrameNumber fn := dl.dl_info.frame_nr;
Stefan Sperling4880be42018-08-07 18:12:59 +02006907
6908 if (is_first_frame) {
6909 is_first_frame := false;
6910 first_fn := dl.dl_info.frame_nr;
6911 }
6912
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07006913 if (g_pars.chan_mode.dtx_d) {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006914 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006915 T.stop;
6916 f_rsl_chan_deact();
6917 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006918
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006919 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames. */
6920 expected_fill_frames := 2;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006921
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006922 if (nfill_frames < expected_fill_frames) {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006923 setverdict(fail, "Not enough fill frames received: ",
6924 nfill_frames, " out of ", expected_fill_frames);
6925 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006926 } else {
6927 setverdict(pass);
6928 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006929 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006930 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6931 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6932 * we should only see the subset of frames numbers which correspond to a block boundary.
6933 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6934 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6935 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006936 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006937 repeat;
6938 }
6939 }
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006940 setverdict(fail, "Received DTX TCH fill frame with bad frame number: ", fn,
6941 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6942 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006943 f_rsl_chan_deact();
6944 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling4880be42018-08-07 18:12:59 +02006945 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006946 } else {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006947 nfill_frames := nfill_frames + 1;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006948 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006949 T.stop;
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006950
6951 select (g_chan_nr) {
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006952 /* TCH/F: we expect 24 fill frames for every 104 frames. */
6953 case (t_RslChanNr_Bm(?)) { expected_fill_frames := 24; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006954 /* TCH/H: we expect 2 fill frames for every 104 frames. */
6955 case (t_RslChanNr_Lm(?, ?)) { expected_fill_frames := 2; }
6956 /* SDCCH: we expect 5 fill frames for every 104 frames. */
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006957 case (t_RslChanNr_SDCCH4(?, ?)) { expected_fill_frames := 4; }
6958 case (t_RslChanNr_SDCCH8(?, ?)) { expected_fill_frames := 4; }
Vadim Yanitskiy34ed2282020-10-24 23:18:42 +07006959 case else {
6960 /* This shall not happen, just to be sure */
6961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6962 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006963 }
6964
6965 f_rsl_chan_deact();
6966 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006967
Vadim Yanitskiy080a17d2020-10-25 01:06:48 +07006968 if (nfill_frames >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006969 setverdict(pass);
6970 } else {
Vadim Yanitskiy76dc4d02020-10-24 22:56:46 +07006971 setverdict(fail, "Not enough fill frames received: ",
6972 nfill_frames, " out of ", expected_fill_frames);
6973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Stefan Sperling4880be42018-08-07 18:12:59 +02006974 }
6975 } else {
6976 repeat;
6977 }
6978 }
6979 }
6980 [] L1CTL.receive { repeat; }
6981 [] T.timeout {
6982 f_rsl_chan_deact();
6983 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006985 }
6986 }
6987}
6988
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006989private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006990 var template RSL_IE_ChannelMode ch_mode;
Stefan Sperling4880be42018-08-07 18:12:59 +02006991 var ConnHdlr vc_conn;
6992 var ConnHdlrPars pars;
6993 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006994 f_init();
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006995 ch_mode := ts_RSL_ChanMode_SIGN(dtx_downlink := dtxd);
Stefan Sperling4880be42018-08-07 18:12:59 +02006996 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
Vadim Yanitskiy8fc43df2020-10-20 02:11:05 +07006997 pars := valueof(t_Pars(g_AllChannels[i], ch_mode));
Stefan Sperling4880be42018-08-07 18:12:59 +02006998 if (dtxd) {
6999 if (i >= 4) { /* DTX is only allowed on TCH/F */
7000 break;
7001 }
Stefan Sperling4880be42018-08-07 18:12:59 +02007002 }
Vadim Yanitskiy28a03ef2020-10-25 01:50:40 +07007003 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
Stefan Sperling4880be42018-08-07 18:12:59 +02007004 vc_conn.done;
7005 }
7006}
7007
7008/* Verify that L2 fill frames are sent on TCH in signaling mode if
7009 * there is nothing to transmit while DTX is disabled on downlink. */
7010testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
7011 f_tch_sign_l2_fill_frame(false);
7012}
7013
7014/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
7015 * there is nothing to transmit while DTX is enabled on downlink. */
7016testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
7017 f_tch_sign_l2_fill_frame(true);
7018}
Harald Welte0472ab42018-03-12 15:02:26 +01007019
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007020testcase TC_chopped_ipa_ping() runs on test_CT {
7021 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7022}
7023
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007024testcase TC_chopped_ipa_payload() runs on test_CT {
7025 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
7026}
7027
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007028
7029/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
7030 * Return value: Measurement Report to be sent (encoded octetstring). */
7031type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
7032 runs on ConnHdlr return octetstring;
7033
7034private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
7035runs on ConnHdlr {
7036 var L1ctlDlMessage l1_dl;
7037 var SacchL1Header l1h;
7038 var octetstring l2;
7039
7040 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
7041 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
7042 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
7043 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
7044
7045 /* Pass it to the user specified call-back function */
7046 l2 := cb.apply(l1h, num_blocks);
7047 /* Send a Measurement Report generated by the call-back */
7048 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
7049 l1_dl.dl_info.link_id,
7050 l1h, l2));
7051
7052 /* Shall we keep going? */
7053 num_blocks := num_blocks - 1;
7054 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
7055 if (num_blocks > 0) { repeat; }
7056 }
7057 [] L1CTL.receive { repeat; }
7058}
7059
7060private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
7061runs on ConnHdlr return octetstring {
7062 /* Command the L1 to apply received parameters */
7063 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
7064
7065 /* Dummy measurement report (the results are invalid) */
7066 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
7067}
7068
7069private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
7070runs on ConnHdlr return octetstring {
7071 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
7072 setverdict(fail, "Unexpected MS Power level change: ",
7073 g_pars.l1_pars.ms_power_level, " -> ",
7074 l1h.ms_power_lvl);
7075 }
7076
7077 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
7078}
7079
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007080private function f_TC_ms_pwr_ctrl_cb_rssi_pwm(inout SacchL1Header l1h, integer num_blocks)
7081runs on ConnHdlr return octetstring {
7082 /* UL RSSI oscillation driven by SACCH block number */
7083 if (num_blocks rem 2 == 0) {
7084 f_trxc_fake_rssi(-100);
7085 } else {
7086 f_trxc_fake_rssi(-50);
7087 }
7088
7089 /* Make sure that MS power level remains constant */
7090 return f_TC_ms_pwr_ctrl_cb_const(l1h, num_blocks);
7091}
7092
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007093/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
7094private function f_TC_ms_pwr_ctrl_constant(charstring id)
7095runs on ConnHdlr {
7096 var integer num_blocks := 8;
7097 timer T := int2float(num_blocks);
7098
7099 f_l1_tune(L1CTL);
7100 RSL.clear;
7101
7102 /* These IEs are needed for autonomous MS power control */
7103 var template (value) RSL_IE_List ies := {
7104 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7105 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7106 }),
7107 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7108 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7109 })
7110 };
7111
7112 /* Ensure that 'rx-current' equals 'rx-target' */
7113 f_trxc_fake_rssi(mp_uplink_power_target);
7114
7115 /* Establish a dedicated channel */
7116 f_est_dchan(more_ies := valueof(ies));
7117
7118 L1CTL.clear;
7119 T.start;
7120 alt {
7121 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
7122 [] T.timeout {
7123 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7124 num_blocks, " were not handled");
7125 }
7126 }
7127}
7128testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
7129 var ConnHdlr vc_conn;
7130 var ConnHdlrPars pars;
7131
7132 f_init();
7133
7134 /* Explicitly configure the Uplink power target (in dBm) */
7135 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
7136
7137 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7138 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7139 log(testcasename(), ": starting on ", pars.chan_nr);
7140
7141 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
7142 pars, trxc_comp := true);
7143 vc_conn.done;
7144 }
7145
7146 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7148}
7149
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007150/* Test Exponentially Weighted Moving Average (EWMA) power filtering */
7151private function f_TC_ms_pwr_ctrl_pf_ewma(charstring id)
7152runs on ConnHdlr {
7153 var integer num_blocks := 16;
7154 timer T := int2float(num_blocks);
7155
7156 f_l1_tune(L1CTL);
7157 RSL.clear;
7158
7159 /* These IEs are needed for autonomous MS power control */
7160 var template (value) RSL_IE_List ies := {
7161 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
7162 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
7163 }),
7164 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
7165 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
7166 })
7167 };
7168
7169 /* Ensure that 'rx-current' equals 'rx-target' */
7170 f_trxc_fake_rssi(mp_uplink_power_target);
7171
7172 /* Establish a dedicated channel */
7173 f_est_dchan(more_ies := valueof(ies));
7174
7175 L1CTL.clear;
7176 T.start;
7177 alt {
7178 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_rssi_pwm), num_blocks);
7179 [] T.timeout {
7180 setverdict(fail, "Not all SACCH blocks were processed in time, ",
7181 num_blocks, " were not handled");
7182 }
7183 }
7184}
7185testcase TC_ms_pwr_ctrl_pf_ewma() runs on test_CT {
7186 var ConnHdlr vc_conn;
7187 var ConnHdlrPars pars;
7188
7189 f_init();
7190
7191 /* Explicitly configure EWMA filtering with 80% smoothing (alpha = 0.2) */
7192 f_vty_config(BTSVTY, "bts 0", "uplink-power-filtering algo ewma beta 80");
7193 /* Explicitly configure the Uplink power range (target and delte) */
7194 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target)
7195 & " hysteresis " & int2str(mp_uplink_power_hysteresis));
7196
7197 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
7198 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
7199 log(testcasename(), ": starting on ", pars.chan_nr);
7200
7201 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_pf_ewma),
7202 pars, trxc_comp := true);
7203 vc_conn.done;
7204 }
7205
7206 /* No need to reset Uplink power parameters - the IUT restarts anyway */
7207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
7208}
7209
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007210private function f_TC_speech_no_rtp(charstring id) runs on ConnHdlr {
7211 var template L1ctlDlMessage tr_bad_frame;
7212 var L1ctlDlMessage l1_dl;
7213 timer T := 8.0;
7214
7215 f_l1_tune(L1CTL);
7216 RSL.clear;
7217
7218 f_est_dchan();
7219
7220 /* There may be a few errors right after the channel activation */
7221 f_sleep(2.0); /* ... so let's give the L1 some time to stabilize */
7222 L1CTL.clear;
7223
7224 /* A universal template for bad Downlink frame: {DATA,TRAFFIC}.ind */
7225 tr_bad_frame := tr_L1CTL_TRAFFIC_IND(g_chan_nr, tr_RslLinkID_DCCH(0));
7226 tr_bad_frame.header.msg_type := (L1CTL_DATA_IND, L1CTL_TRAFFIC_IND);
7227 tr_bad_frame.dl_info.fire_crc := (1..255); /* != 0 */
7228 tr_bad_frame.payload := ?;
7229
7230 T.start;
7231 alt {
7232 /* OS#4823: DATA.ind or TRAFFIC.ind with bad CRC most likely means that
7233 * the IUT is sending *dummy bursts*, so the L1 fails to decode them. */
7234 [] L1CTL.receive(tr_bad_frame) -> value l1_dl {
7235 setverdict(fail, "Received {DATA,TRAFFIC}.ind with bad CRC: ", l1_dl);
7236 }
7237 [] as_l1_sacch();
7238 [] L1CTL.receive { repeat; }
7239 [] T.timeout {
7240 /* We're done, break the loop */
7241 setverdict(pass);
7242 }
7243 }
7244
7245 f_rsl_chan_deact();
7246 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
7247}
7248testcase TC_speech_no_rtp_tchf() runs on test_CT {
7249 var ConnHdlr vc_conn;
7250 var ConnHdlrPars pars;
7251
7252 f_init();
7253
7254 /* TS1, TCH/F, V1 (FR codec) */
7255 pars := valueof(t_Pars(ts_RslChanNr_Bm(1), ts_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1)));
7256 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7257 vc_conn.done;
7258}
7259testcase TC_speech_no_rtp_tchh() runs on test_CT {
7260 var ConnHdlr vc_conn;
7261 var ConnHdlrPars pars;
7262
7263 f_init();
7264
7265 /* TS5, TCH/H, V1 (HR codec) */
7266 pars := valueof(t_Pars(ts_RslChanNr_Lm(5, 0), ts_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1)));
7267 vc_conn := f_start_handler(refers(f_TC_speech_no_rtp), pars);
7268 vc_conn.done;
7269}
7270
Harald Welte0472ab42018-03-12 15:02:26 +01007271/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
7272/* protocol error as per 44.006 */
7273/* link layer failure (repetition of I-frame N200 times without ACK */
7274/* repetition of SABM or DISC N200 times without ACK */
7275/* receptiom of SABM in multi-frame established state */
7276
7277
Harald Welte68e495b2018-02-25 00:05:57 +01007278/* TODO Areas:
7279
7280* channel activation
7281** with BS_Power / MS_Power, bypassing power control loop
7282** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01007283** with timing advance from initial activation on
7284* mode modify
7285** encryption
7286** multirate
7287* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01007288** unsupported algorithm
7289* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01007290* BS Power Control
7291* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01007292* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01007293* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01007294** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01007295* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01007296** DATA_IND from BTS->PCU
7297** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01007298
7299*/
Harald Welte70767382018-02-21 12:16:40 +01007300
7301control {
7302 execute( TC_chan_act_stress() );
7303 execute( TC_chan_act_react() );
7304 execute( TC_chan_deact_not_active() );
7305 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01007306 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01007307 execute( TC_sacch_filling() );
7308 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01007309 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01007310 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02007311 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02007312 execute( TC_sacch_chan_act_ho_async() );
7313 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007314 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02007315 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01007316 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01007317 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07007318 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02007319 execute( TC_rach_load_idle_thresh0() );
7320 execute( TC_rach_load_idle_below_thresh() );
7321 execute( TC_rach_load_count() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007322 execute( TC_meas_res_speech_tchf() );
Philipp Maier149c3922020-10-22 17:29:36 +02007323 execute( TC_meas_res_speech_tchf_facch() );
Vadim Yanitskiy204b98c2020-10-19 14:52:48 +07007324 execute( TC_meas_res_speech_tchh() );
Philipp Maier149c3922020-10-22 17:29:36 +02007325 execute( TC_meas_res_speech_tchh_facch() );
Vadim Yanitskiy780bc072020-10-20 02:16:01 +07007326 execute( TC_meas_res_speech_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01007327 execute( TC_meas_res_sign_tchf() );
7328 execute( TC_meas_res_sign_tchh() );
7329 execute( TC_meas_res_sign_sdcch4() );
7330 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01007331 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02007332 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02007333 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02007334 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02007335 execute( TC_rsl_bs_pwr_static_ass() );
7336 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01007337 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02007338 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02007339 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02007340 execute( TC_rsl_ms_pwr_dyn_up() );
7341 execute( TC_rsl_ms_pwr_dyn_down() );
7342 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
7343 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02007344 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02007345 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02007346 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01007347 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01007348 execute( TC_paging_imsi_80percent() );
7349 execute( TC_paging_tmsi_80percent() );
7350 execute( TC_paging_imsi_200percent() );
7351 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01007352 execute( TC_rsl_protocol_error() );
7353 execute( TC_rsl_mand_ie_error() );
7354 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007355 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007356 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007357 execute( TC_si_sched_2bis() );
7358 execute( TC_si_sched_2ter() );
7359 execute( TC_si_sched_2ter_2bis() );
7360 execute( TC_si_sched_2quater() );
7361 execute( TC_si_sched_13() );
7362 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007363 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007364 execute( TC_ipa_crcx_twice_not_active() );
7365 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007366 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007367 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007368
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007369 if (mp_pcu_socket != "") {
7370 execute( TC_pcu_act_req() );
7371 execute( TC_pcu_act_req_wrong_ts() );
7372 execute( TC_pcu_act_req_wrong_bts() );
7373 execute( TC_pcu_act_req_wrong_trx() );
7374 execute( TC_pcu_deact_req() );
7375 execute( TC_pcu_deact_req_wrong_ts() );
Philipp Maier94c08482021-02-01 17:36:05 +01007376 execute( TC_pcu_ver_si1() );
7377 execute( TC_pcu_ver_si3() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007378 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007379 if (mp_l1_supports_gprs) {
7380 execute( TC_pcu_data_req_pdtch() );
7381 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007382 execute( TC_pcu_data_req_wrong_bts() );
7383 execute( TC_pcu_data_req_wrong_trx() );
7384 execute( TC_pcu_data_req_wrong_ts() );
7385 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007386 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007387 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007388 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007389 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007390 execute( TC_pcu_data_req_imm_ass_pch() );
7391 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007392 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007393 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007394 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007395 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007396 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007397 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007398 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007399 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007400 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007401 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007402 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007403 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007404 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007405 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007406 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007407 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007408 execute( TC_dyn_osmo_pdch_act_deact() );
7409 execute( TC_dyn_osmo_pdch_double_act() );
7410 execute( TC_dyn_ipa_pdch_act_deact() );
7411 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +01007412 execute( TC_pcu_info_ind_fh_params() );
7413 execute( TC_pcu_socket_nsvc_ipv4() );
7414 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiye2a50a82021-03-23 05:58:02 +01007415 execute( TC_pcu_socket_two_nsvc() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007416 } else {
7417 log("PCU socket path not available, skipping PCU tests");
7418 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007419
Harald Welte3d04ae62018-04-04 20:29:05 +02007420 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007421 execute( TC_dyn_osmo_pdch_tchf_act() );
7422 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007423 execute( TC_dyn_ipa_pdch_tchf_act() );
7424 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007425
7426 execute( TC_rll_est_ind() );
7427 execute( TC_rll_est_req_DCCH_3() );
7428 execute( TC_rll_est_req_ACCH_3() );
7429 execute( TC_rll_rel_ind_DCCH_0() );
7430 execute( TC_rll_rel_ind_DCCH_3() );
7431 execute( TC_rll_rel_ind_ACCH_0() );
7432 execute( TC_rll_rel_ind_ACCH_3() );
7433 execute( TC_rll_rel_req() );
7434 execute( TC_rll_unit_data_req_DCCH() );
7435 execute( TC_rll_unit_data_req_ACCH() );
7436 execute( TC_rll_unit_data_ind_DCCH() );
7437 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007438
7439 execute( TC_chan_act_a51() );
7440 execute( TC_chan_act_a52() );
7441 execute( TC_chan_act_a53() );
7442 execute( TC_encr_cmd_a51() );
7443 execute( TC_encr_cmd_a52() );
7444 execute( TC_encr_cmd_a53() );
7445
Harald Welteee25aae2019-05-19 14:32:37 +02007446 execute( TC_err_rep_wrong_mdisc() );
7447 execute( TC_err_rep_wrong_msg_type() );
7448 execute( TC_err_rep_wrong_sequence() );
7449
Harald Weltee613f962018-04-18 22:38:16 +02007450 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007451
7452 execute( TC_tch_sign_l2_fill_frame() );
7453 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007454
7455 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007456 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007457
7458 execute( TC_ms_pwr_ctrl_constant() );
Vadim Yanitskiy652e60e2020-10-18 19:43:27 +07007459 execute( TC_ms_pwr_ctrl_pf_ewma() );
Vadim Yanitskiy5fa85612020-10-21 03:46:18 +07007460
7461 execute( TC_speech_no_rtp_tchf() );
7462 execute( TC_speech_no_rtp_tchh() );
Harald Welte70767382018-02-21 12:16:40 +01007463}
7464
7465
7466}