blob: 9503bec0b4e0d543910ba7f40f5c8bc61ad4f194 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Vadim Yanitskiy5d2cf442020-05-02 16:49:17 +070032import from GSM_RestOctets all;
Harald Welte82ccef72018-02-25 16:17:33 +010033import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010034import from L1CTL_PortType all;
35import from L1CTL_Types all;
36import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020037import from LAPDm_RAW_PT all;
Alexander Couzens5283f552020-07-28 15:39:04 +020038import from Native_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020040import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010041
42import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010043import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010044import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020045import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010046import from RSL_Emulation all;
47
48import from IPL4asp_Types all;
49import from TRXC_Types all;
50import from TRXC_CodecPort all;
51import from TRXC_CodecPort_CtrlFunct all;
52
Harald Welte883340c2018-02-28 18:59:29 +010053import from PCUIF_Types all;
54import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020055import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010056
Harald Welte7484fc42018-02-24 14:09:45 +010057import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010058import from MobileL3_RRM_Types all;
59import from MobileL3_Types all;
60import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020061import from L3_Common all;
62import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010063
Harald Welte8da48242018-02-27 20:41:32 +010064import from Osmocom_VTY_Functions all;
65import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020066import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010067
Harald Welte505cf9b2018-09-15 17:47:23 +030068friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020069friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020070friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010071friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030072
Harald Welte70767382018-02-21 12:16:40 +010073/* The tests assume a BTS with the following timeslot configuration:
74 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020075 * TS1 : TCH/F
76 * TS2 : TCH/F
77 * TS3 : TCH/F_PDCH (IPA Style)
78 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010079 * TS5 : TCH/H
80 * TS6 : SDCCH/8
81 * TS7 : PDCH
82 */
83
84modulepar {
85 charstring mp_rsl_ip := "127.0.0.2";
86 integer mp_rsl_port := 3003;
87 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +070088 integer mp_trx1_arfcn := 873;
89 integer mp_trx2_arfcn := 875;
90 integer mp_trx3_arfcn := 877;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070091 charstring mp_bts_trxc_ip := "127.0.0.1";
92 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010093 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020094 charstring mp_ctrl_ip := "127.0.0.1";
95 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020096 charstring mp_bsc_ctrl_ip := "127.0.0.1";
97 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020098 integer mp_tolerance_rxqual := 1;
99 integer mp_tolerance_rxlev := 3;
100 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200101 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200102 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200103 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200104 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
105 integer mp_bts_tx_pwr_att_exp := 20; /* Expected Tx Power attenuation wrt to Tx Nominal Output Power, in dB */
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200106 integer mp_ms_actual_ta_exp := 0;
107 integer mp_timing_offset_256syms_exp := 512;
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +0700108 integer mp_uplink_power_target := -75;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100109 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200110 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200111 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200112 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
113 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700114 /* how many transceivers do we expect to connect */
115 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700116 /* frequency hopping status */
117 boolean mp_freq_hop_enabled := false;
118 /* frequency hopping parameters */
119 FreqHopConfig mp_fh_config;
Harald Welte70767382018-02-21 12:16:40 +0100120}
121
Harald Welte629cc6b2018-03-11 17:19:05 +0100122type record of RslChannelNr ChannelNrs;
123
Harald Welte70767382018-02-21 12:16:40 +0100124type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100125 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100126 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100127 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100128 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100129 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100130 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100131
132 /* L1CTL port (for classic tests) */
133 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100134
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700135 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700136 port TRXC_CODEC_PT BTS_TRXC;
137 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100138
Harald Weltef50e3ae2018-09-10 10:27:56 +0200139 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100140 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200141 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100142
Harald Welte883340c2018-02-28 18:59:29 +0100143 /* PCU Interface of BTS */
144 port PCUIF_CODEC_PT PCU;
145 var integer g_pcu_conn_id;
146 /* Last PCU INFO IND we received */
147 var PCUIF_Message g_pcu_last_info;
148
Harald Welte48494ca2018-02-25 16:59:50 +0100149 /* SI configuration */
150 var SystemInformationConfig si_cfg := {
151 bcch_extended := false,
152 si1_present := false,
153 si2bis_present := false,
154 si2ter_present := false,
155 si2quater_present := false,
156 si7_present := false,
157 si8_present := false,
158 si9_present := false,
159 si13_present := false,
160 si13alt_present := false,
161 si15_present := false,
162 si16_present := false,
163 si17_present := false,
164 si2n_present := false,
165 si21_present := false,
166 si22_present := false
167 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100168
169 /* all logical channels available on the BTS */
170 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100171 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100172}
173
174/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200175type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100176 port L1CTL_PT L1CTL;
177
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700178 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700179 port TRXC_CODEC_PT BTS_TRXC;
180 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100181
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200182 /* port to be initialized optionally to access BSC VTY */
183 port TELNETasp_PT BSCVTY;
184
Harald Welte70767382018-02-21 12:16:40 +0100185 timer g_Tguard;
186 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
187
188 var ConnHdlrPars g_pars;
189 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100190 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200191
192 /* PCU Interface of BTS */
193 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100194}
195
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700196private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700197 var bitstring trx_mask := '00000000'B;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200198 var bitstring rfind_mask := '00000000'B;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700199 var integer trx_count := 0;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200200 var integer rfind_count := 0;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700201 var RSLEm_Event ev;
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200202 var ASP_RSL_Unitdata rx_ud;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700203 timer T;
204
Harald Welte70767382018-02-21 12:16:40 +0100205 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
206 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
207
208 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
209 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
210 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
211
212 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
213 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700214
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700215 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700216 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700217 T.start(mp_ipa_up_timeout);
218 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700219 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700220 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
221 /* Make sure that all transceivers use unique stream ID */
222 if (trx_mask[enum2int(ev.sid)] == '1'B) {
223 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
224 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
225 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700226
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700227 trx_mask[enum2int(ev.sid)] := '1'B;
228 trx_count := trx_count + 1;
229
230 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200231 repeat;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700232 }
Pau Espin Pedrol9a053c02020-10-16 13:52:28 +0200233 /* This message (RF RESource INDication) is sent by the IUT itself */
234 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ?)) -> value rx_ud {
235 if (trx_mask[enum2int(rx_ud.streamId)] == '0'B) {
236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
237 log2str("Got RF Resource Indication before RSLEM_EV_TRX_UP (", rx_ud.streamId, ")"));
238 }
239 if (rfind_mask[enum2int(rx_ud.streamId)] == '1'B) {
240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
241 log2str("Duplicate RF Resource Indication ID (", rx_ud.streamId, ")"));
242 }
243
244 rfind_mask[enum2int(rx_ud.streamId)] := '1'B;
245 rfind_count := rfind_count + 1;
246 log(rfind_count, "/", mp_transceiver_num, " RF Resource Indication(s) received");
247 if (rfind_count < mp_transceiver_num) { repeat; }
248 }
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700249 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
250 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
251 [] T.timeout {
252 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
253 "Timeout waiting for RSL bring up");
254 }
255 }
Harald Welte70767382018-02-21 12:16:40 +0100256}
257
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700258friend type record FreqHopPars {
259 /* Whether frequency hopping is in use */
260 boolean enabled,
261 /* Mobile Allocation Index Offset / Hopping Sequence Number */
262 MaioHsn maio_hsn,
263 /* MA bitmap to be indicated in RR Immediate Assignment */
264 MobileAllocationLV ma_map,
265 /* The actual Mobile Allocation (ARFCN list) to be used */
266 L1ctlMA ma
267};
268
Harald Welte70767382018-02-21 12:16:40 +0100269type record ConnHdlrPars {
270 RslChannelNr chan_nr,
271 RSL_IE_ChannelMode chan_mode,
272 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100273 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200274 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200275 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700276 BtsBand bts0_band optional,
277
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700278 /* Frequency hopping parameters */
279 FreqHopPars fhp
280};
Harald Welte0472ab42018-03-12 15:02:26 +0100281
282/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700283private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100284 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100285}
286
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700287private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100288 max_retrans := RACH_MAX_RETRANS_7,
289 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100290 cell_barr_access := false,
291 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100292 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100293};
294
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700295private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100296 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200297 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100298 acs := '0'B,
299 neci := true,
300 rxlev_access_min := 0
301}
302
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700303private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100304 mcc_mnc := '262F42'H,
305 lac := 42
306}
307
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700308private template (value) GPRSIndicator ts_GPRSIndicator_def := {
309 ra_colour := 0,
310 si13_pos := '0'B
311}
312
313private template (value) SI3RestOctets ts_SI3RestOctets_def
314modifies ts_SI3RestOctets := {
315 gprs_ind := {
316 presence := CSN1_H,
317 ind := ts_GPRSIndicator_def
318 }
319}
320
321private template (value) SI4RestOctets ts_SI4RestOctets_def
322modifies ts_SI4RestOctets := {
323 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700324 presence := CSN1_H,
325 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700326 }
327}
328
Harald Welte7484fc42018-02-24 14:09:45 +0100329/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700330private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100331 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100332 payload := {
333 si3 := {
334 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100335 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100336 ctrl_chan_desc := {
337 msc_r99 := true,
338 att := true,
339 bs_ag_blks_res := 1,
340 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100341 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100342 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
343 spare := '00'B,
344 bs_pa_mfrms := 0, /* 2 multiframes */
345 t3212 := 1 /* 6 minutes */
346 },
Harald Welte82ccef72018-02-25 16:17:33 +0100347 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100348 dn_ind := false,
349 pwrc := false,
350 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100351 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100352 },
Harald Weltef10153f2018-02-25 16:34:05 +0100353 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100354 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200355 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100356 }
357 }
358}
Harald Welte70767382018-02-21 12:16:40 +0100359
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700360private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100361 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100362 payload := {
363 si2 := {
364 bcch_freq_list := '00000000000000000000000000000000'O,
365 ncc_permitted := '11111111'B,
366 rach_control := ts_RachCtrl_default
367 }
368 }
369}
370
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700371private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100372 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100373 payload := {
374 si4 := {
375 lai := ts_LAI_default,
376 cell_sel_par := ts_CellSelPar_default,
377 rach_control := ts_RachCtrl_default,
378 cbch_chan_desc := omit,
379 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200380 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100381 }
382 }
383}
384
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700385private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100386runs on test_CT {
387 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700388 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100389}
390
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700391private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100392runs on test_CT {
393 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
394 log("Setting ", rsl_si_type, ": ", si_dec);
395 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
396}
397
Harald Welte505cf9b2018-09-15 17:47:23 +0300398friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100399 map(self:BTSVTY, system:BTSVTY);
400 f_vty_set_prompts(BTSVTY);
401 f_vty_transceive(BTSVTY, "enable");
402}
403
Harald Welte505cf9b2018-09-15 17:47:23 +0300404friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200405 map(self:BSCVTY, system:BSCVTY);
406 f_vty_set_prompts(BSCVTY, "OsmoBSC");
407 f_vty_transceive(BSCVTY, "enable");
408}
409
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200410friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
411 map(self:BSCVTY, system:BSCVTY);
412 f_vty_set_prompts(BSCVTY, "OsmoBSC");
413 f_vty_transceive(BSCVTY, "enable");
414}
415
Harald Welte883340c2018-02-28 18:59:29 +0100416/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200417private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
418 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100419 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200420 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
421 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100422 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200423 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200424 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100425 }
426}
427
Harald Weltef26de0b2018-04-04 20:28:05 +0200428private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
429 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100430 timer T := 2.0;
431 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100432 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200433 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100434 return;
435 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200436 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100437
438 T.start;
439 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200440 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100441 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200442 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100443 }
444 }
445}
446
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700447private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
448 out integer trxc_conn_id) {
449 var Result res;
450
451 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
452 "", -1, -1, { udp := {} }, {});
453 if (not ispresent(res.connId)) {
454 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
455 "Could not connect to the control (TRXC) interface " &
456 "of FakeTRX, check your configuration");
457 }
458 trxc_conn_id := res.connId;
459}
460
Harald Welte70767382018-02-21 12:16:40 +0100461/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700462friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200463 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100464 g_AllChannels := {
465 /* TS 1..4: TCH/F */
466 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
467 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
468 /* TS 5: TCH/H */
469 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
470 /* TS 0: SDCCH/4 */
471 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
472 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
473 /* TS 6: SDCCH/8 */
474 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
475 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
476 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
477 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
478 };
479
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200480 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700481 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200482 g_AllChanTypes := {
483 /* TS 1..4: TCH/F */
484 valueof(ts_RslChanNr_Bm(1)),
485 /* TS 5: TCH/H */
486 valueof(ts_RslChanNr_Lm(5,1)),
487 /* TS 0: SDCCH/4 */
488 valueof(ts_RslChanNr_SDCCH4(0,2)),
489 /* TS 6: SDCCH/8 */
490 valueof(ts_RslChanNr_SDCCH8(6,4))
491 };
492 } else {
493 g_AllChanTypes := {
494 /* TS 1..4: TCH/F */
495 valueof(ts_RslChanNr_Bm(1)),
496 /* TS 0: SDCCH/4 */
497 valueof(ts_RslChanNr_SDCCH4(0,2)),
498 /* TS 6: SDCCH/8 */
499 valueof(ts_RslChanNr_SDCCH8(6,4))
500 };
501 }
Harald Welte70767382018-02-21 12:16:40 +0100502 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100503 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100504 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200505 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100506
507 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100508 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
509 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
510 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
511 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100512
Harald Weltef26de0b2018-04-04 20:28:05 +0200513 map(self:PCU, system:PCU);
514 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100515
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700516 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100517 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700518
519 /* Init TRXC interface to FakeTRX */
520 map(self:BTS_TRXC, system:BTS_TRXC);
521 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
522
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700523 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700524 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700525 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700526 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
527 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100528 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200529
530 /* Wait some extra time to make sure the BTS emits a stable carrier.
531 * (this is only relevant when running the tests with a physical BTS.) */
532 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100533}
534
Harald Welte68e495b2018-02-25 00:05:57 +0100535/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700536friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100537 map(self:L1CTL, system:L1CTL);
538 f_connect_reset(L1CTL);
539}
540
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700541private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100542
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700543private type record length(8) of FreqHopGroups FreqHopConfig;
544
545private type record of FreqHopGroup FreqHopGroups;
546private type record FreqHopGroup {
547 uint6_t hsn,
548 FreqHopGroupItems trx_maio
549};
550
551private type record of FreqHopGroupItem FreqHopGroupItems;
552private type record FreqHopGroupItem {
553 uint8_t trx_nr,
554 uint6_t maio
555};
556
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700557friend function f_resolve_fh_params(inout FreqHopPars fhp, uint8_t tn,
558 uint8_t trx_nr := 0)
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700559{
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700560 var FreqHopGroups groups := mp_fh_config[tn];
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700561 var integer i, j;
562
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700563 fhp.enabled := false;
564
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700565 for (i := 0; i < lengthof(groups); i := i + 1) {
566 var FreqHopGroup g := groups[i];
567 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
568 var FreqHopGroupItem gi := g.trx_maio[j];
569 if (gi.trx_nr == trx_nr) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700570 fhp.maio_hsn.maio := gi.maio;
571 fhp.maio_hsn.hsn := g.hsn;
572 fhp.enabled := true;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700573 break;
574 }
575 }
576
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700577 if (fhp.enabled) {
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700578 /* Prepare the Mobile Allocation bitmask (length & padding) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700579 fhp.ma_map.len := (mp_transceiver_num + 8 - 1) / 8; /* in bytes */
580 fhp.ma_map.ma := f_pad_bit('0'B, fhp.ma_map.len * 8, '0'B);
581 fhp.ma := { }; /* to be composed below */
Vadim Yanitskiy4fa74252020-08-03 15:51:58 +0700582
583 /* Compose the actual Mobile Allocation and the bitmask */
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700584 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
585 var FreqHopGroupItem gi := g.trx_maio[j];
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700586 fhp.ma := fhp.ma & { l1ctl_ma_def[gi.trx_nr] };
587 fhp.ma_map.ma[gi.trx_nr] := '1'B;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700588 }
589
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700590 log("Freq. hopping parameters: ", fhp);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700591 break; /* We're done */
592 }
593 }
594}
595
Harald Welte70767382018-02-21 12:16:40 +0100596/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700597friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
598 boolean pcu_comp := false,
599 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100600runs on test_CT return ConnHdlr {
601 var charstring id := testcasename();
602 var ConnHdlr vc_conn;
603
604 vc_conn := ConnHdlr.create(id);
605 /* connect to RSL Emulation main component */
606 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
607 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700608
609 /* The ConnHdlr component may want to talk to some ports directly,
610 * so we disconnect it from the test_CT and connect it to the component.
611 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200612 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200613 unmap(self:PCU, system:PCU);
614 map(vc_conn:PCU, system:PCU);
615 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700616 if (trxc_comp) {
617 unmap(self:BTS_TRXC, system:BTS_TRXC);
618 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
619 }
Harald Welte70767382018-02-21 12:16:40 +0100620
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700621 /* Obtain frequency hopping parameters for a given timeslot */
622 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700623 f_resolve_fh_params(pars.fhp, pars.chan_nr.tn);
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700624 }
625
Harald Welte70767382018-02-21 12:16:40 +0100626 vc_conn.start(f_handler_init(fn, id, pars));
627 return vc_conn;
628}
629
Harald Welte70767382018-02-21 12:16:40 +0100630private altstep as_Tguard() runs on ConnHdlr {
631 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100633 }
634}
635
Harald Welte990a3612019-05-27 14:02:13 +0200636friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
637 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100638}
639
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700640private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100641 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700642 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100643}
644
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700645private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100646 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700647 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100648}
649
650/* first function started in ConnHdlr component */
651private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
652runs on ConnHdlr {
653 g_pars := pars;
654 g_chan_nr := pars.chan_nr;
655
656 map(self:L1CTL, system:L1CTL);
657 f_connect_reset(L1CTL);
658
Harald Welted48c0c72019-06-05 10:01:15 +0200659 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700660 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100661 }
Harald Welte70767382018-02-21 12:16:40 +0100662
663 g_Tguard.start(pars.t_guard);
664 activate(as_Tguard());
665
666 f_rslem_register(0, pars.chan_nr);
667
668 /* call the user-supplied test case function */
669 fn.apply(id);
670}
671
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700672private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
673 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200674runs on ConnHdlr return RSL_Message {
675 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100676 timer T := 3.0;
677 RSL.send(tx);
678 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100679 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200680 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100681 T.stop;
682 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100683 }
Harald Welte1eba3742018-02-25 12:48:14 +0100684 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200685 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100686 }
Harald Welte21240e62018-03-11 21:43:35 +0100687 [not ignore_other] as_l1_sacch();
688 [not ignore_other] as_meas_res();
689 [not ignore_other] as_l1_dcch();
690 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100692 }
Harald Welte21240e62018-03-11 21:43:35 +0100693 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100694 }
Harald Welteb1726c92018-03-30 11:56:38 +0200695 return rx;
696}
697
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700698friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
699 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200700runs on ConnHdlr {
701 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100702}
703
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700704friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
705 boolean encr_enable := false,
706 RSL_IE_List more_ies := {},
707 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
708runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200709 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200710 if (encr_enable) {
711 /* append encryption related IEs, if requested */
712 var RSL_IE_EncryptionInfo encr_info;
713 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
714 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
715encr_info})) };
716 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200717 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200718 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100719}
720
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700721friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100722 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 +0100723 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100724}
725
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700726/* Default Mobile Allocation to be used for frequency hopping */
727private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
728 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
729
Harald Welte2f2b2b72019-05-31 22:24:57 +0200730friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100731 template RSL_IE_ChannelMode chan_mode,
732 float t_guard := 20.0) := {
733 chan_nr := valueof(chan_nr),
734 chan_mode := valueof(chan_mode),
735 t_guard := t_guard,
736 l1_pars := {
737 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100738 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100739 meas_ul := {
740 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200741 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100742 rxqual := 0
743 },
744 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200745 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100746 rxqual := 0
747 }
748 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200749 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100750 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200751 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200752 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100753 },
Harald Weltee613f962018-04-18 22:38:16 +0200754 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200755 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700756 bts0_band := omit,
Vadim Yanitskiyca813922020-09-12 19:08:31 +0700757 fhp := {
758 enabled := false,
759 maio_hsn := ts_HsnMaio(0, 0),
760 ma_map := c_MA_null,
761 ma := l1ctl_ma_def
762 }
Harald Welte70767382018-02-21 12:16:40 +0100763}
764
Harald Welte93640c62018-02-25 16:59:33 +0100765/***********************************************************************
766 * Channel Activation / Deactivation
767 ***********************************************************************/
768
Harald Welte70767382018-02-21 12:16:40 +0100769/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700770private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100771 for (var integer i := 0; i < 500; i := i+1) {
772 f_rsl_chan_act(g_pars.chan_mode);
773 f_rsl_chan_deact();
774 }
775 setverdict(pass);
776}
777testcase TC_chan_act_stress() runs on test_CT {
778 var ConnHdlr vc_conn;
779 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200780 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100781 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
782 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200783 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100784}
785
786/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700787private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100788 f_rsl_chan_act(g_pars.chan_mode);
789 /* attempt to activate the same lchan again -> expect reject */
790 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
791 alt {
792 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200793 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100794 }
795 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
796 setverdict(pass);
797 }
798 }
799 f_rsl_chan_deact();
800}
801testcase TC_chan_act_react() runs on test_CT {
802 var ConnHdlr vc_conn;
803 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100804 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100805 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
806 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200807 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100808}
809
810/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700811private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100812 timer T := 3.0;
813 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
814 T.start;
815 alt {
816 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
817 setverdict(pass);
818 }
819 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100821 }
822 }
823}
824testcase TC_chan_deact_not_active() runs on test_CT {
825 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100826 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100827 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
828 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100830}
831
832/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700833private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100834 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
835 alt {
836 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200837 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100838 }
839 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
840 setverdict(pass);
841 }
842 }
843}
844private type record WrongChanNrCase {
845 RslChannelNr chan_nr,
846 charstring description
847}
848private type record of WrongChanNrCase WrongChanNrCases;
849private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
850 chan_nr := chan_nr,
851 description := desc
852}
853
854testcase TC_chan_act_wrong_nr() runs on test_CT {
855 var ConnHdlr vc_conn;
856 var ConnHdlrPars pars;
857
Harald Welte294b0a22018-03-10 23:26:48 +0100858 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100859
860 var WrongChanNrCases wrong := {
861 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
862 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
863 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
864 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
865 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
866 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
867 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
868 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
869 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
870 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
871 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
872 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
873 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
874 };
875
876 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
877 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
878 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
879 vc_conn.done;
880 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100882}
883
Harald Weltee613f962018-04-18 22:38:16 +0200884/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200885friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200886 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200887 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200888
889 /* test on each of the channels we have */
890 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
891 pars.chan_nr := valueof(g_AllChanTypes[i]);
892
893 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
894 vc_conn := f_start_handler(fn, pars);
895 vc_conn.done;
896 }
897
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200899}
900
Harald Welte93640c62018-02-25 16:59:33 +0100901/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100902 * SACCH handling
903 ***********************************************************************/
904
905private function f_exp_sacch(boolean exp) runs on ConnHdlr {
906 timer T_sacch := 3.0;
907 T_sacch.start;
908 alt {
909 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100911 }
912 [not exp] T_sacch.timeout {
913 setverdict(pass);
914 }
915 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
916 setverdict(pass);
917 }
918 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200919 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100920 }
921 [] L1CTL.receive { repeat; }
922 [] RSL.receive { repeat; }
923 }
924}
925
926/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
927private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
928 f_l1_tune(L1CTL);
929 RSL.clear;
930
931 /* activate the logical channel */
932 f_est_dchan();
933 L1CTL.clear;
934
935 /* check that SACCH actually are received as expected */
936 f_exp_sacch(true);
937
938 /* deactivate SACCH on the logical channel */
939 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
940 f_sleep(1.0);
941 L1CTL.clear;
942
943 /* check that no SACCH are received anymore */
944 f_exp_sacch(false);
945
946 /* release the channel */
947 f_rsl_chan_deact();
948 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
949}
950testcase TC_deact_sacch() runs on test_CT {
951 var ConnHdlr vc_conn;
952 var ConnHdlrPars pars;
953 f_init();
954 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
955 //for (var integer i := 0; i < 1; i := i+1) {
956 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
957 log(testcasename(), ": Starting for ", g_AllChannels[i]);
958 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
959 vc_conn.done;
960 }
961 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200962 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100963}
964
Harald Welte55700662018-03-12 13:15:43 +0100965/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100966private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
967 var L1ctlDlMessage dl;
968 /* check that the specified SI5 value is actually sent */
969 timer T_sacch := 3.0;
970 L1CTL.clear;
971 T_sacch.start;
972 alt {
973 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
974 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
975 if (match(l3, l3_exp)) {
976 setverdict(pass);
977 } else {
978 repeat;
979 }
980 }
981 [] L1CTL.receive { repeat; }
982 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100984 }
985 }
986}
987
Harald Welte55700662018-03-12 13:15:43 +0100988/* verify that given SACCH payload is not present */
989private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
990 var L1ctlDlMessage dl;
991 /* check that the specified SI5 value is actually sent */
992 timer T_sacch := 3.0;
993 L1CTL.clear;
994 T_sacch.start;
995 alt {
996 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
997 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
998 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200999 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +01001000 } else {
1001 repeat;
1002 }
1003 }
1004 [] L1CTL.receive { repeat; }
1005 [] T_sacch.timeout {
1006 setverdict(pass);
1007 }
1008 }
1009}
1010
Harald Welte629cc6b2018-03-11 17:19:05 +01001011/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +01001012private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
1013 /* Set a known default SACCH filling for SI5 */
1014 var octetstring si5 := f_rnd_octstring(19);
1015 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1016
1017 f_l1_tune(L1CTL);
1018 RSL.clear;
1019
1020 /* activate the logical channel */
1021 f_est_dchan();
1022
1023 /* check that the specified SI5 value is actually sent */
1024 f_sacch_present(si5);
1025
1026 /* release the channel */
1027 RSL.clear;
1028 f_rsl_chan_deact();
1029 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1030}
1031testcase TC_sacch_filling() runs on test_CT {
1032 var ConnHdlr vc_conn;
1033 var ConnHdlrPars pars;
1034 f_init();
1035 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1036 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1037 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1038 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1039 vc_conn.done;
1040 }
1041 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001043}
1044
Harald Welte629cc6b2018-03-11 17:19:05 +01001045/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001046private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1047 /* Set a known default SACCH filling for SI5 */
1048 var octetstring si5 := f_rnd_octstring(19);
1049 var octetstring si5_diff := f_rnd_octstring(19);
1050 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1051
1052 f_l1_tune(L1CTL);
1053 RSL.clear;
1054
1055 log("Activating channel, expecting standard SI5");
1056 /* activate the logical channel */
1057 f_est_dchan();
1058 /* check that the specified SI5 value is actually sent */
1059 f_sacch_present(si5);
1060
1061 /* set channel-specific different SI5 */
1062 log("Setting channel specific SACCH INFO, expecting it");
1063 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1064 /* check that the specified lchan-specific value is now used */
1065 f_sacch_present(si5_diff);
1066
1067 /* deactivate the channel and re-activate it, this should result in default SI5 */
1068 log("De-activating and re-activating channel, expecting standard SI5");
1069 f_rsl_chan_deact();
1070 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1071 /* Verify that the TRX-wide default SACCH filling is present again */
1072 f_sacch_present(si5);
1073
1074 /* release the channel */
1075 RSL.clear;
1076 f_rsl_chan_deact();
1077 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1078}
1079testcase TC_sacch_info_mod() runs on test_CT {
1080 var ConnHdlr vc_conn;
1081 var ConnHdlrPars pars;
1082 f_init();
1083 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1084 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1085 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1086 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1087 vc_conn.done;
1088 }
1089 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001091}
1092
Harald Welte075d84c2018-03-12 13:07:24 +01001093/* Test SACCH scheduling of multiple different SI message types */
1094private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1095 var octetstring si5 := f_rnd_octstring(19);
1096 var octetstring si5bis := f_rnd_octstring(19);
1097 var octetstring si5ter := f_rnd_octstring(19);
1098 var octetstring si6 := f_rnd_octstring(19);
1099
1100 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1101 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1102 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1103 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1104
1105 f_l1_tune(L1CTL);
1106 RSL.clear;
1107
1108 /* activate the logical channel */
1109 f_est_dchan();
1110 L1CTL.clear;
1111
1112 /* check that SACCH actually are received as expected */
1113 f_sacch_present(si5);
1114 f_sacch_present(si5bis);
1115 f_sacch_present(si5ter);
1116 f_sacch_present(si6);
1117
1118 /* release the channel */
1119 f_rsl_chan_deact();
1120 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1121}
1122testcase TC_sacch_multi() runs on test_CT {
1123 var ConnHdlr vc_conn;
1124 var ConnHdlrPars pars;
1125 f_init();
1126 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1127 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1128 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1129 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1130 vc_conn.done;
1131 }
1132 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001134}
1135
Harald Welte55700662018-03-12 13:15:43 +01001136/* Test if SACH information is modified as expected */
1137private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1138 var octetstring si5 := f_rnd_octstring(19);
1139 var octetstring si6 := f_rnd_octstring(19);
1140
1141 /* First, configure both SI5 and SI6 to be transmitted */
1142 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1143 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1144
1145 f_l1_tune(L1CTL);
1146 RSL.clear;
1147
1148 /* activate the logical channel */
1149 f_est_dchan();
1150 L1CTL.clear;
1151
1152 /* check that SACCH actually are received as expected */
1153 f_sacch_present(si5);
1154 f_sacch_present(si6);
1155
1156 /* disable SI6 */
1157 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1158
1159 /* check that SI5 is still transmitted */
1160 f_sacch_present(si5);
1161 /* check if SI6 is now gone */
1162 f_sacch_missing(si6);
1163
1164 /* release the channel */
1165 f_rsl_chan_deact();
1166 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1167}
1168testcase TC_sacch_multi_chg() runs on test_CT {
1169 var ConnHdlr vc_conn;
1170 var ConnHdlrPars pars;
1171 f_init();
1172 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1173 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1174 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1175 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1176 vc_conn.done;
1177 }
1178 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001180}
1181
Harald Weltec8d363c2019-05-19 20:36:48 +02001182/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1183private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1184 var octetstring si5 := f_rnd_octstring(19);
1185 var octetstring si6 := f_rnd_octstring(19);
1186 var octetstring si5_specific := f_rnd_octstring(19);
1187 var octetstring si6_specific := f_rnd_octstring(19);
1188
1189 /* First, configure both SI5 and SI6 to be transmitted */
1190 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1191 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1192
1193 f_l1_tune(L1CTL);
1194 RSL.clear;
1195
1196 /* activate channel with different SACCH filling */
1197 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1198 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1199 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1200 }));
1201 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1202 RSL_IE_Body:{sacch_info := sacch_info})) };
1203 f_est_dchan(more_ies := addl_ies);
1204
1205 /* check that SACCH actually are received as expected */
1206 f_sacch_present(si5_specific);
1207 f_sacch_present(si6_specific);
1208
1209 /* release the channel */
1210 f_rsl_chan_deact();
1211 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1212}
1213testcase TC_sacch_chan_act() runs on test_CT {
1214 var ConnHdlr vc_conn;
1215 var ConnHdlrPars pars;
1216 f_init();
1217
1218 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1219 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1220 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1221 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1222 vc_conn.done;
1223 }
1224 /* TODO: do the above in parallel, rather than sequentially? */
1225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1226}
1227
Harald Welte8b01c792019-05-19 22:51:25 +02001228/* verify that SACCH DL transmission is started only if MS power IE present
1229 * see section 4.1.3 of 3GPP TS 48.058 */
1230private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1231 var octetstring si5 := f_rnd_octstring(19);
1232
1233 f_l1_tune(L1CTL);
1234 RSL.clear;
1235
1236 /* Step 1: Activate ASYNC HO channel without MS power IE */
1237
1238 /* Activate channel on BTS side */
1239 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1240 /* don't perform immediate assignment here, as we're testing non-IA case */
1241 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001242 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001243
1244 /* Verify that no DL SACCH is being received */
1245 f_sacch_missing(?);
1246
1247 f_rsl_chan_deact();
1248 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1249
1250
1251 /* Step 2: Activate ASYNC HO channel with MS power IE */
1252
1253 /* Activate channel on BTS side */
1254 var RSL_IE_List addl_ies := {
1255 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1256 };
1257 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1258 /* don't perform immediate assignment here, as we're testing non-IA case */
1259 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001260 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001261
1262 /* Verify that DL SACCH is being received */
1263 f_sacch_present(si5);
1264
1265 f_rsl_chan_deact();
1266 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1267}
1268testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1269 var ConnHdlr vc_conn;
1270 var ConnHdlrPars pars;
1271 f_init();
1272
1273 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1274 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1275 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1276 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1277 vc_conn.done;
1278 }
1279 /* TODO: do the above in parallel, rather than sequentially? */
1280 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1281}
1282
1283/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1284 * see section 4.1.4 of 3GPP TS 48.058 */
1285private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1286 var octetstring si5 := f_rnd_octstring(19);
1287 var RSL_IE_List addl_ies;
1288
1289 f_l1_tune(L1CTL);
1290 RSL.clear;
1291
1292 /* Step 1: Activate SYNC HO channel without MS power IE */
1293
1294 /* Activate channel on BTS side */
1295 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1296 /* don't perform immediate assignment here, as we're testing non-IA case */
1297 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001298 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001299
1300 /* Verify that no DL SACCH is being received */
1301 f_sacch_missing(?);
1302
1303 f_rsl_chan_deact();
1304 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1305
1306
1307 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1308
1309 /* Activate channel on BTS side */
1310 addl_ies := {
1311 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1312 };
1313 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1314 /* don't perform immediate assignment here, as we're testing non-IA case */
1315 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001316 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001317
1318 /* Verify that no DL SACCH is being received */
1319 f_sacch_missing(?);
1320
1321 f_rsl_chan_deact();
1322 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1323
1324
1325 /* Step 2b: Activate SYNC HO channel with TA IE */
1326
1327 /* Activate channel on BTS side */
1328 addl_ies := {
1329 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1330 };
1331 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1332 /* don't perform immediate assignment here, as we're testing non-IA case */
1333 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001334 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001335
1336 /* Verify that no DL SACCH is being received */
1337 f_sacch_missing(?);
1338
1339 f_rsl_chan_deact();
1340 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1341
1342
1343 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1344
1345 /* Activate channel on BTS side */
1346 addl_ies := {
1347 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1348 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1349 };
1350 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1351 /* don't perform immediate assignment here, as we're testing non-IA case */
1352 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001353 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001354
1355 /* Verify that DL SACCH is being received */
1356 f_sacch_present(si5);
1357
1358 f_rsl_chan_deact();
1359 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1360}
1361testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1362 var ConnHdlr vc_conn;
1363 var ConnHdlrPars pars;
1364 f_init();
1365
1366 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1367 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1368 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1369 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1370 vc_conn.done;
1371 }
1372 /* TODO: do the above in parallel, rather than sequentially? */
1373 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1374}
Harald Welte629cc6b2018-03-11 17:19:05 +01001375
1376
1377/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001378 * RACH Handling
1379 ***********************************************************************/
1380
Harald Welte8c24c2b2018-02-26 08:31:31 +01001381/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001382private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001383 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001384 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001385 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001386
Harald Welte8c24c2b2018-02-26 08:31:31 +01001387 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001388 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001389 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001390 var OCT1 ra := f_rnd_ra_emerg();
1391 if (emerg == true) {
1392 ra := f_rnd_ra_emerg();
1393 } else {
1394 ra := f_rnd_ra_cs();
1395 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001396 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1397 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001399 }
1400 fn_last := fn;
1401
1402 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001403 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001404 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001405 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001406 T.stop;
1407 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001408 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001410 }
1411 [] RSL_CCHAN.receive { repeat; }
1412 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001413 test_failed := true;
1414 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001415 }
1416 }
1417 }
Maxba06feb2019-03-05 10:52:46 +01001418 if (test_failed) {
1419 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001420 }
Maxba06feb2019-03-05 10:52:46 +01001421 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001423}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001424
Philipp Maier16ade782020-07-08 21:36:00 +02001425/* Normal variant */
1426testcase TC_rach_content() runs on test_CT {
1427 f_TC_rach_content(emerg := false);
1428}
1429
1430/* Emergency call variant */
1431testcase TC_rach_content_emerg() runs on test_CT {
1432 f_TC_rach_content(emerg := true);
1433}
1434
Harald Welte8c24c2b2018-02-26 08:31:31 +01001435/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1436testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001437 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001438 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001439 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001440 f_l1_tune(L1CTL);
1441
1442 var GsmFrameNumber fn_last := 0;
1443 for (var integer i := 0; i < 1000; i := i+1) {
1444 var OCT1 ra := f_rnd_ra_cs();
1445 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1446 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001447 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001448 }
1449 fn_last := fn;
1450 }
1451 var integer rsl_chrqd := 0;
1452 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001453 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001454 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001455 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001456 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001457 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001458 repeat;
1459 }
1460 [] RSL_CCHAN.receive { repeat; }
1461 [] T.timeout { }
1462 }
1463 if (rsl_chrqd == 1000) {
1464 setverdict(pass);
1465 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001467 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001468 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001469}
1470
Harald Welte3453ab42019-05-24 21:19:58 +02001471private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1472 var charstring bts_str := "bts " & int2str(bts_nr);
1473 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1474}
1475
1476/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1477private template integer tr_rach_slots_per_interval := (90 .. 130);
1478
1479/* Expect 0 RACH load on an idle BTS that has just started up */
1480testcase TC_rach_load_idle_thresh0() runs on test_CT {
1481 var ASP_RSL_Unitdata rx_ud;
1482
1483 f_init_vty_bsc();
1484 /* send load indications even at 0% load */
1485 f_vty_load_ind_thresh(0);
1486 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1487 f_sleep(2.0);
1488
1489 f_init();
1490
Harald Weltee37f9a52020-10-11 20:45:23 +02001491 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1492 alt {
1493 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1494 [] RSL_CCHAN.receive { repeat }
1495 }
1496
Harald Welte3453ab42019-05-24 21:19:58 +02001497 timer T := 5.0;
1498 T.start;
1499 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001500 [] 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 +02001501 setverdict(pass);
1502 repeat;
1503 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001504 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001505 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1506 repeat;
1507 }
1508 [] RSL_CCHAN.receive {
1509 repeat;
1510 }
1511 [] T.timeout { }
1512 }
1513
1514 f_vty_load_ind_thresh(10);
1515 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1516}
1517
1518/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1519testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1520 var ASP_RSL_Unitdata rx_ud;
1521
1522 f_init_vty_bsc();
1523 f_init();
1524
1525 timer T := 5.0;
1526 T.start;
1527 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001528 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001529 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1530 repeat;
1531 }
1532 [] RSL_CCHAN.receive {
1533 repeat;
1534 }
1535 [] T.timeout {
1536 setverdict(pass);
1537 }
1538 }
1539
1540 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1541}
1542
1543/* Expect 0 RACH load on an idle BTS that has just started up */
1544testcase TC_rach_load_count() runs on test_CT {
1545 var ASP_RSL_Unitdata rx_ud;
1546 var integer load_access_count := 0;
1547
1548 f_init_vty_bsc();
1549 /* send load indications even at 0% load */
1550 f_vty_load_ind_thresh(0);
1551 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1552 f_sleep(2.0);
1553 f_init();
1554
1555 f_init_l1ctl();
1556 f_sleep(1.0);
1557 f_l1_tune(L1CTL);
1558
Harald Welte52ae1682020-10-11 20:45:55 +02001559 /* Skip the first RACH LOAD IND, as it may not have the full slot count (BTS started less than 1s before) */
1560 alt {
1561 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) { }
1562 [] RSL_CCHAN.receive { repeat }
1563 }
1564
Harald Welte3453ab42019-05-24 21:19:58 +02001565 var GsmFrameNumber fn_last := 0;
1566 for (var integer i := 0; i < 1000; i := i+1) {
1567 var OCT1 ra := f_rnd_ra_cs();
1568 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1569 if (fn == fn_last) {
1570 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1571 }
1572 fn_last := fn;
1573 }
1574
1575 timer T := 5.0;
1576 T.start;
1577 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001578 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001579 -> value rx_ud {
1580 var RSL_IE_Body ie;
1581 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1582 load_access_count := load_access_count + ie.rach_load.access_count;
1583 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1584 setverdict(fail, "Access count cannot be < Busy count");
1585 }
1586 repeat;
1587 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001588 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001589 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1590 repeat;
1591 }
1592 [] RSL_CCHAN.receive {
1593 repeat;
1594 }
1595 [] T.timeout { }
1596 }
1597 if (load_access_count == 1000) {
1598 setverdict(pass);
1599 } else {
1600 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1601 }
1602
1603 f_vty_load_ind_thresh(10);
1604 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1605}
1606
Harald Welte54a2a2d2018-02-26 09:14:05 +01001607private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001608 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001609 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001610 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001611 f_sleep(0.5);
1612
1613 /* Transmit RACH request + wait for confirmation */
1614 var OCT1 ra := f_rnd_ra_cs();
1615 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1616
1617 /* Check for expected result */
1618 timer T := 1.5;
1619 T.start;
1620 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001621 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001622 setverdict(pass);
1623 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001624 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001625 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001626 }
1627 [] RSL_CCHAN.receive { repeat; }
1628 [not expect_pass] T.timeout {
1629 setverdict(pass);
1630 }
1631 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001632 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001633 }
1634 }
1635}
1636
1637/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1638testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001639 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001640 f_init_l1ctl();
1641 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001642 f_sleep(1.0);
1643
1644 /* default max-ta is 63 (full range of GSM timing advance */
1645
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001646 /* We allow early arrival up to 2 symbols */
1647 f_rach_toffs(-1*256, true);
1648 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001649 f_rach_toffs(-10*256, false);
1650
1651 /* 0 / 32 / 63 bits is legal / permitted */
1652 f_rach_toffs(0, true);
1653 f_rach_toffs(32*256, true);
1654 f_rach_toffs(63*256, true);
1655
1656 /* more than 63 bits is not legal / permitted */
1657 f_rach_toffs(64*256, false);
1658 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001659 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001660}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001661
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001662private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001663 var GsmFrameNumber fn;
1664 var RSL_Message rm;
1665
1666 f_l1_tune(L1CTL);
1667 RSL.clear;
1668
1669 /* Generate a random Handover Reference */
1670 var integer ho_ref := oct2int(f_rnd_octstring(1));
1671
1672 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1673 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1674 RSL_IE_Body:{ handover_ref := ho_ref }));
1675
1676 /* Activate a channel on the BTS side (no encryption) */
1677 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1678 act_type := t_RSL_IE_ActType_HO_SYNC);
1679
1680 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1681 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001682 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001683
1684 /* Send handover Access Burst */
1685 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1686
1687 /* TODO: test mismatching Handover Reference, and missing IE */
1688
1689 /* Wait for handover detection */
1690 timer T := 3.0;
1691 T.start;
1692 alt {
1693 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1694 log("Handover RACH has been detected: ", rm);
1695 setverdict(pass);
1696 }
1697 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1698 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1699 log2str("RSL_CHAN_RQD was not expected: ", rm));
1700 }
1701 [] RSL.receive { repeat; }
1702 [] T.timeout {
1703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1704 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1705 }
1706 }
1707
1708 /* Release the channel */
1709 f_rsl_chan_deact();
1710 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1711}
1712
1713/* Test handover RACH detection */
1714testcase TC_ho_rach() runs on test_CT {
1715 var ConnHdlrPars pars;
1716 var ConnHdlr vc_conn;
1717
1718 f_init();
1719
1720 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1721 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1722 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1723 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1724 vc_conn.done;
1725 }
1726
1727 /* TODO: do the above in parallel, rather than sequentially? */
1728 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1729}
1730
Harald Welte93640c62018-02-25 16:59:33 +01001731/***********************************************************************
1732 * Measurement Processing / Reporting
1733 ***********************************************************************/
1734
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001735private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001736 spare := '0'B,
1737 lpd := 0,
1738 sapi := sapi,
1739 c_r := c_r,
1740 ea := true
1741}
1742
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001743private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001744 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001745 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001746 len := 0, /* overwritten */
1747 m := false,
1748 el := 1,
1749 payload := pl
1750}
1751
1752/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001753private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001754 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001755 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001756 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001757 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, mp_rxlev_exp, mp_rxlev_exp, 0, 0, omit));
Harald Welted879bd92018-03-12 15:01:23 +01001758 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001759 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001760
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001761 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1762 g_pars.l1_pars.ms_power_level, false,
1763 g_pars.l1_pars.ms_actual_ta);
1764
1765 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1766 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1767
1768 log("Sending Measurement Report: ", l1h, l2);
1769 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001770 repeat;
1771 }
1772}
1773
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001774private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001775 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001776 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001777 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1778 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001779 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1780 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001781 repeat;
1782 }
1783}
1784
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001785private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001786 uint6_t rxlev,
1787 uint3_t rxqual
1788}
1789
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001790private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001791 MeasElem full,
1792 MeasElem sub
1793}
1794
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001795private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001796 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001797 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001798 MeasElemFS meas_ul,
1799 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001800 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001801 uint5_t ms_power_level,
1802 uint8_t ms_actual_ta
1803}
1804
1805/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1806private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1807 return 63 + (toffs256s/256);
1808}
1809
Harald Welted5684392018-03-10 18:22:04 +01001810private function f_max(integer a, integer b) return integer {
1811 if (a > b) {
1812 return a;
1813 } else {
1814 return b;
1815 }
1816}
1817
1818private function f_min(integer a, integer b) return integer {
1819 if (a < b) {
1820 return a;
1821 } else {
1822 return b;
1823 }
1824}
1825
1826/* compute negative tolerance val-tolerance, ensure >= min */
1827private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1828 val := val - tolerance;
1829 return f_max(val, min);
1830}
1831
1832/* compute positive tolerance val+tolerance, ensure <= max */
1833private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1834 val := val + tolerance;
1835 return f_min(val, max);
1836}
1837
1838/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1839private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1840return template integer {
1841 var template integer ret;
1842 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1843 return ret;
1844}
1845
1846
Harald Welte70767382018-02-21 12:16:40 +01001847/* build a template for matching measurement results against */
1848private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1849 var ConnL1Pars l1p := g_pars.l1_pars;
1850 var template RSL_IE_UplinkMeas ul_meas := {
1851 len := 3,
1852 rfu := '0'B,
1853 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001854 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001855 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001856 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001857 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001858 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1859 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001860 supp_meas_info := omit
1861 };
Harald Welte685d5982018-02-27 20:42:05 +01001862 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001863 ul_meas.len := (3+8);
1864 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001865 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001866 toa256_min := ?,
1867 toa256_max := ?,
1868 toa256_std_dev := ?
1869 }
Harald Welte685d5982018-02-27 20:42:05 +01001870 }
Harald Welte70767382018-02-21 12:16:40 +01001871 var template RSL_IE_BS_Power bs_power := {
1872 reserved := 0,
1873 epc := false,
1874 fpc := false,
1875 power_level := l1p.bs_power_level
1876 };
1877 var template RSL_IE_L1Info l1_info := {
1878 ms_power_lvl := l1p.ms_power_level,
1879 fpc := false,
1880 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001881 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001882 };
1883 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001884 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001885 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1886 ?, t_toffs);
1887}
1888
Philipp Maierdd841d32019-12-17 14:44:54 +01001889/* build a template for matching measurement results that do not contain any
1890 * MS related measurement (l1_info, l3_info and ms timing offset). */
1891private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1892 var ConnL1Pars l1p := g_pars.l1_pars;
1893 var template RSL_IE_UplinkMeas ul_meas := {
1894 len := 3,
1895 rfu := '0'B,
1896 dtx_d := l1p.dtx_enabled,
1897 rxlev_f_u := ?,
1898 reserved1 := '00'B,
1899 rxlev_s_u := ?,
1900 reserved2 := '00'B,
1901 rxq_f_u := ?,
1902 rxq_s_u := ?,
1903 supp_meas_info := omit
1904 };
1905 if (l1p.toa256_enabled) {
1906 ul_meas.len := (3+8);
1907 ul_meas.supp_meas_info := {
1908 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1909 toa256_min := ?,
1910 toa256_max := ?,
1911 toa256_std_dev := ?
1912 }
1913 }
1914 var template RSL_IE_BS_Power bs_power := {
1915 reserved := 0,
1916 epc := false,
1917 fpc := false,
1918 power_level := l1p.bs_power_level
1919 };
1920
1921 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1922}
1923
Harald Welte70767382018-02-21 12:16:40 +01001924/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001925private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001926 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001927 var boolean chan_est := false;
1928
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001929 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001930
1931 /* Receive osmocom specific measurement reports. This is the normal
1932 * case. Here we verify that the measurement reports we sent are
1933 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001934 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1935 /* increment counter of next to-be-expected meas rep */
1936 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1937 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001938 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001939
1940 /* The following two cases may only happen in the beginning
1941 * of the channel establishment phase. Once we have received
1942 * the "our" measurement report the first time, the channel
1943 * is established and empty or hardcoded TRXCON reports must
1944 * not occur anymore. */
1945 chan_est := true;
1946
1947 repeat;
1948 }
1949
1950 /* When the BTS has established the channel, the MS might need slightly
1951 * more time to establish the channel and actually start sending. The
1952 * result is then a measurement report that just lacks the measurement
1953 * information of the MS. This is normal and we tolerate this behavior. */
1954 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1955 /* increment counter of next to-be-expected meas rep */
1956 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1957 /* Re-start the timer expecting the next MEAS RES */
1958 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001959 repeat;
1960 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001961
1962 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1963 * measurements if the TTCN3 side does not supply measurement input in
1964 * time. In those cases TRXCON will either use a cached measurement
1965 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1966 * report the templates above will not match. We tolerate this
1967 * behavior, but only once. */
1968 [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 +01001969 /* increment counter of next to-be-expected meas rep */
1970 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1971 if (g_first_meas_res) {
1972 g_first_meas_res := false;
1973 repeat;
1974 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001975 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001976 }
Harald Welte70767382018-02-21 12:16:40 +01001977 }
1978 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001980 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001981 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001983 }
1984}
1985
Harald Weltee613f962018-04-18 22:38:16 +02001986private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1987 select (rsl_alg_id) {
1988 case (RSL_ALG_ID_A5_0) { return 0; }
1989 case (RSL_ALG_ID_A5_1) { return 1; }
1990 case (RSL_ALG_ID_A5_2) { return 2; }
1991 case (RSL_ALG_ID_A5_3) { return 3; }
1992 case (RSL_ALG_ID_A5_4) { return 4; }
1993 case (RSL_ALG_ID_A5_5) { return 5; }
1994 case (RSL_ALG_ID_A5_6) { return 6; }
1995 case (RSL_ALG_ID_A5_7) { return 7; }
1996 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1998 /* Make compiler happy by calling mtc.stop here. It is already
1999 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002000 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002001 }
2002 }
2003}
2004
2005private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2006 select (rsl_alg_id) {
2007 case (RSL_ALG_ID_A5_1) { return '000'B; }
2008 case (RSL_ALG_ID_A5_2) { return '001'B; }
2009 case (RSL_ALG_ID_A5_3) { return '010'B; }
2010 case (RSL_ALG_ID_A5_4) { return '011'B; }
2011 case (RSL_ALG_ID_A5_5) { return '100'B; }
2012 case (RSL_ALG_ID_A5_6) { return '101'B; }
2013 case (RSL_ALG_ID_A5_7) { return '110'B; }
2014 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002015 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2016 /* Make compiler happy by calling mtc.stop here. It is already
2017 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002018 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002019 }
2020 }
2021}
2022
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002023/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2024private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2025 var GsmFrameNumber fn;
2026 timer T := 8.0;
2027
2028 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2029 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2030
2031 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2032 /* Send the actual RACH */
2033 fn := f_L1CTL_RACH(L1CTL, ra);
2034
2035 T.start;
2036 alt {
2037 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2038 [] T.timeout {
2039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2040 }
2041 }
2042 T.stop
2043 return fn;
2044}
Harald Weltee613f962018-04-18 22:38:16 +02002045
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002046/* Tune to a dedicated channel: L1CTL only */
2047private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002048 if (not pars.fhp.enabled) {
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002049 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2050 7 /* TODO: mp_tsc */,
2051 mp_trx0_arfcn));
2052 } else {
2053 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2054 7 /* TODO: mp_tsc */,
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002055 pars.fhp.maio_hsn.hsn,
2056 pars.fhp.maio_hsn.maio,
2057 pars.fhp.ma));
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002058 }
2059}
2060
Harald Welte70767382018-02-21 12:16:40 +01002061/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002062private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002063 var GsmFrameNumber fn;
2064 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002065 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002066 var integer ra := 23;
2067
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002068 /* Send RACH request and wait for ChanReq */
2069 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002070
2071 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002072 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002073
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002074 /* Craft channel description (with or without frequency hopping parameters) */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002075 if (g_pars.fhp.enabled) {
2076 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.fhp.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002077 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002078 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002079 }
2080
Harald Welte70767382018-02-21 12:16:40 +01002081 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002082 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 +01002083 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2084
2085 /* receive IMM.ASS on MS side */
2086 var ImmediateAssignment ia_um;
2087 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002088
2089 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2090 if (ch_desc.h != ia_um.chan_desc.h) {
2091 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2092 }
2093
Harald Welte70767382018-02-21 12:16:40 +01002094 /* enable dedicated mode */
Vadim Yanitskiyca813922020-09-12 19:08:31 +07002095 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.fhp.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002096 /* enable encryption, if requested */
2097 if (encr_enable) {
2098 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2099 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2100 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002101
2102 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002103}
2104
2105/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002106private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002107 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002108 RSL.clear;
2109
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002110 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002111 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002112 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002113 }
Harald Welte70767382018-02-21 12:16:40 +01002114
2115 f_est_dchan();
2116
2117 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2118 * RSL measurement reports on Abis side */
2119 timer T := 8.0;
2120 T.start;
2121 alt {
2122 [] as_l1_sacch();
2123 [] as_meas_res();
2124 [] as_l1_dcch();
2125 [] L1CTL.receive { repeat; }
2126 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002127 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002128 * of any earlier errors, so if we reach this timeout, we're good */
2129 setverdict(pass);
2130 }
2131 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002132 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002133 }
2134 }
2135 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002136 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002137}
Harald Welte0472ab42018-03-12 15:02:26 +01002138
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002139/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2140private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002141 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002142 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2143 timer Tup := 10.0;
2144 Tup.start;
2145 alt {
2146 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2147 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2148 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002149
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002150 if (rx_lvl != max_rx_lvl) {
2151 repeat;
2152 }
2153 Tup.stop;
2154 }
2155 [] L1CTL.receive { repeat; }
2156 [] Tup.timeout {
2157 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2158 log2str("Didn't reach full power ", max_rx_lvl));
2159 }
2160 }
2161 return max_rx_lvl;
2162}
2163
2164/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2165private function f_verify_ramp_up() runs on ConnHdlr {
2166 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002167 var integer initial_rx_lvl := -1;
2168 var integer last_rx_lvl := -1;
2169 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2170
2171 timer T := 2.0;
2172 alt {
2173 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2174 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2175 log("Received rx_level=", rx_lvl);
2176 if (initial_rx_lvl == -1) {
2177 initial_rx_lvl := rx_lvl;
2178 last_rx_lvl := rx_lvl;
2179
2180 /* Expect a somehow low value during first received messages */
2181 if (initial_rx_lvl >= max_rx_lvl / 2) {
2182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2183 log2str("Detected high initial tx power during ramp up: ",
2184 initial_rx_lvl , ", full power is", max_rx_lvl));
2185 }
2186 }
2187
2188 /* received Rx level bigger than maximum allowed power by CN */
2189 if (rx_lvl > max_rx_lvl) {
2190 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2191 log2str("Detected Tx power higher than full power: ",
2192 rx_lvl , " > ", max_rx_lvl));
2193 }
2194
2195 /* Make sure it never decreases, since we are rumping up */
2196 if (last_rx_lvl > rx_lvl) {
2197 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2198 log2str("Detected Tx power decrease during ramp up: ",
2199 last_rx_lvl , " -> ", rx_lvl));
2200 }
2201
2202 if (rx_lvl == max_rx_lvl and not T.running) {
2203 /* We reached the maximum power, start timer and receive
2204 /* a few more to make sure we don't surpass it */
2205 log("Reached full power, wating a bit more until success");
2206 T.start;
2207 }
2208
2209 last_rx_lvl := rx_lvl;
2210 repeat;
2211 }
2212 [] L1CTL.receive { repeat; }
2213 [] T.timeout { }
2214 }
2215
2216 /* We didn't increase tx power during ramp up */
2217 if (initial_rx_lvl < last_rx_lvl) {
2218 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2219 } else {
2220 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2221 log2str("No Tx power increase during whole ramp up: ",
2222 initial_rx_lvl , " -> ", last_rx_lvl));
2223 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002224}
2225
2226/* verify BTS ramps power down to rx_level 0 */
2227private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2228 var L1ctlDlMessage l1_dl;
2229 var integer last_rx_lvl := max_rx_lvl;
2230
2231 timer Tdown := 5.0;
2232 Tdown.start;
2233 alt {
2234 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2235 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2236 log("Received rx_level=", rx_lvl);
2237
2238 /* received Rx level bigger than maximum allowed power by CN */
2239 if (rx_lvl > max_rx_lvl) {
2240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2241 log2str("Detected Tx power higher than full power: ",
2242 rx_lvl , " > ", max_rx_lvl));
2243 }
2244
2245 /* Make sure it never increases, since we are rumping down */
2246 if (last_rx_lvl < rx_lvl) {
2247 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2248 log2str("Detected Tx power increase during ramp up: ",
2249 last_rx_lvl , " -> ", rx_lvl));
2250 }
2251
2252 last_rx_lvl := rx_lvl;
2253 if (last_rx_lvl != 0) {
2254 repeat;
2255 }
2256 /* we reached power level 0, we are done */
2257 Tdown.stop;
2258 }
2259 [] L1CTL.receive { repeat; }
2260 [] Tdown.timeout { }
2261 }
2262
2263 /* We didn't increase tx power during ramp down */
2264 if (max_rx_lvl > last_rx_lvl) {
2265 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2266 } else {
2267 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2268 log2str("No Tx power decrease during whole ramp down: ",
2269 max_rx_lvl , " -> ", last_rx_lvl));
2270 }
2271}
2272
2273/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002274private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002275 f_l1_tune(L1CTL);
2276 RSL.clear;
2277
2278 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002279
2280 setverdict(pass);
2281}
2282testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2283 var ConnHdlr vc_conn;
2284 var ConnHdlrPars pars;
2285 f_init();
2286 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2287 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2288 pcu_comp := false, trxc_comp := true);
2289 vc_conn.done;
2290 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2291}
2292
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002293/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002294private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002295 f_connhdlr_init_vty_bsc();
2296
2297 f_l1_tune(L1CTL);
2298 RSL.clear;
2299
2300 /* Wait until BTS is started and at full power */
2301 var integer max_rx_lvl := f_wait_ramp_up();
2302 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2303
2304 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2305 f_verify_ramp_down(max_rx_lvl);
2306
2307 setverdict(pass);
2308}
2309testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2310 var ConnHdlr vc_conn;
2311 var ConnHdlrPars pars;
2312 f_init();
2313 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2314 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2315 pcu_comp := false, trxc_comp := true);
2316 vc_conn.done;
2317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2318}
2319
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002320/* Verify Tx power:
2321 * + ramping down during ADM state UNLOCKED->LOCKED
2322 * + ramping up during ADM state LOCKED->UNLOCKED
2323 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002324private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002325 var L1ctlDlMessage l1_dl;
2326 var integer last_rx_lvl;
2327
2328 f_connhdlr_init_vty_bsc();
2329
2330 f_l1_tune(L1CTL);
2331 RSL.clear;
2332
2333 /* Wait until BTS is started and at full power */
2334 var integer max_rx_lvl := f_wait_ramp_up();
2335 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2336
2337 log("ADM STATE UNLOCKED->LOCKED");
2338 f_vty_enter_cfg_trx(BSCVTY);
2339 f_vty_transceive(BSCVTY, "rf_locked 1");
2340 last_rx_lvl := max_rx_lvl;
2341 f_verify_ramp_down(max_rx_lvl);
2342
2343 /* Let some time after we received 0dBm, then check we don't receive BCCH
2344 * anymore because scheduler has stopped after ramping down */
2345 f_sleep(2.0);
2346 L1CTL.clear;
2347 timer Tlocked := 2.0;
2348 Tlocked.start;
2349 alt {
2350 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2351 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2352 log2str("Received data_ind during rf_locked: ", l1_dl));
2353 }
2354 [] L1CTL.receive { repeat; }
2355 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2356 }
2357
2358 log("ADM STATE LOCKED->UNLOCKED");
2359 f_vty_transceive(BSCVTY, "rf_locked 0");
2360 f_verify_ramp_up();
2361 setverdict(pass);
2362}
2363testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2364 var ConnHdlr vc_conn;
2365 var ConnHdlrPars pars;
2366 f_init();
2367 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2368 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2369 pcu_comp := false, trxc_comp := true);
2370 vc_conn.done;
2371 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2372}
2373
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002374private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002375 timer T := 8.0;
2376 T.start;
2377 var RSL_Message rsl;
2378 alt {
2379 [] as_l1_sacch();
2380 [] L1CTL.receive { repeat; }
2381 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2382 if (rsl.ies[3].body.bs_power.power_level == level) {
2383 setverdict(pass)
2384 } else {
2385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2386 }
2387 }
2388 [] T.timeout {
2389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2390 }
2391 }
2392}
2393
2394/* see if the rsl meas res contains our expeced bs power level
2395bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002396private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002397 f_l1_tune(L1CTL);
2398 RSL.clear;
2399
2400 if (mp_bts_trxc_port != -1) {
2401 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2402 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2403 }
2404
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002405 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002406 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2407 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2408
2409 f_est_dchan(more_ies :={valueof(pwr)});
2410
2411 f_check_meas_bs_power_level(pwr_var);
2412
2413 f_rsl_chan_deact();
2414 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2415}
2416
2417/* see if the rsl meas res contains our expeced bs power level
2418bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002419private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002420 f_l1_tune(L1CTL);
2421 RSL.clear;
2422
2423 if (mp_bts_trxc_port != -1) {
2424 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2425 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2426 }
2427
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002428 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002429 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2430
2431 f_est_dchan();
2432
2433 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2434
2435 f_check_meas_bs_power_level(pwr_var);
2436
2437 f_rsl_chan_deact();
2438 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2439}
2440
2441testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2442 var ConnHdlr vc_conn;
2443 var ConnHdlrPars pars;
2444 f_init();
2445 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2446 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2447 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2448 pcu_comp := false, trxc_comp := true);
2449 vc_conn.done;
2450 }
2451 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2452}
2453
2454testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2455 var ConnHdlr vc_conn;
2456 var ConnHdlrPars pars;
2457 f_init();
2458 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2459 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2460 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2461 pcu_comp := false, trxc_comp := true);
2462 vc_conn.done;
2463 }
2464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2465}
2466
Eric Wild61edb7e2019-06-03 12:38:31 +02002467/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2468second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2469These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002470private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002471 var uint5_t pwr_var := 7;
2472 var L1ctlDlMessage l1_dl;
2473
2474 f_trxc_fake_rssi(rxlev2dbm(10));
2475 f_l1_tune(L1CTL);
2476 RSL.clear;
2477
2478 var RSL_IE_List addl_ies;
2479 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2480
2481 addl_ies := {
2482 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2483 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2484 };
2485
2486 /* establish with power parameters */
2487 f_est_dchan(more_ies := addl_ies);
2488
2489 /* set a high value to ensure L1 power control level increases */
2490 f_trxc_fake_rssi(rxlev2dbm(20));
2491
2492 timer T2 := 6.0;
2493 T2.start;
2494 alt {
2495 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002496 /* Update sent MS power to follow what BTS requests */
2497 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2498 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002499 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002500 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002501 T2.stop;
2502 }
2503 [] L1CTL.receive { repeat; }
2504 [] T2.timeout {
2505 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2506 "Power Level in L1 header has not increased sufficiently");
2507 }
2508 }
2509
2510 /* set a low value to ensure L1 power control level decreases */
2511 f_trxc_fake_rssi(rxlev2dbm(0));
2512
2513 timer T4 := 6.0;
2514 T4.start;
2515 alt {
2516 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002517 /* Update sent MS power to follow what BTS requests */
2518 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2519 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002520 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002521 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002522 T4.stop;
2523 setverdict(pass, "Power level in L1 decreased/increased as expected");
2524 }
2525 [] L1CTL.receive { repeat; }
2526 [] T4.timeout {
2527 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2528 "Power Level in L1 header has not decreased sufficiently");
2529 }
2530 }
2531
2532 f_rsl_chan_deact();
2533 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2534
2535}
2536
2537/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002538private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002539 var uint5_t pwr_var := 7;
2540 var L1ctlDlMessage l1_dl;
2541
2542 /* set a low value to ensure power increases */
2543 f_trxc_fake_rssi(rxlev2dbm(10));
2544 f_l1_tune(L1CTL);
2545 RSL.clear;
2546
2547 var RSL_IE_List addl_ies;
2548 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2549
2550 addl_ies := {
2551 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2552 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2553 };
2554
2555 /* establish with power parameters */
2556 f_est_dchan(more_ies := addl_ies);
2557
2558 timer T1 := 10.0;
2559 T1.start;
2560 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002561 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2562 /* Update sent MS power to follow what BTS requests */
2563 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2564 repeat;
2565 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002566 [] L1CTL.receive { repeat; }
2567 [] T1.timeout {
2568 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2569 setverdict(fail, "Power level in L1 header should not have changed");
2570 }
2571 }
2572 }
2573
2574 f_rsl_chan_deact();
2575 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2576
2577}
2578
2579/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002580private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002581 var L1ctlDlMessage l1_dl;
2582 var uint5_t pwr_var := 15;
2583 var uint5_t pwr_max_var := f_get_max_power_from_band();
2584
2585 /* set a low value to ensure power increases */
2586 f_trxc_fake_rssi(rxlev2dbm(10));
2587 f_l1_tune(L1CTL);
2588 RSL.clear;
2589
2590 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2591 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2592
2593 /* establish with fixed power level */
2594 f_est_dchan(more_ies :={valueof(pwr)});
2595
2596 /* check our initial power level */
2597 f_wait_for_l1_power_level(pwr_var);
2598
2599 /* update power param to enable power loop
2600 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2601 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2602
2603 /* wait, then check that our power level was reduced */
2604 timer T1 := 10.0;
2605 T1.start;
2606 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002607 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2608 /* Update sent MS power to follow what BTS requests */
2609 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2610 repeat;
2611 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002612 [] L1CTL.receive { repeat; }
2613 [] T1.timeout {
2614 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2615 if( f_power_level_is_highest_dbm(rcv) ){
2616 setverdict(pass, "Power level in L1 header reduced as expected");
2617 } else {
2618 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2619 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2620 }
2621 }
2622 }
2623
2624 f_rsl_chan_deact();
2625 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2626
2627}
2628
2629/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002630private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002631 var L1ctlDlMessage l1_dl;
2632
2633 /* set a high value to ensure power decreases */
2634 f_trxc_fake_rssi(rxlev2dbm(50));
2635 f_l1_tune(L1CTL);
2636 RSL.clear;
2637
2638 var uint5_t pwr_var := 5;
2639 var uint5_t pwr_target_val := 15;
2640
2641 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2642 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2643
2644 /* establish with fixed power level */
2645 f_est_dchan(more_ies :={valueof(pwr)});
2646
2647 /* check our initial power level */
2648 f_wait_for_l1_power_level(pwr_var);
2649
2650 /* update power param to enable power loop
2651 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002652 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002653
2654 /* wait, then check that our power level was increased */
2655 timer T1 := 10.0;
2656 T1.start;
2657 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002658 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2659 /* Update sent MS power to follow what BTS requests */
2660 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2661 repeat;
2662 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002663 [] L1CTL.receive { repeat; }
2664 [] T1.timeout {
2665 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2666 setverdict(pass, "Power level in L1 header increased to lowest power value");
2667 } else {
2668 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2669 "Power level in L1 header NOT increased to lowest power value");
2670 }
2671 }
2672 }
2673
2674 f_rsl_chan_deact();
2675 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2676
2677}
2678
Eric Wild095024b2019-06-17 15:08:57 +02002679/* see if we change the power level without receiving power parameters, which should not happen
2680rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002681private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002682 var L1ctlDlMessage l1_dl;
2683
2684 /* set a high value to ensure power decreases */
2685 f_trxc_fake_rssi(rxlev2dbm(50));
2686 f_l1_tune(L1CTL);
2687 RSL.clear;
2688
2689 var uint5_t pwr_var := 5;
2690
2691 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2692 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2693
2694 /* establish with fixed power level */
2695 f_est_dchan(more_ies :={valueof(pwr)});
2696
2697 /* check our initial power level */
2698 f_wait_for_l1_power_level(pwr_var);
2699
2700 /* wait, then check that our power level did not change */
2701 timer T1 := 10.0;
2702 T1.start;
2703 alt {
2704 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2705 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2706 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2707 "BS power control should not be active unless we receive a power parameters IE!");
2708 }
2709 repeat;
2710 }
2711 [] L1CTL.receive { repeat; }
2712 [] T1.timeout { setverdict(pass); }
2713 }
2714
2715 f_rsl_chan_deact();
2716 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2717
2718}
2719
Eric Wild095024b2019-06-17 15:08:57 +02002720/* see if we change the power level without receiving power parameters, which should not happen
2721ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002722private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002723 var L1ctlDlMessage l1_dl;
2724
2725 /* set a high value to ensure power decreases */
2726 f_trxc_fake_rssi(rxlev2dbm(50));
2727 f_l1_tune(L1CTL);
2728 RSL.clear;
2729
2730 var uint5_t pwr_var := 5;
2731
2732 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2733 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2734
2735 /* establish with fixed power level */
2736 f_est_dchan(more_ies :={valueof(pwr)});
2737
2738 /* check our initial power level */
2739 f_wait_for_l1_power_level(pwr_var);
2740
2741 /* pwr control without power params IE, should NOT activate MS power control*/
2742 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2743
2744 /* wait, then check that our power level did not change */
2745 timer T1 := 10.0;
2746 T1.start;
2747 alt {
2748 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2749 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2750 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2751 "BS power control should not be active unless we receive a power parameters IE!");
2752 }
2753 repeat;
2754 }
2755 [] L1CTL.receive { repeat; }
2756 [] T1.timeout { setverdict(pass); }
2757 }
2758
2759 f_rsl_chan_deact();
2760 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2761
2762}
2763
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002764private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002765 var L1ctlDlMessage l1_dl;
2766 timer T0 := 10.0;
2767 T0.start;
2768 alt {
2769 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2770 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2771 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2772 "Power level in L1 header != signaled (RSL) power level.");
2773 }
2774 }
2775 [] L1CTL.receive { repeat; }
2776 [] T0.timeout {
2777 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2778 "Timeout waiting for initial power level");
2779 }
2780 }
2781 T0.stop;
2782}
2783
2784private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2785 var IntegerRecord min_dbm_level;
2786 var IntegerRecord max_dbm_level;
2787 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2788
2789 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2790 if (min_dbm_level[i] == level) {
2791 return true;
2792 }
2793 }
2794 return false;
2795}
2796
2797private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2798 var IntegerRecord min_dbm_level;
2799 var IntegerRecord max_dbm_level;
2800 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2801
2802 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2803 if (max_dbm_level[i] == level) {
2804 return true;
2805 }
2806 }
2807 return false;
2808}
2809
2810private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2811 var IntegerRecord min_dbm_level;
2812 var IntegerRecord max_dbm_level;
2813 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2814 return max_dbm_level[0];
2815}
2816
2817type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002818private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002819private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2820 // 45.005 4.1.1
2821 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2822 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2823 2, 1, 0};
2824 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2825 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2826 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2827 var IntegerRecord rv;
2828
2829 select(band){
2830 case (BtsBand_allGSM){
2831 rv := gsm_power;
2832 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2833 max_dbm_level := {2, 1, 0};
2834 }
2835 case("DCS1800"){
2836 rv := dcs_power;
2837 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2838 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2839 }
2840 case("PCS1900"){
2841 rv := pcs_power;
2842 min_dbm_level := {15};
2843 max_dbm_level := {30};
2844 }
Harald Welte194b6912020-10-11 21:01:55 +02002845 case else {
2846 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unsupported band: " & band);
2847 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002848 }
2849
2850 return rv;
2851}
2852
2853private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
Harald Weltec935fad2020-10-11 21:02:54 +02002854 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 +02002855}
2856
2857testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2858 var ConnHdlr vc_conn;
2859 var ConnHdlrPars pars;
2860 f_init();
2861 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2862 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2863 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2864 pars.bts0_band := f_vty_get_bts0_band();
2865 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2866 vc_conn.done;
2867 }
2868 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2869 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2870}
2871
2872testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2873 var ConnHdlr vc_conn;
2874 var ConnHdlrPars pars;
2875 f_init();
2876 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2877 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2878 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2879 pars.bts0_band := f_vty_get_bts0_band();
2880 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2881 vc_conn.done;
2882 }
2883 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2884 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2885}
2886
2887testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2888 var ConnHdlr vc_conn;
2889 var ConnHdlrPars pars;
2890 f_init();
2891 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2892 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2893 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2894 pars.bts0_band := f_vty_get_bts0_band();
2895 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2896 vc_conn.done;
2897 }
2898 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2899 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2900}
2901
2902testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2903 var ConnHdlr vc_conn;
2904 var ConnHdlrPars pars;
2905 f_init();
2906 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2907 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2908 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2909 pars.bts0_band := f_vty_get_bts0_band();
2910 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2911 vc_conn.done;
2912 }
2913 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2914 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2915}
2916
Eric Wild280ccb82019-06-17 11:11:52 +02002917testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2918 var ConnHdlr vc_conn;
2919 var ConnHdlrPars pars;
2920 f_init();
2921 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2922 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2923 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2924 pars.bts0_band := f_vty_get_bts0_band();
2925 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2926 vc_conn.done;
2927 }
2928 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2929 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2930}
2931
Eric Wild095024b2019-06-17 15:08:57 +02002932testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2933 var ConnHdlr vc_conn;
2934 var ConnHdlrPars pars;
2935 f_init();
2936 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2937 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2938 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2939 pars.bts0_band := f_vty_get_bts0_band();
2940 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2941 vc_conn.done;
2942 }
2943 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2944 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2945}
2946
Harald Welte70767382018-02-21 12:16:40 +01002947testcase TC_meas_res_sign_tchf() runs on test_CT {
2948 var ConnHdlr vc_conn;
2949 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002950 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002951 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2952 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002953 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2954 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002955 vc_conn.done;
2956 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002957 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002958}
2959testcase TC_meas_res_sign_tchh() runs on test_CT {
2960 var ConnHdlr vc_conn;
2961 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002962 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002963 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2964 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002965 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2966 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002967 vc_conn.done;
2968 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002969 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002970}
2971testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2972 var ConnHdlr vc_conn;
2973 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002974 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002975 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2976 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002977 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2978 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002979 vc_conn.done;
2980 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002982}
2983testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2984 var ConnHdlr vc_conn;
2985 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002986 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002987 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2988 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002989 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2990 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002991 vc_conn.done;
2992 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002993 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002994}
Harald Welte685d5982018-02-27 20:42:05 +01002995testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2996 var ConnHdlr vc_conn;
2997 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002998 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002999 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
3000 for (var integer ss := 0; ss <= 1; ss := ss+1) {
3001 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
3002 pars.l1_pars.toa256_enabled := true;
3003 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
3004 vc_conn.done;
3005 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003006 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003007}
3008
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003009/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3010 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003011private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003012 var L1ctlDlMessage l1_dl;
3013 var RSL_IE_MS_Power ms_power;
3014 var RSL_Message rsl;
3015 var uint5_t power_level := 0;
3016
3017 f_l1_tune(L1CTL);
3018 RSL.clear;
3019
3020 f_est_dchan();
3021
3022 ms_power.reserved := 0;
3023 ms_power.fpc_epc := false;
3024
3025 /* Send the first power control command. This will disable any BTS/TRX
3026 * internal power control and switch the MS (which is not in scope of
3027 * this test) to a constant power level. We start with a power level
3028 * of 0 */
3029 ms_power.power_level := power_level;
3030 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3031 RSL.send(rsl);
3032
3033 alt {
3034
3035 /* Pick all SACCH blocks for checking */
3036 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3037
3038 /* The first byte of the L1 header contains the power level.
3039 * The reserved bits and the fpc bit is set to 0, so we may
3040 * compare directly. */
3041 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3042 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3043 }
3044
3045 /* Signal a new power level via RSL for the next turn. */
3046 if (power_level < 31) {
3047 power_level := power_level + 1;
3048 ms_power.power_level := power_level;
3049 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3050 RSL.send(rsl);
3051 repeat;
3052 }
3053
3054 }
3055
3056 /* Ignore all other blocks */
3057 [] L1CTL.receive { repeat; }
3058
3059 }
3060
3061 f_rsl_chan_deact();
3062 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3063
3064 setverdict(pass);
3065}
3066
3067testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3068 var ConnHdlr vc_conn;
3069 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003070 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003071
3072 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3073 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3074 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3075 vc_conn.done;
3076 }
3077 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3078}
Harald Welte70767382018-02-21 12:16:40 +01003079
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003080/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003081TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003082private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003083 var L1ctlDlMessage l1_dl;
3084 var uint5_t ta_to_test := 16;
3085
3086
3087 f_l1_tune(L1CTL);
3088 RSL.clear;
3089
3090 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003091 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003092
3093 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3094
3095
3096 alt {
3097
3098 /* Pick all SACCH blocks for checking */
3099 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3100
3101 /* The second byte of the L1 header contains the TA. */
3102 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3103 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3104 }
3105
3106 }
3107
3108 /* Ignore all other blocks */
3109 [] L1CTL.receive { repeat; }
3110
3111 }
3112
3113 f_rsl_chan_deact();
3114 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3115
3116 setverdict(pass);
3117}
3118
3119testcase TC_rsl_chan_initial_ta() runs on test_CT {
3120 var ConnHdlr vc_conn;
3121 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003122 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003123 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003124 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3125 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003126 vc_conn.done;
3127 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3128}
3129
Eric Wilde57e1a62019-05-28 13:30:55 +02003130/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003131private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003132 var L1ctlDlMessage l1_dl;
3133 var uint5_t ms_power_level := 7;
3134
3135 var RSL_IE_MS_Power ms_power;
3136 ms_power.reserved := 0;
3137 ms_power.fpc_epc := false;
3138 ms_power.power_level := ms_power_level;
3139
3140 f_l1_tune(L1CTL);
3141 RSL.clear;
3142
3143 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3144
3145 timer T := 1.0;
3146 T.start;
3147 alt {
3148 /* Pick all SACCH blocks for checking */
3149 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3150 /* The first byte of the L1 header contains the power level.. */
3151 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3152 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3153 }
3154 }
3155 /* Ignore all other blocks */
3156 [] L1CTL.receive { repeat; }
3157 [] T.timeout {
3158 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3159 }
3160 }
3161
3162 f_rsl_chan_deact();
3163 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3164 setverdict(pass);
3165}
3166
3167testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3168 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3169 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3170}
3171
Harald Welte0472ab42018-03-12 15:02:26 +01003172/* 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 +01003173private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003174 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003175 RSL.clear;
3176
3177 f_est_dchan();
3178 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003179 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003180
3181 timer T := 40.0;
3182 T.start;
3183 alt {
3184 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3185 setverdict(pass)
3186 }
3187 [] RSL.receive { repeat };
3188 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003190 }
3191 }
3192 f_rsl_chan_deact();
3193}
3194testcase TC_conn_fail_crit() runs on test_CT {
3195 var ConnHdlr vc_conn;
3196 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003197 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003198 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3199 pars.t_guard := 60.0;
3200 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3201 vc_conn.done;
3202}
3203
Harald Welte93640c62018-02-25 16:59:33 +01003204/***********************************************************************
3205 * Paging
3206 ***********************************************************************/
3207
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003208private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003209 if (tmsi == 'FFFFFFFF'O) {
3210 return true;
3211 } else {
3212 return false;
3213 }
3214}
Harald Welte70767382018-02-21 12:16:40 +01003215
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003216private type record allowedFn { integer frame_nr }
3217private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3218private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3219private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3220private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3221private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3222private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3223private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3224private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3225private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003226{
3227 var integer frame_nr_51;
3228 frame_nr_51 := frame_nr mod 51
3229
3230 var allowedFn fn_check;
3231 fn_check.frame_nr := frame_nr_51;
3232
3233 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003234 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003235 return;
3236 }
3237
3238 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3239 return;
3240 }
3241 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3242 return;
3243 }
3244 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3245 return;
3246 }
3247 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3248 return;
3249 }
3250 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3251 return;
3252 }
3253 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3254 return;
3255 }
3256 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3257 return;
3258 }
3259 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3260 return;
3261 }
3262
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003263 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003264 return;
3265}
3266
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003267private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3268 inout integer num_paging_rcv_ids,
3269 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003270runs on test_CT {
3271 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003272 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003273 repeat;
3274 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003275 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003276 var octetstring without_plen :=
3277 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3278 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003279
3280 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3281
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003282 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3283 /* Ignore empty RR Paging Request (PCH filling) messages.
3284 * TODO: does it make sense to count them? */
3285 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003286 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3287 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003288 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003289 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3290 }
3291 } else if (match(rr, tr_PAGING_REQ2)) {
3292 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3293 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3294 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3295 }
3296 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3297 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3298 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003299 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003300 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3301 }
3302 } else if (match(rr, tr_PAGING_REQ3)) {
3303 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3304 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3305 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3306 }
3307 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3308 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3309 }
3310 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3311 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3312 }
3313 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3314 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3315 }
3316 }
3317 repeat;
3318 }
3319}
3320
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003321private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003322 boolean combined_ccch,
3323 integer bs_ag_blks_res,
3324 float load_factor,
3325 boolean exp_load_ind,
3326 boolean exp_overload,
3327 boolean use_tmsi
3328}
3329
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003330private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003331 integer num_paging_sent,
3332 integer num_paging_rcv_msgs,
3333 integer num_paging_rcv_ids,
3334 integer num_overload
3335}
3336
Harald Welte68e495b2018-02-25 00:05:57 +01003337/* Helper function for paging related testing */
3338private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003339 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003340 f_init_l1ctl();
3341 f_l1_tune(L1CTL);
3342
3343 var PagingTestState st := {
3344 num_paging_sent := 0,
3345 num_paging_rcv_msgs := 0,
3346 num_paging_rcv_ids := 0,
3347 num_overload := 0
3348 };
3349
3350 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3351 var float max_pch_imsi_per_sec;
3352 if (cfg.use_tmsi) {
3353 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3354 } else {
3355 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3356 }
3357 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3358 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003359 var float time_total := 20.0;
3360 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3361 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003362
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003363 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3364 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003365
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003366 timer T_itv := 0.0;
3367 T_itv.start;
3368 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003369 alt {
3370 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003371 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003372 st.num_overload := st.num_overload + 1;
3373 repeat;
3374 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003375 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003377 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003378 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003379 log("Rx LOAD_IND");
3380 /* FIXME: analyze/verify interval + contents */
3381 repeat;
3382 }
3383 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003384 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003385 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003386 [] T_itv.timeout {
3387 /* Send paging cmds based on elapsed time */
3388 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3389 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003390 var MobileIdentityV mi;
3391
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003392 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003393 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003394 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003395 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003396 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003397 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003398
3399 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003400 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 +02003401
3402 st.num_paging_sent := st.num_paging_sent + 1;
3403 }
3404 if (st.num_paging_sent < pkt_total) {
3405 /* Wait for interval to next PAGING COMMAND */
3406 var float time_now := T_total.read;
3407 var float next_sched := int2float(st.num_paging_sent)*interval;
3408 if (next_sched > time_now) {
3409 T_itv.start(next_sched - time_now);
3410 } else {
3411 T_itv.start(0.0);
3412 }
3413 } else {
3414 /* We are done, no need to keep counting */
3415 T_total.stop;
3416 }
3417 }
3418 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003419 }
3420 }
3421
3422 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3423 timer T_wait := 18.0;
3424 T_wait.start;
3425 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003426 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003427 [] L1CTL.receive { repeat; }
3428 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003429 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3430 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003431 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003433 }
Harald Welte68e495b2018-02-25 00:05:57 +01003434 }
3435
3436 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3437 " rcvd_ids=", st.num_paging_rcv_ids);
3438 return st;
3439}
3440
3441/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3442 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3443 * - that CCCH LOAD IND (PCH) are being generated
3444 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3445testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003446 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003447 var PagingTestCfg cfg := {
3448 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003449 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003450 load_factor := 0.8,
3451 exp_load_ind := true,
3452 exp_overload := false,
3453 use_tmsi := false
3454 };
3455 var PagingTestState st := f_TC_paging(cfg);
3456 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003457 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3458 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003459 } else {
3460 setverdict(pass);
3461 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003462 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003463}
3464
3465/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3466 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3467 * - that CCCH LOAD IND (PCH) are being generated
3468 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3469testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003470 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003471 var PagingTestCfg cfg := {
3472 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003473 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003474 load_factor := 0.8,
3475 exp_load_ind := true,
3476 exp_overload := false,
3477 use_tmsi := true
3478 };
3479 var PagingTestState st := f_TC_paging(cfg);
3480 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3482 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003483 } else {
3484 setverdict(pass);
3485 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003486 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003487}
3488
3489/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3490 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3491 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3492 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3493testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003494 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003495 var PagingTestCfg cfg := {
3496 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003497 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003498 load_factor := 2.0,
3499 exp_load_ind := true,
3500 exp_overload := true,
3501 use_tmsi := false
3502 };
3503 var PagingTestState st := f_TC_paging(cfg);
3504 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3505 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003506 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003507 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003508 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 +01003509 } else {
3510 setverdict(pass);
3511 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003512 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003513}
3514
3515/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3516 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3517 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3518 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3519testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003520 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003521 var PagingTestCfg cfg := {
3522 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003523 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003524 load_factor := 2.0,
3525 exp_load_ind := true,
3526 exp_overload := true,
3527 use_tmsi := true
3528 };
3529 var PagingTestState st := f_TC_paging(cfg);
3530 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3531 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003532 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003533 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003534 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 +01003535 } else {
3536 setverdict(pass);
3537 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003538 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003539}
3540
3541
Harald Welte93640c62018-02-25 16:59:33 +01003542/***********************************************************************
3543 * Immediate Assignment / AGCH
3544 ***********************************************************************/
Vadim Yanitskiy3b464a92020-08-25 03:55:32 +07003545private const MobileAllocationLV c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003546 len := 0,
3547 ma := ''B
3548}
Harald Welte93640c62018-02-25 16:59:33 +01003549
Harald Weltee8d750e2018-06-10 21:41:35 +02003550private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3551 return int2str(num_tx) & " sent, "
3552 & int2str(num_rx) & " received, "
3553 & int2str(num_del) & " deleted";
3554}
3555
3556private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3557 var L1ctlDlMessage l1_dl;
3558 timer T := 10.0;
3559 var integer num_tx := 0;
3560 var integer num_rx := 0;
3561 var integer num_del := 0;
3562 var charstring res_str;
3563 var float rx_ratio;
3564
Harald Welte10474062019-05-30 16:48:17 +02003565 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003566 f_init_l1ctl();
3567 f_l1_tune(L1CTL);
3568
3569 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiydd82be32020-10-18 16:09:58 +07003570 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(ts_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003571 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3572 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003573 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003574 num_tx := num_tx+1;
3575 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003576 }
3577 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003578 T.start;
3579 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003580 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003581 num_del := num_del+1;
3582 repeat;
3583 }
3584 [] RSL_CCHAN.receive {
3585 repeat;
3586 }
3587 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003588 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3589 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3590 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003591 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003592 } else {
3593 num_rx := num_rx+1;
3594 }
3595 repeat;
3596 }
3597 [] L1CTL.receive { repeat; }
3598 [] T.timeout { }
3599 }
3600 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3601 log("AGCH test: " & res_str);
3602 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003604 }
3605 rx_ratio := int2float(num_rx) / int2float(num_tx);
3606 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003607 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 +02003608 } else {
3609 setverdict(pass);
3610 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003611 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003612}
3613
Harald Weltee8d750e2018-06-10 21:41:35 +02003614/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3615testcase TC_imm_ass_1000_20ms() runs on test_CT {
3616 f_TC_imm_ass(1000, 0.02, 0.25);
3617}
3618
3619/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3620testcase TC_imm_ass_200_0ms() runs on test_CT {
3621 f_TC_imm_ass(200, 0.0, 0.05);
3622}
3623
3624/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3625testcase TC_imm_ass_200_76ms() runs on test_CT {
3626 f_TC_imm_ass(150, 0.076, 1.00);
3627}
3628
3629
3630
Harald Welte48494ca2018-02-25 16:59:50 +01003631/***********************************************************************
3632 * BCCH
3633 ***********************************************************************/
3634
3635/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003636private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003637 GsmFrameNumber frame_number,
3638 SystemInformation si
3639}
3640
3641/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003642private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003643
3644/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003645private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003646
3647/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003648private function f_si_vecslot_contains(SystemInformationVector arr,
3649 RrMessageType key,
3650 boolean bcch_ext := false)
3651return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003652 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3653 var integer fn_mod51 := arr[i].frame_number mod 51;
3654 if (not bcch_ext and fn_mod51 == 2 or
3655 bcch_ext and fn_mod51 == 6) {
3656 if (arr[i].si.header.message_type == key) {
3657 return true;
3658 }
3659 }
3660 }
3661 return false;
3662}
3663
3664/* 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 +07003665private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3666 integer tc, RrMessageType key,
3667 boolean ext_bcch := false)
3668{
Harald Welte48494ca2018-02-25 16:59:50 +01003669 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003670 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003671 }
3672}
3673
3674/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003675private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3676 RrMessageType key)
3677return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003678 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3679 if (f_si_vecslot_contains(arr[tc], key) or
3680 f_si_vecslot_contains(arr[tc], key, true)) {
3681 return true;
3682 }
3683 }
3684 return false;
3685}
3686
3687/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003688private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3689 RrMessageType key,
3690 boolean bcch_ext := false,
3691 integer n := 1, integer m := 4)
3692return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003693 var integer count := 0;
3694 if (sizeof(arr) < m) {
Harald Weltea616ec92020-10-11 21:28:00 +02003695 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array: "
3696 & int2str(sizeof(arr)) & " < " & int2str(m));
Harald Welte48494ca2018-02-25 16:59:50 +01003697 }
3698 for (var integer i:= 0; i < m; i := i + 1) {
3699 var integer fn_mod51 := arr[i].frame_number mod 51;
3700 if (not bcch_ext and fn_mod51 == 2 or
3701 bcch_ext and fn_mod51 == 6) {
3702 if (arr[i].si.header.message_type == key) {
3703 count := count + 1;
3704 }
3705 }
3706 }
3707 if (count >= n) {
3708 return true;
3709 } else {
3710 return false;
3711 }
3712}
3713
3714/* 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 +07003715private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3716 integer tc, RrMessageType key,
3717 boolean ext_bcch := false,
3718 integer n, integer m)
3719{
Harald Welte48494ca2018-02-25 16:59:50 +01003720 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003721 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003722 }
3723}
3724
3725/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003726private function f_si_vecslot_contains_only(SystemInformationVector arr,
3727 RrMessageType key,
3728 boolean bcch_ext := false)
3729return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003730 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3731 var integer fn_mod51 := arr[i].frame_number mod 51;
3732 if (not bcch_ext and fn_mod51 == 2 or
3733 bcch_ext and fn_mod51 == 6) {
3734 if (arr[i].si.header.message_type != key) {
3735 return false;
3736 }
3737 }
3738 }
3739 return true;
3740}
3741
3742/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003743private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3744 integer tc, RrMessageType key,
3745 boolean ext_bcch := false)
3746{
Harald Welte48494ca2018-02-25 16:59:50 +01003747 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003749 }
3750}
3751
3752/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003753private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003754 boolean bcch_extended,
3755 boolean si1_present,
3756 boolean si2bis_present,
3757 boolean si2ter_present,
3758 boolean si2quater_present,
3759 boolean si7_present,
3760 boolean si8_present,
3761 boolean si9_present,
3762 boolean si13_present,
3763 boolean si13alt_present,
3764 boolean si15_present,
3765 boolean si16_present,
3766 boolean si17_present,
3767 boolean si2n_present,
3768 boolean si21_present,
3769 boolean si22_present
3770}
3771
3772/* 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 +07003773private function f_validate_si_scheduling(SystemInformationConfig cfg,
3774 SystemInformationVectorPerTc si_per_tc)
3775{
Harald Welte48494ca2018-02-25 16:59:50 +01003776 var integer i;
3777 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3778 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003779 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003780 }
3781 }
3782 if (cfg.si1_present) {
3783 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3784 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3785 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3786 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3787 /* make sure *ALL* contain SI1 */
3788 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3789 }
3790 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3791 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3792 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3793 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3794 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3795 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3796
3797 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3798 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3799 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3800 * consecutive occurrences of TC = 4. */
3801 if (cfg.si2bis_present and not cfg.si2ter_present) {
3802 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3803 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3804 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3805 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3806 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3807 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3808 }
3809
3810 if (cfg.si7_present or cfg.si8_present) {
3811 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3812 * if System Information type 4 does not contain all information needed for cell
3813 * selection and reselection. */
3814 if (not cfg.bcch_extended) {
3815 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3816 }
3817 if (cfg.si7_present) {
3818 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3819 }
3820 if (cfg.si8_present) {
3821 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3822 }
3823 }
3824
3825 if (cfg.si2quater_present) {
3826 /* iii) System information type 2 quater is sent if needed, as determined by the system
3827 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3828 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3829 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3830 * within any of 4 consecutive occurrences of TC = 5. */
3831 if (not (cfg.bcch_extended)) {
3832 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3833 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3834 } else {
3835 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3836 }
3837 } else {
3838 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3839 }
3840 }
3841 if (cfg.si9_present) {
3842 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3843 * in system information type 3 as defined in 3GPP TS 44.018. */
3844 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3845 }
3846 if (cfg.si13_present) {
3847 /* vii) System Information type 13 is only related to the GPRS service. System Information
3848 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3849 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3850 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3851 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3852 * within any of 4 consecutive occurrences of TC=4. */
3853 if (not cfg.bcch_extended) {
3854 log("not-bccch-extended");
3855 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3856 } else {
3857 log("bccch-extended");
3858 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3859 }
3860 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003861 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003862 }
3863 }
3864 if (cfg.si16_present or cfg.si17_present) {
3865 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3866 * should not be sent in a cell where network sharing is used (see rule xv). */
3867 if (cfg.si22_present) {
3868 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3869 }
3870 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003871 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003872 }
3873 if (not cfg.bcch_extended) {
3874 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3875 }
3876 if (cfg.si16_present) {
3877 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3878 }
3879 if (cfg.si17_present) {
3880 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3881 }
3882 }
3883
3884 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3885 * broadcast information. The frequency with which they are sent is determined by the
3886 * system operator. System Information type 9 identifies the scheduling of System
3887 * Information type 18 and 20 messages. */
3888
3889 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3890 * Information Type 19 is present, then its scheduling shall be indicated in System
3891 * Information Type 9. */
3892
3893 if (cfg.si15_present) {
3894 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3895 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3896 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3897 * 4 consecutive occurrences of TC = 1. */
3898 if (not cfg.bcch_extended) {
3899 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3900 } else {
3901 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3902 }
3903 }
3904 if (cfg.si13alt_present) {
3905 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3906 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3907 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3908 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3909 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3910 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3911 * of TC = 4. */
3912 if (cfg.si13_present) {
3913 testcase.stop("Error: Cannot have SI13alt and SI13");
3914 }
3915 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003916 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003917 }
3918 if (not cfg.bcch_extended) {
3919 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3920 } else {
3921 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3922 }
3923 }
3924 if (cfg.si2n_present) {
3925 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3926 * as determined by the system operator. In the case that the message is sent on the
3927 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3928 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3929 * consecutive occurrences of TC = 4. */
3930 if (not cfg.bcch_extended) {
3931 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3932 } else {
3933 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3934 }
3935 }
3936 if (cfg.si21_present) {
3937 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3938 * determined by the system operator. If Extended Access Barring is in use in the cell
3939 * then this message is sent at least once within any of 4 consecutive occurrences of
3940 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3941 * cell then this message shall only be sent on BCCH Ext. */
3942 if (not cfg.bcch_extended) {
3943 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3944 } else {
3945 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3946 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003947 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003948 }
3949 }
3950 }
3951 if (cfg.si22_present) {
3952 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3953 * should not be sent in a cell where SoLSA is used (see rule viii). System
3954 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3955 * =2 and TC=6. */
3956 if (cfg.si16_present or cfg.si17_present) {
3957 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3958 }
3959 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3960 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003962 }
3963 if (not cfg.bcch_extended) {
3964 testcase.stop("Error: SI22 requires BCCH Extd!");
3965 } else {
3966 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3967 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3968 }
3969 }
3970}
3971
3972/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003973private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3974return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003975 timer T := duration;
3976 var SystemInformationVectorPerTc si_per_tc;
3977 var L1ctlDlMessage l1_dl;
3978
3979 /* initialize all per-TC vectors empty */
3980 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3981 si_per_tc[i] := {};
3982 }
3983
3984 /* flush all previous L1 queued msgs */
3985 pt.clear;
3986
3987 T.start;
3988 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003989 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003990 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3991 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3992 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003993 repeat;
3994 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003995
Harald Welte48494ca2018-02-25 16:59:50 +01003996 var integer tc := f_gsm_compute_tc(sig.frame_number);
3997 log("SI received at TC=", tc, ": ", sig.si);
3998 /* append to the per-TC bucket */
3999 si_per_tc[tc] := si_per_tc[tc] & { sig };
4000 repeat;
4001 }
4002 [] pt.receive { repeat; }
4003 [] T.timeout { }
4004 }
4005
4006 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4007 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4008 }
4009 log("si_per_tc=", si_per_tc);
4010 return si_per_tc;
4011}
4012
4013/* helper function: Set given SI via RSL + validate scheduling.
4014 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Harald Welte9b965d52020-10-11 21:28:22 +02004015private function f_TC_si_sched(float duration := 8.0) runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004016 var SystemInformationVectorPerTc si_per_tc;
4017 f_init_l1ctl();
4018 f_l1_tune(L1CTL);
4019
4020 /* Sample + Validate Scheduling */
Harald Welte9b965d52020-10-11 21:28:22 +02004021 si_per_tc := f_l1_sample_si(L1CTL, duration);
Harald Welte48494ca2018-02-25 16:59:50 +01004022 f_validate_si_scheduling(si_cfg, si_per_tc);
4023
4024 setverdict(pass);
4025}
4026
4027testcase TC_si_sched_default() runs on test_CT {
4028 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004029 /* 2+3+4 are mandatory and set in f_init() */
4030 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004031 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004032}
4033
4034testcase TC_si_sched_1() runs on test_CT {
4035 f_init();
4036 si_cfg.si1_present := true;
4037 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004038 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004040}
4041
4042testcase TC_si_sched_2bis() runs on test_CT {
4043 f_init();
4044 si_cfg.si2bis_present := true;
4045 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4046 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004047 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004048}
4049
4050testcase TC_si_sched_2ter() runs on test_CT {
4051 f_init();
4052 si_cfg.si2ter_present := true;
4053 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4054 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004055 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004056}
4057
4058testcase TC_si_sched_2ter_2bis() runs on test_CT {
4059 f_init();
4060 si_cfg.si2bis_present := true;
4061 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4062 si_cfg.si2ter_present := true;
4063 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4064 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004065 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004066}
4067
4068testcase TC_si_sched_2quater() runs on test_CT {
4069 f_init();
4070 si_cfg.si2quater_present := true;
4071 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004072 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004074}
4075
4076testcase TC_si_sched_13() runs on test_CT {
4077 f_init();
4078 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004079 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004080 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004081 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004082}
4083
4084testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4085 f_init();
4086 si_cfg.si2bis_present := true;
4087 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4088 si_cfg.si2ter_present := true;
4089 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4090 si_cfg.si2quater_present := true;
4091 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4092 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004093 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte9b965d52020-10-11 21:28:22 +02004094 f_TC_si_sched(16.0);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004095 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004096}
4097
4098
Harald Welte68e495b2018-02-25 00:05:57 +01004099testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004100 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004101 /* FIXME: enable / disable individual BCCH info */
4102 //ts_RSL_BCCH_INFO(si_type, info);
4103 /* expect no ERROR REPORT after either of them *
4104 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004105 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004106}
4107
Harald Welte93640c62018-02-25 16:59:33 +01004108/***********************************************************************
4109 * Low-Level Protocol Errors / ERROR REPORT
4110 ***********************************************************************/
4111
Harald Welte01d982c2018-02-25 01:31:40 +01004112private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4113 timer T := 5.0;
4114 T.start;
4115 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004116 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004117 setverdict(pass);
4118 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004119 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004120 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004121 }
4122 [] RSL_CCHAN.receive {
4123 repeat;
4124 }
4125 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004127 }
4128 }
4129}
4130
4131/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4132testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004133 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004134 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4135 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004136 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004137
4138 f_exp_err_rep(RSL_ERR_PROTO);
4139}
4140
4141/* Provoke a mandatory IE error and match on ERROR REPORT */
4142testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004143 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004144
4145 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4146 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004147 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004148
4149 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4150}
4151
4152/* Provoke an IE content error and match on ERROR REPORT */
4153testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004154 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004155 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4156 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004157 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004158
4159 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4160}
4161
Harald Welteee25aae2019-05-19 14:32:37 +02004162/* attempt to activate channel with wrong RSL Message Discriminator IE */
4163function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4164 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4165 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4166 RSL.send(rsl);
4167 f_rslem_unregister(0, g_chan_nr);
4168}
4169testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4170 var ConnHdlr vc_conn;
4171 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4172
Harald Welte10474062019-05-30 16:48:17 +02004173 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004174
4175 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4176 vc_conn.done;
4177 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4178
4179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4180}
4181
4182/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004183private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004184 var template (value) RSL_Message rsl_tx;
4185 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4186 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4187 RSL.send(rsl_tx);
4188 f_rslem_unregister(0, g_chan_nr);
4189}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004190private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004191 var template (value) RSL_Message rsl_tx;
4192 /* we first have to activate the dedicated channel */
4193 f_rsl_chan_act(g_pars.chan_mode);
4194 /* ... to then send an invalid RLL message */
4195 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4196 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4197 RSL.send(rsl_tx);
4198 f_rslem_unregister(0, g_chan_nr);
4199}
4200testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4201 var ConnHdlr vc_conn;
4202 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4203 var template (value) RSL_Message rsl_tx;
4204
Harald Welte10474062019-05-30 16:48:17 +02004205 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004206
4207 /* Common Channel with wrong message type */
4208 RSL_CCHAN.clear;
4209 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4210 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004211 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004212 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4213
4214 /* TRX Management */
4215 RSL_CCHAN.clear;
4216 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4217 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004218 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004219 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4220
4221 /* Dedicated Channel */
4222 RSL_CCHAN.clear;
4223 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4224 vc_conn.done;
4225 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4226
4227 /* RLL */
4228 RSL_CCHAN.clear;
4229 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4230 vc_conn.done;
4231 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4232}
4233
4234/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004235private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004236 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4237 f_rslem_unregister(0, g_chan_nr);
4238}
4239testcase TC_err_rep_wrong_sequence() runs on test_CT {
4240 var ConnHdlr vc_conn;
4241 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4242
Harald Welte10474062019-05-30 16:48:17 +02004243 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004244
4245 RSL_CCHAN.clear;
4246 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4247 vc_conn.done;
4248 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4249}
4250
Harald Welte93640c62018-02-25 16:59:33 +01004251/***********************************************************************
4252 * IPA CRCX/MDCX/DLCS media stream handling
4253 ***********************************************************************/
4254
Harald Weltea871a382018-02-25 02:03:14 +01004255/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004256private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004257 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4258 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004259}
4260testcase TC_ipa_dlcx_not_active() runs on test_CT {
4261 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004262 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004263 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4264 vc_conn.done;
4265}
Harald Welte68e495b2018-02-25 00:05:57 +01004266
Harald Weltea3f1df92018-02-25 12:49:55 +01004267/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004268private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004269 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4270 "IPA CRCX ACK");
4271 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4272 "IPA CRCX NACK");
4273}
4274testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4275 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004276 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004277 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4278 vc_conn.done;
4279}
4280
4281/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004282private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004283 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4284 "IPA CRCX ACK");
4285 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4286 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4287 var uint7_t rtp_pt2 := f_rnd_int(127);
4288 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4289 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4290 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4291 "IPA MDCX ACK");
4292 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4293 "IPA DLCX ACK");
4294}
4295testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4296 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004297 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004298 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4299 vc_conn.done;
4300}
4301
Harald Welte3ae11da2018-02-25 13:36:06 +01004302/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004303private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004304 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4305 "IPA CRCX ACK");
4306 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4307 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4308 var uint7_t rtp_pt2 := f_rnd_int(127);
4309 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4310 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4311 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4312 "IPA MDCX ACK");
4313 /* Second MDCX */
4314 remote_ip := f_rnd_int(c_UINT32_MAX);
4315 remote_port := f_rnd_int(c_UINT16_MAX);
4316 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4317 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4318 "IPA MDCX ACK");
4319 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4320 "IPA DLCX ACK");
4321}
4322testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4323 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004324 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004325 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4326 vc_conn.done;
4327}
4328
Harald Welte9912eb52018-02-25 13:30:15 +01004329/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004330private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004331 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4332 "IPA CRCX NACK");
4333}
4334testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4335 var ConnHdlrPars pars;
4336 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004337 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004338
4339 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4340 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4341 vc_conn.done;
4342
4343 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4344 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4345 vc_conn.done;
4346}
4347
Harald Weltea3f1df92018-02-25 12:49:55 +01004348
Harald Welte883340c2018-02-28 18:59:29 +01004349/***********************************************************************
4350 * PCU Socket related tests
4351 ***********************************************************************/
4352
Harald Welte07bd2d22019-05-25 11:03:30 +02004353/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004354friend 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 +01004355runs on test_CT {
4356 timer T := 3.0;
4357
4358 /* we don't expect any RTS.req before PDCH are active */
4359 T.start;
4360 alt {
4361 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004362 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004363 }
4364 [] PCU.receive { repeat; }
4365 [] T.timeout { }
4366 }
4367
4368 /* Send PDCH activate request for known PDCH timeslot */
4369 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4370
4371 /* we now expect RTS.req for this timeslot (only) */
4372 T.start;
4373 alt {
4374 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4375 setverdict(pass);
4376 }
4377 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4378 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004379 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004380 }
4381 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004382 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004383 }
4384 [] PCU.receive { repeat; }
4385 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004386 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004387 }
4388 [not exp_success] T.timeout {
4389 setverdict(pass);
4390 }
4391 }
4392}
4393
Harald Welte07bd2d22019-05-25 11:03:30 +02004394/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004395friend 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 +01004396runs on test_CT {
4397 timer T := 3.0;
4398
4399 /* Send PDCH activate request for known PDCH timeslot */
4400 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 +02004401 /* wait for some time as there is no PCUIF_DEACT_RESP or the like, so we don't know
4402 * when it will actually have been executed in the BTS */
4403 f_sleep(1.0);
Harald Welte883340c2018-02-28 18:59:29 +01004404 PCU.clear;
4405 /* we now expect no RTS.req for this timeslot */
4406 T.start;
4407 alt {
4408 [] 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 +02004409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004410 }
4411 [] PCU.receive { repeat; }
4412 [] T.timeout {
4413 setverdict(pass);
4414 }
4415 }
4416}
4417
Harald Weltead033dc2019-05-25 17:28:16 +02004418friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004419 f_init();
4420 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4421}
4422
Harald Welte883340c2018-02-28 18:59:29 +01004423/* PDCH activation via PCU socket; check for presence of RTS.req */
4424testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004425 f_init_pcu_test();
4426
Harald Welte883340c2018-02-28 18:59:29 +01004427 f_TC_pcu_act_req(0, 0, 7, true);
4428}
4429
4430/* PDCH activation via PCU socket on non-PDCU timeslot */
4431testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004432 f_init_pcu_test();
4433
Harald Welte883340c2018-02-28 18:59:29 +01004434 f_TC_pcu_act_req(0, 0, 1, false);
4435}
4436
4437/* PDCH activation via PCU socket on wrong BTS */
4438testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004439 f_init_pcu_test();
4440
Harald Welte883340c2018-02-28 18:59:29 +01004441 f_TC_pcu_act_req(23, 0, 7, false);
4442}
4443
4444/* PDCH activation via PCU socket on wrong TRX */
4445testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004446 f_init_pcu_test();
4447
Harald Welte883340c2018-02-28 18:59:29 +01004448 f_TC_pcu_act_req(0, 23, 7, false);
4449}
4450
4451/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4452testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004453 f_init_pcu_test();
4454
Harald Welte883340c2018-02-28 18:59:29 +01004455 /* Activate PDCH */
4456 f_TC_pcu_act_req(0, 0, 7, true);
4457 f_sleep(1.0);
4458 /* and De-Activate again */
4459 f_TC_pcu_deact_req(0, 0, 7);
4460}
4461
4462/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4463testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004464 f_init_pcu_test();
4465
Harald Welte883340c2018-02-28 18:59:29 +01004466 f_TC_pcu_deact_req(0, 0, 1);
4467}
4468
4469/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4470testcase TC_pcu_ver_si13() runs on test_CT {
4471 const octetstring si13 := '00010203040506070909'O;
4472 var PCUIF_send_data sd;
4473 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004474 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004475
4476 /* Set SI13 via RSL */
4477 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004478
Harald Welte883340c2018-02-28 18:59:29 +01004479 T.start;
4480 alt {
4481 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4482 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4483 setverdict(pass);
4484 } else {
4485 repeat;
4486 }
4487 }
4488 [] PCU.receive { repeat; }
4489 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004491 }
4492 }
4493}
4494
4495private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4496
4497/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004498friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004499 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4500runs on test_CT
4501{
4502 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4503 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4504}
4505
4506/* 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 +02004507friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4508 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004509runs on test_CT
4510{
4511 var PCUIF_send_data sd;
4512
4513 timer T := 3.0;
4514 T.start;
4515 alt {
4516 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4517 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4518 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4519 sd.data.u.rts_req.fn, sapi, data);
4520 }
4521 [] PCU.receive { repeat; }
4522 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004523 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004524 }
4525 }
4526}
4527
4528/* Send DATA.req on invalid BTS */
4529testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004530 var TfiUsfArr tua := f_TfiUsfArrInit();
4531 var octetstring data := '0000'O & f_rnd_octstring(21);
4532
4533 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004534
Harald Welte883340c2018-02-28 18:59:29 +01004535 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004536 f_TfiUsfArrSet(tua, 7, 0);
4537 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4538 f_sleep(1.0);
4539
4540 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004541}
4542
4543/* Send DATA.req on invalid TRX */
4544testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004545 var TfiUsfArr tua := f_TfiUsfArrInit();
4546 var octetstring data := '0000'O & f_rnd_octstring(21);
4547
4548 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004549
Harald Welte883340c2018-02-28 18:59:29 +01004550 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004551 f_TfiUsfArrSet(tua, 7, 0);
4552 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4553 f_sleep(1.0);
4554
4555 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004556}
4557
4558/* Send DATA.req on invalid timeslot */
4559testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004560 var TfiUsfArr tua := f_TfiUsfArrInit();
4561 var octetstring data := '0000'O & f_rnd_octstring(21);
4562
4563 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004564
Harald Welte883340c2018-02-28 18:59:29 +01004565 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004566 f_TfiUsfArrSet(tua, 7, 0);
4567 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4568 f_sleep(1.0);
4569
4570 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004571}
4572
4573/* Send DATA.req on timeslot that hasn't been activated */
4574testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004575 var TfiUsfArr tua := f_TfiUsfArrInit();
4576 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004577
Harald Welte7162a612019-05-26 12:56:09 +02004578 f_virtphy_common();
4579
4580 f_TfiUsfArrSet(tua, 7, 0);
4581 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4582 f_sleep(1.0);
4583
4584 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004585}
4586
Harald Weltead033dc2019-05-25 17:28:16 +02004587private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004588 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4589 boolean wait_rts := true)
4590runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004591 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004592 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004593
4594 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004595 if (wait_rts) {
4596 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4597 } else {
4598 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4599 }
Harald Weltead033dc2019-05-25 17:28:16 +02004600
4601 T.start;
4602 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004603 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004604 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4605 setverdict(pass);
4606 }
Harald Welte7162a612019-05-26 12:56:09 +02004607 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4608 setverdict(fail, "Received unexpected ", rx_dl);
4609 }
Harald Weltead033dc2019-05-25 17:28:16 +02004610 [] L1CTL.receive {
4611 repeat;
4612 }
Harald Welte7162a612019-05-26 12:56:09 +02004613 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004614 setverdict(fail, "Timeout waiting for ", data);
4615 }
Harald Welte7162a612019-05-26 12:56:09 +02004616 [not expect_data] T.timeout {
4617 setverdict(pass);
4618 }
Harald Weltead033dc2019-05-25 17:28:16 +02004619 }
4620}
4621
4622private function f_disable_dynamic_ts() runs on test_CT
4623{
4624 f_init_vty_bsc();
4625 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4626 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4627 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4628 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004629 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004630}
4631
4632private function f_virtphy_common() runs on test_CT {
4633 f_disable_dynamic_ts();
4634 f_init_l1ctl();
4635 f_l1_tune(L1CTL);
4636}
4637
4638testcase TC_pcu_data_req_pdtch() runs on test_CT {
4639 var TfiUsfArr tua := f_TfiUsfArrInit();
4640 var octetstring data := '0000'O & f_rnd_octstring(21);
4641
4642 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004643
Harald Welte883340c2018-02-28 18:59:29 +01004644 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004645 f_TfiUsfArrSet(tua, 7, 0);
4646 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4647 f_sleep(1.0);
4648
4649 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004650}
4651
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004652/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004653testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004654 var TfiUsfArr tua := f_TfiUsfArrInit();
4655 var octetstring data := '0000'O & f_rnd_octstring(21);
4656
4657 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004658
Harald Welte883340c2018-02-28 18:59:29 +01004659 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004660 f_TfiUsfArrSet(tua, 7, 0);
4661 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4662 f_sleep(1.0);
4663
4664 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004665}
4666
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004667private function f_TC_pcu_ptcch_ul(uint16_t ra)
4668runs on test_CT {
4669 var template PCUIF_Message pcu_rach_ind;
4670 var PCUIF_send_data sd;
4671 var GsmFrameNumber fn;
4672 timer T;
4673
4674 /* Send an Access Burst on PTCCH/U over the Um-interface */
4675 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4676 chan_nr := ts_RslChanNr_PDCH(7),
4677 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4678
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004679 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4680 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004681
4682 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4683 T.start(52.0 * 4.615 / 1000.0);
4684 alt {
4685 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4686 log("Rx an Access Burst on the PCU interface: ", sd.data);
4687 setverdict(pass);
4688 T.stop;
4689 }
4690 [] PCU.receive { repeat; }
4691 [] T.timeout {
4692 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4693 /* Keep going, that's not the end of the world */
4694 }
4695 }
4696}
4697
4698testcase TC_pcu_ptcch() runs on test_CT {
4699 var L1ctlDlMessage dl;
4700 var octetstring data;
4701 timer T;
4702
4703 f_init_pcu_test();
4704 f_init_l1ctl();
4705 f_l1_tune(L1CTL);
4706
4707 /* Activate PDCH channel on TS7 */
4708 f_TC_pcu_act_req(0, 0, 7, true);
4709
4710 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004711 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004712 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004713 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004714 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004715
4716 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4717 for (var integer i := 0; i < 16; i := i + 1) {
4718 log("Sending an Access Burst towards the L1CTL interface");
4719 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4720 }
4721
4722 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4723 data := f_rnd_octstring(23);
4724
4725 /* Verify PTCCH/D: send a random data block, make sure it's received */
4726 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4727 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4728
4729 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4730 * let's give it more time in case if we miss the beginning. */
4731 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4732 alt {
4733 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4734 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4735 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4736 frame := data)) -> value dl {
4737 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4738 setverdict(pass);
4739 T.stop;
4740 }
4741 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4742 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4743 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4744 l2_data := data)) -> value dl {
4745 log("Rx PTCCH/D data block on L1CTL: ", dl);
4746 setverdict(pass);
4747 T.stop;
4748 }
4749 [] L1CTL.receive { repeat; }
4750 [] T.timeout {
4751 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4752 }
4753 }
4754}
4755
Harald Welte883340c2018-02-28 18:59:29 +01004756/* Send AGCH from PCU; check it appears on Um side */
4757testcase TC_pcu_data_req_agch() runs on test_CT {
4758 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004759 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004760 f_init_l1ctl();
4761 f_l1_tune(L1CTL);
4762
4763 f_TC_pcu_act_req(0, 0, 7, true);
4764 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4765
4766 T.start;
4767 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004768 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004769 setverdict(pass);
4770 }
4771 [] L1CTL.receive { repeat; }
4772 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004774 }
4775 }
4776}
4777
Harald Welte928622b2019-05-26 13:22:59 +02004778/* Send AGCH from PCU; check it appears on Um side */
4779testcase TC_pcu_data_req_pch() runs on test_CT {
4780 timer T := 3.0;
4781 f_init_pcu_test();
4782 f_init_l1ctl();
4783 f_l1_tune(L1CTL);
4784
4785 f_TC_pcu_act_req(0, 0, 7, true);
4786 /* three characters prefix: last 3 digits of IMSI as ASCII */
4787 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4788
4789 T.start;
4790 alt {
4791 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4792 setverdict(pass);
4793 }
4794 [] L1CTL.receive { repeat; }
4795 [] T.timeout {
4796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4797 }
4798 }
4799}
4800
Harald Welte883340c2018-02-28 18:59:29 +01004801/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4802testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4803 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004804 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004805 f_init_l1ctl();
4806 f_l1_tune(L1CTL);
4807
4808 /* append 3 last imsi digits so BTS can compute pagng group */
4809 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4810
4811 timer T := 0.5;
4812 T.start;
4813 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004814 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004815 /* TODO: verify paging group */
4816 setverdict(pass);
4817 }
4818 [] L1CTL.receive { repeat; }
4819 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004821 }
4822 }
4823}
4824
4825/* Send RACH from Um side, expect it to show up on PCU socket */
4826testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004827 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004828 f_init_l1ctl();
4829 f_l1_tune(L1CTL);
4830
4831 var GsmFrameNumber fn_last := 0;
4832 for (var integer i := 0; i < 1000; i := i+1) {
4833 var OCT1 ra := f_rnd_ra_ps();
4834 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4835 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004836 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004837 }
4838 fn_last := fn;
4839
4840 timer T := 2.0;
4841 T.start;
4842 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004843 [] 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 +01004844 T.stop;
4845 }
4846 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004848 }
4849 [] PCU.receive { repeat; }
4850 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004851 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004852 }
4853 }
4854 }
4855 setverdict(pass);
4856}
4857
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004858/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4859 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4860testcase TC_pcu_ext_rach_content() runs on test_CT {
4861 var template PCUIF_Message pcu_rach_ind;
4862 var GsmFrameNumber fn_last := 0;
4863 var L1ctlRachSynchSeq synch_seq;
4864 var PCUIF_BurstType pcu_bt;
4865 var GsmFrameNumber fn;
4866 var BIT11 ra11;
4867
4868 f_init_pcu_test();
4869 f_init_l1ctl();
4870 f_l1_tune(L1CTL);
4871
4872 for (var integer i := 0; i < 1000; i := i+1) {
4873 /* We need to test both TS1 & TS2 */
4874 if (i rem 2 == 0) {
4875 synch_seq := RACH_SYNCH_SEQ_TS1;
4876 pcu_bt := BURST_TYPE_1;
4877 } else {
4878 synch_seq := RACH_SYNCH_SEQ_TS2;
4879 pcu_bt := BURST_TYPE_2;
4880 }
4881
4882 ra11 := f_rnd_ra11_ps();
4883 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4884 if (fn == fn_last) {
4885 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4886 "Two RACH in same FN?!?");
4887 }
4888 fn_last := fn;
4889
4890 /* Compose the expected message */
4891 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004892 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004893 ra := bit2int(ra11),
4894 is_11bit := 1,
4895 burst_type := pcu_bt,
4896 fn := fn);
4897
4898 timer T := 2.0;
4899 T.start;
4900 alt {
4901 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4902 T.stop;
4903 }
4904 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4905 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4906 }
4907 [] PCU.receive { repeat; }
4908 [] T.timeout {
4909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4910 }
4911 }
4912 }
4913 setverdict(pass);
4914}
4915
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004916private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4917runs on test_CT {
4918 var template PCUIF_send_data sdt;
4919 var PCUIF_send_data sd;
4920 var int16_t lqual_cb;
4921 timer T := 1.0;
4922
4923 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4924 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4925
4926 /* Send a random PDTCH frame over Um */
4927 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4928 '0000'O & f_rnd_octstring(21)));
4929
4930 T.start;
4931 alt {
4932 /* If expected link quality is above the threshold */
4933 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4934 lqual_cb := sd.data.u.data_ind.lqual_cb;
4935 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4936
4937 /* Make sure the actual link quality matches the expected value */
4938 if (not match(lqual_cb, lqual_cb_exp)) {
4939 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4940 "expected value ", lqual_cb_exp));
4941 } else {
4942 setverdict(pass);
4943 }
4944 }
4945 /* If expected link quality is below the threshold */
4946 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4947 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4948 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4949 }
4950 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4951 [] PCU.receive { repeat; }
4952 [lqual_cb_exp < thresh] T.timeout {
4953 log("Rx nothing, as expected");
4954 setverdict(pass);
4955 }
4956 [lqual_cb_exp >= thresh] T.timeout {
4957 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4958 "Timeout waiting for PCUIF_DATA.ind");
4959 }
4960 }
4961}
4962
4963/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4964testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4965 f_init_pcu_test();
4966 PCU.clear;
4967
4968 f_init_l1ctl();
4969 f_l1_tune(L1CTL);
4970
4971 /* Activate a PDCH channel on TS7 */
4972 f_TC_pcu_act_req(0, 0, 7, true);
4973
4974 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004975 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004976 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiyca813922020-09-12 19:08:31 +07004977 { f_resolve_fh_params(pars.fhp, pars.chan_nr.tn); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004978 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004979
4980 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4981 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4982 var TrxcMessage ret;
4983
4984 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4985 valueof(ts_TRXC_FAKE_CI(i)));
4986
4987 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4988 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4989 }
4990}
4991
Harald Welte883340c2018-02-28 18:59:29 +01004992/* Send PAGING via RSL, expect it to shw up on PCU socket */
4993testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004994 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004995
4996 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004997 var MobileIdentityLV mi_lv;
4998 var octetstring mi_lv_enc;
4999 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01005000 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005001
Harald Welte883340c2018-02-28 18:59:29 +01005002 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005003 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01005004 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005005 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01005006 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005007
5008 /* Fancy encoding for PCUIF */
5009 mi_lv := valueof(ts_MI_LV(mi));
5010 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5011 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005012
5013 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005014 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005015 T.start;
5016 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005017 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005018 }
5019 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005021 }
5022 [] PCU.receive { repeat; }
5023 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005024 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005025 }
5026 }
5027 }
5028 setverdict(pass);
5029}
5030
Harald Welted66c9b82019-05-25 09:03:15 +02005031/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5032testcase TC_pcu_time_ind() runs on test_CT {
5033 var PCUIF_send_data pcu_sd;
5034 var integer num_time_ind := 0;
5035 var integer first_fn, last_fn;
5036 var float test_duration := 5.0;
5037 timer T;
5038
5039 f_init_pcu_test();
5040 f_TC_pcu_act_req(0, 0, 7, true);
5041
5042 PCU.clear;
5043 T.start(test_duration);
5044 alt {
5045 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5046 num_time_ind := num_time_ind + 1;
5047 if (not isbound(first_fn)) {
5048 first_fn := pcu_sd.data.u.time_ind.fn;
5049 }
5050 last_fn := pcu_sd.data.u.time_ind.fn;
5051 repeat;
5052 }
5053 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5054 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5055 repeat;
5056 }
5057 [] PCU.receive {
5058 repeat;
5059 }
5060 [] T.timeout {}
5061 }
5062 var integer fn_expired := last_fn - first_fn;
5063 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5064
5065 /* verify the number of frames expired matches our expectation */
5066 const float c_GSM_FN_DURATION_MS := 4.61538;
5067 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005068 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005069 if (not match(fn_expired, t_fn_expected)) {
5070 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5071 }
5072
5073 /* There are three TIME.ind in every fn MOD 13 */
5074 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5075 /* Add some tolerance */
5076 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5077 if (not match(num_time_ind, t_time_ind_exp)) {
5078 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5079 }
5080
5081 setverdict(pass);
5082}
5083
Harald Welte4832c862019-05-25 14:57:18 +02005084/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5085testcase TC_pcu_rts_req() runs on test_CT {
5086 var PCUIF_send_data pcu_sd;
5087 var integer first_fn, last_fn;
5088 var integer num_rts_pdtch := 0;
5089 var integer num_rts_ptcch := 0;
5090 var float test_duration := 5.0;
5091 timer T;
5092
5093 f_init_pcu_test();
5094 f_TC_pcu_act_req(0, 0, 7, true);
5095
5096 PCU.clear;
5097 T.start(test_duration);
5098 alt {
5099 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5100 -> value pcu_sd {
5101 num_rts_pdtch := num_rts_pdtch + 1;
5102 if (not isbound(first_fn)) {
5103 first_fn := pcu_sd.data.u.rts_req.fn;
5104 }
5105 last_fn := pcu_sd.data.u.rts_req.fn;
5106 repeat;
5107 }
5108 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5109 -> value pcu_sd {
5110 num_rts_ptcch := num_rts_ptcch + 1;
5111 if (not isbound(first_fn)) {
5112 first_fn := pcu_sd.data.u.rts_req.fn;
5113 }
5114 last_fn := pcu_sd.data.u.rts_req.fn;
5115 repeat;
5116 }
5117 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5118 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5119 repeat;
5120 }
5121 [] PCU.receive {
5122 repeat;
5123 }
5124 [] T.timeout {}
5125 }
5126 var integer fn_expired := last_fn - first_fn;
5127 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5128 ", num_rts_ptcch=", num_rts_ptcch);
5129
5130 /* verify the number of frames expired matches our expectation */
5131 const float c_GSM_FN_DURATION_MS := 4.61538;
5132 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005133 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005134 if (not match(fn_expired, t_fn_expected)) {
5135 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5136 }
5137
5138 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5139 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5140 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5141 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5142 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5143 t_ptcch_exp);
5144 }
5145
5146 /* We have 12 PDTCH blocks every 52-multiframe */
5147 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5148 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5149 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5150 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5151 t_pdtch_exp);
5152 }
5153
5154 setverdict(pass);
5155}
5156
Harald Welte07bd2d22019-05-25 11:03:30 +02005157/* test for generating Abis side OML ALERT from the PCU */
5158testcase TC_pcu_oml_alert() runs on test_CT {
5159 var PCUIF_send_data pcu_sd;
5160 var integer num_time_ind := 0;
5161 var integer first_fn, last_fn;
5162 var float test_duration := 5.0;
5163 timer T;
5164
5165 f_init_pcu_test();
5166 f_TC_pcu_act_req(0, 0, 7, true);
5167
5168 /* re-connect CTRL port from BTS to BSC */
5169 f_ipa_ctrl_stop();
5170 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5171
5172 /* Send that OML Alert */
5173 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5174
5175 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5176 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5177 setverdict(pass);
5178}
5179
Harald Welteeaa9a862019-05-26 23:01:08 +02005180/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5181private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5182 var PCUIF_Message first_info;
5183 var integer pcu_conn_id := -1;
5184 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5185 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5186 var OCT4 tlli := '01020304'O;
5187 var OCT1 cause := '23'O;
5188 timer T := 5.0;
5189
5190 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5191
5192 f_l1_tune(L1CTL);
5193 RSL.clear;
5194
5195 f_est_dchan();
5196 L1CTL.clear;
5197
5198 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5199
5200 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5201 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5202 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5203
5204 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5205 T.start;
5206 alt {
5207 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5208 setverdict(pass);
5209 }
5210 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5211 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5212 }
5213 [] PCU.receive {
5214 repeat;
5215 }
5216 [] T.timeout {
5217 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5218 }
5219 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005220
5221 /* release the channel */
5222 f_rsl_chan_deact();
5223 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5224 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005225}
5226testcase TC_pcu_rr_suspend() runs on test_CT {
5227 var ConnHdlrPars pars;
5228 var ConnHdlr vc_conn;
5229
5230 f_init();
5231
5232 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5233 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5234 vc_conn.done;
5235}
Harald Welte07bd2d22019-05-25 11:03:30 +02005236
Harald Weltea2e0e942019-05-27 18:12:53 +02005237/* Ensure that PCUIF socket can accept only a single connection */
5238testcase TC_pcu_socket_connect_multi() runs on test_CT {
5239 timer T := 5.0;
5240
5241 /* this (among other things) establishes the first connection to the PCUIF socket */
5242 f_init();
5243
5244 /* try to establish a second connection, expect it to fail */
5245 PCU.send(UD_connect:{mp_pcu_socket, -1});
5246 T.start;
5247 alt {
5248 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5249 setverdict(pass);
5250 }
5251 [] PCU.receive(UD_connect_result:?) {
5252 setverdict(fail, "Unexpected unix domain connect result");
5253 }
5254 [] T.timeout {
5255 setverdict(pass);
5256 }
5257 }
5258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5259}
5260
Harald Weltec8effb72019-05-27 18:23:04 +02005261/* Ensure that PCUIF socket can disconnect + reconnect */
5262testcase TC_pcu_socket_reconnect() runs on test_CT {
5263 /* this (among other things) establishes the first connection to the PCUIF socket */
5264 f_init();
5265
5266 f_sleep(1.0);
5267
5268 f_pcuif_close(PCU, g_pcu_conn_id);
5269 g_pcu_conn_id := -1;
5270
5271 f_sleep(1.0);
5272
5273 /* re-connect */
5274 PCU.clear;
5275 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5276 setverdict(pass);
5277
5278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5279}
5280
Harald Weltebe030482019-05-27 22:29:35 +02005281/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005282private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5283runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005284 var L1ctlDlMessage l1_dl;
5285 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005286 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005287 timer T := 5.0;
5288 T.start;
5289 alt {
5290 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005291 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5292 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005293 repeat;
5294 }
5295 }
5296 [] pt.receive {
5297 repeat;
5298 }
5299 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005300 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5301 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005302 }
5303 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005304 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005305}
5306
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005307/* Check if GPRS Indicator is present in RR System Information of a given type */
5308private function f_si_has_gprs_indicator(RrMessageType si_type)
5309runs on test_CT return boolean {
5310 var SystemInformation si := f_get_si(L1CTL, si_type);
5311
5312 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005313 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005314 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005315 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005316 }
5317
5318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5319 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005320}
5321
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005322/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5323private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5324runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005325 /* don't call f_init() as this would connect PCU socket */
5326 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005327
5328 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005329 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005330 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005331
5332 f_init_l1ctl();
5333 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005334 f_sleep(2.0);
5335 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005336
5337 if (f_si_has_gprs_indicator(si_type)) {
5338 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005339 } else {
5340 setverdict(pass);
5341 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005342
Harald Weltebe030482019-05-27 22:29:35 +02005343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5344}
5345
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005346testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5347 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5348}
Harald Weltebe030482019-05-27 22:29:35 +02005349
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005350testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5351 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5352}
5353
5354/* Ensure that GPRS capability is advertised after PCU socket connect */
5355private function f_TC_pcu_socket_connect(RrMessageType si_type)
5356runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005357 /* this (among other things) establishes the first connection to the PCUIF socket */
5358 f_init();
5359 f_init_l1ctl();
5360 f_l1_tune(L1CTL);
5361
5362 f_sleep(2.0);
5363 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005364
5365 if (not f_si_has_gprs_indicator(si_type)) {
5366 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005367 } else {
5368 setverdict(pass);
5369 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005370
Harald Weltebe030482019-05-27 22:29:35 +02005371 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5372}
5373
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005374testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5375 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5376}
Harald Weltebe030482019-05-27 22:29:35 +02005377
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005378testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5379 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5380}
5381
5382/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5383private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5384runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005385 /* this (among other things) establishes the first connection to the PCUIF socket */
5386 f_init();
5387 f_init_l1ctl();
5388 f_l1_tune(L1CTL);
5389
5390 f_pcuif_close(PCU, g_pcu_conn_id);
5391 g_pcu_conn_id := -1;
5392
5393 f_sleep(1.0);
5394
5395 /* re-connect */
5396 PCU.clear;
5397 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5398
5399 f_sleep(2.0);
5400 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005401
5402 if (f_si_has_gprs_indicator(si_type)) {
5403 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005404 } else {
5405 setverdict(pass);
5406 }
5407
5408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5409}
5410
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005411testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5412 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5413}
5414
5415testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5416 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5417}
5418
Oliver Smithf5239c72019-08-28 10:01:25 +02005419/* 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) */
5420testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5421 var SystemInformation si3 := valueof(ts_SI3_default);
5422
5423 f_init();
5424
Harald Welte76220222020-10-11 20:32:44 +02005425 /* actually give the BTS some time to fully come up and to send a PCU INFO IND with the correct
5426 * information */
5427 timer T := 2.0;
5428 T.start;
5429 alt {
5430 [] as_pcu_info_ind(PCU, g_pcu_conn_id, g_pcu_last_info) { repeat; }
5431 [] T.timeout {}
5432 }
5433
Oliver Smithf5239c72019-08-28 10:01:25 +02005434 /* Verify cell_id */
5435 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5436 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5437 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005438 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5439 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5440 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005441 }
5442
5443 /* Verify LAC */
5444 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5445 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5446 if (lac_si3 != lac_pcu) {
5447 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5448 }
5449
5450 setverdict(pass);
5451}
Harald Welted66c9b82019-05-25 09:03:15 +02005452
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005453/* Verify hopping parameters in the INFO.ind message (version >= 10) */
5454testcase TC_pcu_info_ind_fh_params() runs on test_CT {
5455 var PCUIF_info_ind info_ind;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005456 var FreqHopPars fhp;
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005457
5458 f_init();
5459
5460 info_ind := g_pcu_last_info.u.info_ind;
5461
5462 for (var integer i := 0; i < mp_transceiver_num; i := i + 1) {
5463 for (var integer tn := 0; tn < 8; tn := tn + 1) {
5464 if (info_ind.trx.v10[i].pdch_mask[tn] != '1'B) {
5465 /* Skip inactive timeslots */
5466 continue;
5467 }
5468
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005469 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
Vadim Yanitskiy7e1d0a22020-09-17 19:48:11 +07005470 { f_resolve_fh_params(fhp, tn, trx_nr := i); }
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005471 else
5472 { fhp.enabled := false; }
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005473
5474 var template PCUIF_InfoTrxTs tr_ts;
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005475 if (fhp.enabled) {
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005476 tr_ts := tr_PCUIF_InfoTrxTsH1(
Vadim Yanitskiyca813922020-09-12 19:08:31 +07005477 hsn := fhp.maio_hsn.hsn,
5478 maio := fhp.maio_hsn.maio,
5479 ma := f_pad_bit(fhp.ma_map.ma, 64, '0'B),
Vadim Yanitskiyaa553ed2020-09-17 19:44:32 +07005480 ma_bit_len := mp_transceiver_num);
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07005481 } else {
5482 tr_ts := tr_PCUIF_InfoTrxTsH0;
5483 }
5484
5485 var PCUIF_InfoTrxTs ts := info_ind.trx.v10[i].ts[tn];
5486 log("Checking timeslot #", tn, " of trx#", i, ": ", ts);
5487 if (not match(ts, tr_ts)) {
5488 setverdict(fail, "Hopping parameters do not match: ",
5489 "received ", ts, " vs expected ", tr_ts);
5490 } else {
5491 setverdict(pass);
5492 }
5493 }
5494 }
5495}
5496
Alexander Couzens5283f552020-07-28 15:39:04 +02005497/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5498testcase TC_pcu_socket_nsvc_ipv4() runs on test_CT {
5499 f_init_vty_bsc();
5500 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip 127.127.127.127");
5501 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5502
5503 f_init();
5504
5505 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5506 if (not ischosen(remote_addr.v10)) {
5507 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5508 log2str("Unexpected remote_addr: ", remote_addr));
5509 }
5510
5511 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV4) {
5512 setverdict(fail, "Received address family is not IPv4");
5513 }
5514
5515 if (substr(remote_addr.v10.addr[0], 0, 4) != f_inet_addr("127.127.127.127")) {
5516 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5517 }
5518
5519 setverdict(pass);
5520}
5521
5522/* Verify IPv4 NSVC address in the INFO.ind message (version >= 10) */
5523testcase TC_pcu_socket_nsvc_ipv6() runs on test_CT {
5524 f_init_vty_bsc();
5525 f_vty_config2(BSCVTY, {"network", "bts 0"} , "gprs nsvc 0 remote ip fd00::ca:ff:ee");
5526
5527 f_init();
5528
5529 var PCUIF_RemoteAddr remote_addr := g_pcu_last_info.u.info_ind.remote_addr;
5530 if (not ischosen(remote_addr.v10)) {
5531 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5532 log2str("Unexpected remote_addr: ", remote_addr));
5533 }
5534
5535 if (remote_addr.v10.addr_type[0] != PCUIF_ADDR_TYPE_IPV6) {
5536 setverdict(fail, "Received address family is not IPv6");
5537 }
5538
5539 if (remote_addr.v10.addr[0] != f_inet6_addr("fd00::ca:ff:ee")) {
5540 setverdict(fail, "Unexpected address: ", remote_addr.v10.addr[0]);
5541 }
5542
5543 setverdict(pass);
5544}
5545
Harald Welte3d04ae62018-04-04 20:29:05 +02005546/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005547 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005548 ***********************************************************************/
5549
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005550private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5551 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005552runs on ConnHdlr {
5553 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005554
5555 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
Vadim Yanitskiy9e1206c2020-07-19 15:52:31 +07005556 var bitstring pdch_mask := f_PCUIF_ver_INFO_PDCHMask(sd.data.u.info_ind, trx_nr);
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005557 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5558 repeat;
5559 }
5560 }
5561}
5562
5563private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5564runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005565 /* Expect BTS to immediately acknowledge activation as PDCH */
5566 PCU.clear;
5567 f_rsl_chan_act(g_pars.chan_mode);
5568 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005569 timer T_wait := 2.0;
5570 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005571 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005572 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005573 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005574 [] T_wait.timeout {
5575 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5576 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5577 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005578 }
5579 /* try to activate this PDCH from the PCU point of view */
5580 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5581 /* FIXME: is there a response? */
5582}
5583
5584private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5585runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005586 /* Send RSL CHAN REL (deactivate) */
5587 PCU.clear;
5588 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5589 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005590 timer T_wait := 2.0;
5591 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005592 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005593 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005594 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005595 [] T_wait.timeout {
5596 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5597 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5598 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005599 }
5600 /* Emulate PCU asking BTS to deactivate PDCH */
5601 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5602 alt {
5603 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5604 setverdict(pass);
5605 }
5606 [] RSL.receive { repeat; }
5607 }
5608}
5609
5610/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005611private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005612 var PCUIF_Message first_info;
5613 var integer ts_nr := g_chan_nr.tn;
5614 var integer trx_nr := 0;
5615 var integer bts_nr := 0;
5616 var integer pcu_conn_id := -1;
5617
5618 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5619
5620 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5621 f_sleep(3.0);
5622 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5623 setverdict(pass);
5624}
5625testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5626 var ConnHdlrPars pars;
5627 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005628 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005629
5630 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5631 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5632 vc_conn.done;
5633}
5634
5635/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005636private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005637 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005638 var integer pcu_conn_id := -1;
5639
5640 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5641
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005642 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5643 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5644 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005645 setverdict(pass);
5646}
5647testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5648 var ConnHdlrPars pars;
5649 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005650 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005651
5652 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5653 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5654 vc_conn.done;
5655}
5656
5657/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005658private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005659 var PCUIF_Message first_info;
5660 var integer ts_nr := g_chan_nr.tn;
5661 var integer trx_nr := 0;
5662 var integer bts_nr := 0;
5663 var integer pcu_conn_id := -1;
5664
5665 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5666
5667 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005668 /* Send a second Chan Activ and expect it to be NACKed */
5669 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5670 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005671 setverdict(pass);
5672}
5673testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5674 var ConnHdlrPars pars;
5675 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005676 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005677
5678 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5679 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5680 vc_conn.done;
5681}
5682
5683/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005684private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005685 var PCUIF_Message first_info;
5686 var integer ts_nr := g_chan_nr.tn;
5687 var integer trx_nr := 0;
5688 var integer bts_nr := 0;
5689 var integer pcu_conn_id := -1;
5690 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5691
5692 /* register for the TCH/F channel number */
5693 f_rslem_register(0, chan_nr);
5694
5695 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5696
5697 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5698 "RSL CHAN ACT");
5699 setverdict(pass);
5700}
5701testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5702 var ConnHdlrPars pars;
5703 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005704 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005705
5706 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5707 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5708 vc_conn.done;
5709}
5710
5711/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005712private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005713 var PCUIF_Message first_info;
5714 var integer ts_nr := g_chan_nr.tn;
5715 var integer trx_nr := 0;
5716 var integer bts_nr := 0;
5717 var integer pcu_conn_id := -1;
5718 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5719 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5720
5721 /* register for the TCH/H channel numbers */
5722 f_rslem_register(0, chan_nr[0]);
5723 f_rslem_register(0, chan_nr[1]);
5724
5725 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5726
5727 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5728 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5729 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5730 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5731 setverdict(pass);
5732}
5733testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5734 var ConnHdlrPars pars;
5735 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005736 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005737
5738 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5739 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5740 vc_conn.done;
5741}
5742
Harald Welte9bbbfb52018-04-05 09:33:19 +02005743/***********************************************************************
5744 * IPA Style Dynamic Timeslot Support
5745 ***********************************************************************/
5746
5747private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5748runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005749 /* Expect BTS to immediately acknowledge activation as PDCH */
5750 PCU.clear;
5751 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5752 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005753 timer T_wait := 2.0;
5754 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005755 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005756 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005757 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005758 [] T_wait.timeout {
5759 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5760 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5761 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005762 }
5763 /* try to activate this PDCH from the PCU point of view */
5764 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5765 /* FIXME: is there a response? */
5766
5767 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5768}
5769
5770private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5771runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005772 /* Send RSL CHAN REL (deactivate) */
5773 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5774 PCU.clear;
5775 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005776 timer T_wait := 2.0;
5777 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005778 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005779 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005780 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005781 [] T_wait.timeout {
5782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5783 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5784 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005785 }
5786 /* Emulate PCU asking BTS to deactivate PDCH */
5787 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5788 alt {
5789 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5790 setverdict(pass);
5791 }
5792 [] RSL.receive { repeat; }
5793 }
5794}
5795
5796/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005797private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005798 var PCUIF_Message first_info;
5799 var integer ts_nr := g_chan_nr.tn;
5800 var integer trx_nr := 0;
5801 var integer bts_nr := 0;
5802 var integer pcu_conn_id := -1;
5803
5804 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5805
5806 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5807 f_sleep(3.0);
5808 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5809
5810 setverdict(pass);
5811
5812}
5813testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5814 var ConnHdlrPars pars;
5815 var ConnHdlr vc_conn;
5816 f_init();
5817
5818 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5819 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5820 vc_conn.done;
5821}
5822
5823/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005824private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005825 var PCUIF_Message first_info;
5826 var integer ts_nr := g_chan_nr.tn;
5827 var integer trx_nr := 0;
5828 var integer bts_nr := 0;
5829 var integer pcu_conn_id := -1;
5830
5831 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5832
5833 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5834 "RSL CHAN ACT");
5835 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5836 "RF CHAN REL", true);
5837 setverdict(pass);
5838}
5839testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5840 var ConnHdlrPars pars;
5841 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005842 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005843
5844 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5845 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5846 vc_conn.done;
5847}
5848
5849/* 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 +07005850private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005851 var PCUIF_Message first_info;
5852 var integer ts_nr := g_chan_nr.tn;
5853 var integer trx_nr := 0;
5854 var integer bts_nr := 0;
5855 var integer pcu_conn_id := -1;
5856
5857 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5858
5859 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5860 "RSL CHAN ACT");
5861
5862 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5863 alt {
5864 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5865 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005866 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005867 }
5868 [] RSL.receive { repeat; }
5869 }
5870
5871 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5872 "RF CHAN REL", true);
5873 setverdict(pass);
5874}
5875testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5876 var ConnHdlrPars pars;
5877 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005878 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005879
5880 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5881 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5882 vc_conn.done;
5883}
5884
5885/* 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 +07005886private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005887 var PCUIF_Message first_info;
5888 var integer ts_nr := g_chan_nr.tn;
5889 var integer trx_nr := 0;
5890 var integer bts_nr := 0;
5891 var integer pcu_conn_id := -1;
5892
5893 /* register for the TCH/F channel number */
5894 f_rslem_register(0, g_chan_nr);
5895
5896 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5897
5898 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5899
5900 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5901 "RSL CHAN ACT");
5902
5903 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5904
5905 setverdict(pass);
5906}
5907testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5908 var ConnHdlrPars pars;
5909 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005910 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005911
5912 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5913 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5914 vc_conn.done;
5915}
5916
5917
Harald Welte0472ab42018-03-12 15:02:26 +01005918/***********************************************************************
5919 * LAPDm / RLL related
5920 ***********************************************************************/
5921
5922private function f_tx_lapdm(template (value) LapdmFrame l,
5923 template (value) RslLinkId link_id) runs on ConnHdlr {
5924 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005925 var template (value) SacchL1Header l1h;
5926
5927 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005928 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005929 /* Compose dummy L1 header */
5930 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5931 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 +02005932 } else {
5933 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005934 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 +01005935 }
Harald Welte0472ab42018-03-12 15:02:26 +01005936}
5937
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005938private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005939 uint3_t sapi,
5940 RslLinkId link_id,
5941 octetstring l3,
5942 boolean exp
5943}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005944private type record of RllTestCase RllTestCases;
5945private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5946 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005947 sapi := sapi,
5948 link_id := id,
5949 l3 := l3,
5950 exp := exp
5951}
5952
5953/* execute the same callback function with a set of different parameters (tcs) on a
5954 * variety of logical channels */
5955private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5956 var ConnHdlrPars pars;
5957 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005958 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005959
5960 /* test on each of the channels we have */
5961 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5962 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5963
5964 /* test each of the test cases on the current channel */
5965 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5966 pars.spec.rll := tcs[j];
5967 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5968 vc_conn := f_start_handler(fn, pars);
5969 vc_conn.done;
5970 }
5971 }
5972
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005974}
5975
5976/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5977private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5978 var RllTestCase tc := g_pars.spec.rll;
5979 timer T := 3.0;
5980
5981 f_l1_tune(L1CTL);
5982 RSL.clear;
5983
5984 /* activate the logical channel */
5985 f_est_dchan();
5986 L1CTL.clear;
5987
5988 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5989 T.start;
5990 alt {
5991 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5992 if (tc.exp) {
5993 setverdict(pass);
5994 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005995 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005996 }
5997 }
5998 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5999 if (tc.exp) {
6000 setverdict(pass);
6001 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01006003 }
6004 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006005 /* We also expect to receive the measurements */
6006 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006007 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006008 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006009 }
6010 [not tc.exp] T.timeout {
6011 setverdict(pass);
6012 }
6013 }
6014
6015 f_rsl_chan_deact();
6016 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6017 f_rslem_unregister(0, g_chan_nr);
6018}
6019testcase TC_rll_est_ind() runs on test_CT {
6020 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02006021 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01006022 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02006023 /* normal SAPI0 establishment */
6024 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01006025 /* SAPI 3 doesn't support contention resolution */
6026 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
6027 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
6028 /* normal SAPI3 establishment on main DCCH */
6029 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6030 /* normal SAPI3 establishment on SACCH */
6031 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6032 };
6033 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
6034}
6035
6036/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
6037private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
6038 var RllTestCase tc := g_pars.spec.rll;
6039 var L1ctlDlMessage dl;
6040 timer T := 3.0;
6041
6042 f_l1_tune(L1CTL);
6043 RSL.clear;
6044
6045 /* activate the logical channel */
6046 f_est_dchan();
6047 L1CTL.clear;
6048
6049 /* Send a RSL EST REQ for SAPI3 on main DCCH */
6050 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
6051 T.start;
6052 alt {
6053 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6054 var LapdmFrame lapdm;
6055 var octetstring l2 := dl.payload.data_ind.payload;
6056 if (dl.dl_info.link_id.c == SACCH) {
6057 /* remove L1 header */
6058 l2 := substr(l2, 2, lengthof(l2)-2);
6059 }
6060 lapdm.ab := dec_LapdmFrameAB(l2);
6061 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
6062 setverdict(pass);
6063 } else {
6064 repeat;
6065 }
6066 }
6067 [] L1CTL.receive { repeat; }
6068 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006069 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01006070 }
6071 }
6072
6073 f_rsl_chan_deact();
6074 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6075 f_rslem_unregister(0, g_chan_nr);
6076}
6077testcase TC_rll_est_req_DCCH_3() runs on test_CT {
6078 var RllTestCases tcs := {
6079 /* normal SAPI3 establishment on main DCCH */
6080 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
6081 };
6082 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6083}
6084testcase TC_rll_est_req_ACCH_3() runs on test_CT {
6085 var RllTestCases tcs := {
6086 /* normal SAPI3 establishment on SACCH */
6087 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6088 }
6089 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
6090}
6091
6092/* altstep to receive a LAPDm frame matching the given template */
6093private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
6094 var L1ctlDlMessage dl;
6095 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6096 var LapdmFrame lapdm;
6097 var octetstring l2 := dl.payload.data_ind.payload;
6098 if (dl.dl_info.link_id.c == SACCH) {
6099 /* remove L1 header */
6100 l2 := substr(l2, 2, lengthof(l2)-2);
6101 }
6102 if (ischosen(exp.ab)) {
6103 lapdm.ab := dec_LapdmFrameAB(l2);
6104 } else if (ischosen(exp.b4)) {
6105 lapdm.b4 := dec_LapdmFrameB4(l2);
6106 } else if (ischosen(exp.bbis)) {
6107 lapdm.bbis := dec_LapdmFrameBbis(l2);
6108 }
6109 log("Rx LAPDm ", lapdm);
6110 if (match(lapdm, exp)) {
6111 setverdict(pass);
6112 } else {
6113 repeat;
6114 }
6115 }
6116 [] L1CTL.receive { repeat; }
6117}
6118private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6119 timer T := t;
6120 T.start;
6121 alt {
6122 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006123 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006124 }
6125 [] as_l1_exp_lapdm(exp);
6126 }
6127}
6128
6129/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6130private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6131 /* send SABM from MS -> BTS */
6132 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6133 /* expect RLL EST IND on Abis */
6134 alt {
6135 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6136 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6137 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006138 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006139 }
6140 [] RSL.receive { repeat; }
6141 }
6142 /* expect UA from BTS -> MS */
6143 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6144}
6145
6146/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6147private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6148 var RllTestCase tc := g_pars.spec.rll;
6149
6150 f_l1_tune(L1CTL);
6151 RSL.clear;
6152
6153 /* activate the logical channel */
6154 f_est_dchan();
6155 L1CTL.clear;
6156
6157 /* first establish the link-layer */
6158 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6159
6160 /* then send the DISC */
6161 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6162 /* ... and expect the REL IND on the RSL side */
6163 alt {
6164 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6165 setverdict(pass);
6166 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006167 /* We also expect to receive the measurements */
6168 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006169 }
6170
6171 /* release the channel */
6172 f_rsl_chan_deact();
6173 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6174 f_rslem_unregister(0, g_chan_nr);
6175}
6176testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6177 var RllTestCases tcs := {
6178 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6179 };
6180 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6181}
6182
6183testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6184 var RllTestCases tcs := {
6185 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6186 };
6187 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6188}
6189testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6190 var RllTestCases tcs := {
6191 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6192 };
6193 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6194}
6195testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6196 var RllTestCases tcs := {
6197 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6198 };
6199 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6200}
6201
6202/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6203private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6204 var RllTestCase tc := g_pars.spec.rll;
6205 f_l1_tune(L1CTL);
6206 RSL.clear;
6207
6208 /* activate the logical channel */
6209 f_est_dchan();
6210 L1CTL.clear;
6211
6212 /* first establish the link-layer */
6213 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6214
6215 /* then send the REL REQ via RSL */
6216 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6217 /* ... and expect the DISC on the Um side */
6218 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006219 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006220 /* FIXME: send a UA in resposne to the DISC */
6221 }
6222 }
6223
6224 /* release the channel */
6225 f_rsl_chan_deact();
6226 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6227 f_rslem_unregister(0, g_chan_nr);
6228}
6229testcase TC_rll_rel_req() runs on test_CT {
6230 var RllTestCases tcs := {
6231 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6232 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6233 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6234 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6235 };
6236 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6237}
6238
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006239/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006240testcase TC_rll_data_req() runs on test_CT {
6241}
6242
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006243/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006244testcase TC_rll_data_ind() runs on test_CT {
6245}
6246
6247/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6248private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6249 var RllTestCase tc := g_pars.spec.rll;
6250
6251 f_l1_tune(L1CTL);
6252 RSL.clear;
6253
6254 f_est_dchan();
6255 L1CTL.clear;
6256
6257 /* Send UNITDATA REQ on RSL side */
6258 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6259 /* Expect it to arrive on the other side */
6260 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006261 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006262 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006263 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006264 }
6265
6266 /* release the channel */
6267 f_rsl_chan_deact();
6268 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6269 f_rslem_unregister(0, g_chan_nr);
6270}
6271testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6272 var octetstring l3 := f_rnd_octstring(15);
6273 var RllTestCases tcs := {
6274 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6275 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6276 };
6277 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6278}
6279testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6280 var octetstring l3 := f_rnd_octstring(19);
6281 var RllTestCases tcs := {
6282 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6283 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6284 };
6285 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6286}
6287
6288/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6289private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6290 var RllTestCase tc := g_pars.spec.rll;
6291
6292 f_l1_tune(L1CTL);
6293 RSL.clear;
6294
6295 f_est_dchan();
6296 L1CTL.clear;
6297
6298 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006299 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006300 /* Expdct RLL UNITDATA IND on RSL side */
6301 alt {
6302 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6303 setverdict(pass);
6304 }
6305 [] RSL.receive { repeat; }
6306 }
6307
6308 /* release the channel */
6309 f_rsl_chan_deact();
6310 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6311 f_rslem_unregister(0, g_chan_nr);
6312}
6313testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006314 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006315 var RllTestCases tcs := {
6316 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6317 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6318 };
6319 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6320}
6321testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6322 var octetstring l3 := f_rnd_octstring(18);
6323 var RllTestCases tcs := {
6324 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6325 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6326 };
6327 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6328}
6329
Harald Weltee613f962018-04-18 22:38:16 +02006330/***********************************************************************
6331 * Encryption Related
6332 ***********************************************************************/
6333
6334/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006335private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006336 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6337 if (link_id.c == SACCH) {
6338 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6339 } else {
6340 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6341 }
6342}
6343
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006344/* Expect (or not expect) other kinds of messages */
6345private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6346 [exp_any] RSL.receive { repeat; }
6347 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006348 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006349 }
6350}
6351
Harald Weltee613f962018-04-18 22:38:16 +02006352/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006353private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006354 RslLinkId link_id,
6355 octetstring l3,
6356 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006357 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006358) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006359 timer T := 3.0;
6360 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6361 T.start;
6362 /* Expect RLL UNITDATA IND on RSL side */
6363 alt {
6364 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6365 setverdict(pass);
6366 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006367 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006368 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006369 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006371 }
Harald Weltee613f962018-04-18 22:38:16 +02006372 }
6373}
6374
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006375/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6376private function f_data_mo(
6377 RslLinkId link_id,
6378 boolean p, uint3_t nr, uint3_t ns,
6379 octetstring l3,
6380 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006381 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006382) runs on ConnHdlr {
6383 timer T := 3.0;
6384 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6385 T.start;
6386 /* Expect RLL DATA IND on RSL side */
6387 alt {
6388 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6389 setverdict(pass);
6390 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006391 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006392 [] as_rsl_any_ind(exp_any);
6393 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006395 }
6396 }
6397}
6398
Harald Weltee613f962018-04-18 22:38:16 +02006399/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006400private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006401 f_l1_tune(L1CTL);
6402 f_est_dchan(true);
6403
6404 /* now we actually need to transmit some data both ways to check if the encryption works */
6405 var L1ctlDlMessage dl;
6406
Stefan Sperling603d98e2018-07-25 16:47:28 +02006407 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006408 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6409
6410 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6411 f_unitdata_mt(link_id, l3);
6412
6413 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6414 f_unitdata_mo(link_id, l3);
6415
6416 /* release the channel */
6417 f_rsl_chan_deact();
6418 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6419 f_rslem_unregister(0, g_chan_nr);
6420}
6421testcase TC_chan_act_a51() runs on test_CT {
6422 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6423 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6424 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6425}
6426testcase TC_chan_act_a52() runs on test_CT {
6427 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6428 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6429 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6430}
6431testcase TC_chan_act_a53() runs on test_CT {
6432 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6433 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6434 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6435}
6436
Eric Wildf1827a72019-05-28 17:37:35 +02006437/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6438 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 +07006439private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006440 f_l1_tune(L1CTL);
6441 f_est_dchan(true);
6442
6443 /* now we actually need to transmit some data both ways to check if the encryption works */
6444 var L1ctlDlMessage dl;
6445
6446 var octetstring l3 := f_rnd_octstring(20);
6447 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6448
6449 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6450 f_unitdata_mt(link_id, l3);
6451
6452 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6453 f_unitdata_mo(link_id, l3);
6454
6455 var RSL_Message rsl;
6456 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6457
6458 /* modify key to break proper encryption */
6459 g_pars.encr.key := f_rnd_octstring(8);
6460 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6461 rsl.ies := rsl.ies & { ei };
6462 RSL.send(rsl);
6463
6464 timer T0 := 1.0;
6465 T0.start;
6466 /* Expect RSL MODIFY ACK */
6467 alt {
6468 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6469 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6470 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6471 }
6472 [] T0.timeout {
6473 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6474 }
6475 }
6476
6477 var octetstring l3msg := f_rnd_octstring(15);
6478 timer T1 := 3.0;
6479 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6480 due to broken encryption */
6481 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6482 T1.start;
6483 alt {
6484 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6486 }
6487 [] T1.timeout {
6488 setverdict(pass);
6489 }
6490 }
6491
6492 /* release the channel */
6493 f_rsl_chan_deact();
6494 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6495 f_rslem_unregister(0, g_chan_nr);
6496}
6497testcase TC_rsl_modify_encr() runs on test_CT {
6498 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6499 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6500 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6501}
Harald Weltee613f962018-04-18 22:38:16 +02006502
6503/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006504private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006505 /* L3 payload doesn't matter, as it is passed transparently */
6506 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6507 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6508 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6509
6510 f_l1_tune(L1CTL);
6511
6512 /* first establish a dedicated channel in the clear */
6513 f_est_dchan(false);
6514
6515 /* Establish ABM */
6516 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6517
6518 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6519 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6520 /* expect the L3 to arrive still unencrypted on the MS side */
6521 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6522
6523 /* configure L1 to apply ciphering */
6524 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6525 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6526
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006527 /* send first ciphered I-frame in response and expect it on RSL */
6528 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006529
6530 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6531 * and hence enable encryption also on the downlink */
6532
6533 /* expect bi-directional communication work in encrypted mode */
6534 f_unitdata_mo(link_id, f_rnd_octstring(15));
6535 f_unitdata_mt(link_id, f_rnd_octstring(15));
6536
6537 /* release the channel */
6538 f_rsl_chan_deact();
6539 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6540 f_rslem_unregister(0, g_chan_nr);
6541}
6542testcase TC_encr_cmd_a51() runs on test_CT {
6543 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6544 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6545 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6546}
6547testcase TC_encr_cmd_a52() runs on test_CT {
6548 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6549 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6550 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6551}
6552testcase TC_encr_cmd_a53() runs on test_CT {
6553 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6554 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6555 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6556}
6557
6558private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6559 var LapdmFrame lf;
6560 var octetstring reenc;
6561
6562 /* decode the LAPDm frame */
6563 if (ischosen(exp_match.ab)) {
6564 lf.ab := dec_LapdmFrameAB(enc);
6565 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006567 }
6568
6569 /* check if decoder result matches expectation */
6570 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006572 } else {
6573 log(name, ": matched");
6574 setverdict(pass);
6575 }
6576
6577 /* test if re-encoded frame equals original input */
6578 reenc := enc_LapdmFrame(lf);
6579 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006580 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006581 } else {
6582 setverdict(pass);
6583 }
6584}
6585
6586testcase TC_lapdm_selftest() runs on test_CT {
6587 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6588 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6589 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6590 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6591 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6592 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6593 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6594}
6595
Stefan Sperling4880be42018-08-07 18:12:59 +02006596/***********************************************************************
6597 * DTX Related (see GSM 05.08, section 8.3)
6598 ***********************************************************************/
6599
6600/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006601private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006602 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6603 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6604 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6605 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6606}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006607private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006608 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6609 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6610}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006611private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006612 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6613 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6614 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6615 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6616}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006617private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006618 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6619 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6620 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6621 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6622 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6623 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6624 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6625 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6626}
6627
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006628private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006629 var L1ctlDlMessage dl;
6630 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6631 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6632 var GsmFrameNumber first_fn;
6633 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006634 var integer nfill_frames_sacch := 0;
6635 var integer nfill_frames_nonsacch := 0;
6636 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006637 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6638 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006639 const integer frame_dtx_tchf_mod := 104;
6640 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6641 * which operates in terms of blocks rather than frames. */
6642 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6643 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006644 timer T := 5.0;
6645
6646 f_l1_tune(L1CTL);
6647 RSL.clear;
6648 L1CTL.clear;
6649
6650 /* activate TCHF signalling channel */
6651 f_est_dchan(false);
6652
6653 T.start;
6654 alt {
6655 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6656 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6657 var octetstring l2 := dl.payload.data_ind.payload;
6658
6659 if (is_first_frame) {
6660 is_first_frame := false;
6661 first_fn := dl.dl_info.frame_nr;
6662 }
6663
6664 if (dl.dl_info.link_id.c == SACCH) {
6665 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6666 if (not match(l2_fill_frame_sacch, l2)) {
6667 repeat;
6668 }
6669 } else if (not match(l2_fill_frame, l2)) {
6670 repeat;
6671 }
6672
6673 if (dtxd) {
6674 if (not f_g_chan_is_tchf()) {
6675 T.stop;
6676 f_rsl_chan_deact();
6677 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006678 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received fill frame on non-TCH/F channel; DTX is only allowed on TCH/F!");
Stefan Sperling4880be42018-08-07 18:12:59 +02006679 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006680 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006681 T.stop;
6682 f_rsl_chan_deact();
6683 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006684
6685 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6686 * 2 SACCH, 1 TCH/F */
6687 expected_fill_frames := 3;
6688
6689 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6690 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6691 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006692 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006693 } else {
6694 setverdict(pass);
6695 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006696 } else {
6697 if (dl.dl_info.link_id.c == SACCH) {
6698 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006699 repeat;
6700 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006701 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6702 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6703 * we should only see the subset of frames numbers which correspond to a block boundary.
6704 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6705 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6706 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6707 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6708 repeat;
6709 }
6710 }
6711 log("Received DTX TCH fill frame with bad frame number: ", fn,
6712 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6713 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6714 f_rsl_chan_deact();
6715 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006717 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006718 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006719 if (dl.dl_info.link_id.c == SACCH) {
6720 nfill_frames_sacch := nfill_frames_sacch + 1;
6721 } else {
6722 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6723 }
6724 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006725 T.stop;
6726 if (f_g_chan_is_tchf()) {
6727 /* Without DTX we can expect 25 fill frames for every 104 frames.
6728 * (24 FACCH + 1 SACCH filling) */
6729 expected_fill_frames := 25;
6730 } else if (f_g_chan_is_tchh()) {
6731 /* We can expect 2 fill frames for every 104 frames. */
6732 expected_fill_frames := 2;
6733 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6734 /* We can expect 5 fill frames for every 104 frames. */
6735 expected_fill_frames := 5;
6736 } else {
6737 f_rsl_chan_deact();
6738 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006740 }
6741
6742 f_rsl_chan_deact();
6743 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006744
6745 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006746 setverdict(pass);
6747 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006748 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6749 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006750 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006751 }
6752 } else {
6753 repeat;
6754 }
6755 }
6756 }
6757 [] L1CTL.receive { repeat; }
6758 [] T.timeout {
6759 f_rsl_chan_deact();
6760 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006762 }
6763 }
6764}
6765
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006766private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006767 f_test_l2_fill_frames(false);
6768}
6769
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006770private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006771 f_test_l2_fill_frames(true);
6772}
6773
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006774private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006775 var ConnHdlr vc_conn;
6776 var ConnHdlrPars pars;
6777 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006778 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006779 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6780 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6781 if (dtxd) {
6782 if (i >= 4) { /* DTX is only allowed on TCH/F */
6783 break;
6784 }
6785 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6786 } else {
6787 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6788 }
6789 vc_conn.done;
6790 }
6791}
6792
6793/* Verify that L2 fill frames are sent on TCH in signaling mode if
6794 * there is nothing to transmit while DTX is disabled on downlink. */
6795testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6796 f_tch_sign_l2_fill_frame(false);
6797}
6798
6799/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6800 * there is nothing to transmit while DTX is enabled on downlink. */
6801testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6802 f_tch_sign_l2_fill_frame(true);
6803}
Harald Welte0472ab42018-03-12 15:02:26 +01006804
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006805testcase TC_chopped_ipa_ping() runs on test_CT {
6806 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6807}
6808
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006809testcase TC_chopped_ipa_payload() runs on test_CT {
6810 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6811}
6812
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07006813
6814/* Callback function to be called by as_TC_ms_pwr_ctrl_constant().
6815 * Return value: Measurement Report to be sent (encoded octetstring). */
6816type function f_TC_ms_pwr_ctrl_cb(inout SacchL1Header l1h, integer num_blocks)
6817 runs on ConnHdlr return octetstring;
6818
6819private altstep as_TC_ms_pwr_ctrl(f_TC_ms_pwr_ctrl_cb cb, inout integer num_blocks)
6820runs on ConnHdlr {
6821 var L1ctlDlMessage l1_dl;
6822 var SacchL1Header l1h;
6823 var octetstring l2;
6824
6825 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
6826 /* Parse the L1 SACCH header (MS Power Level & Timing Advance) */
6827 l1h := dec_SacchL1Header(substr(l1_dl.payload.data_ind.payload, 0, 2));
6828 log("as_TC_ms_pwr_ctrl(): Rx SACCH L1 header: ", l1h);
6829
6830 /* Pass it to the user specified call-back function */
6831 l2 := cb.apply(l1h, num_blocks);
6832 /* Send a Measurement Report generated by the call-back */
6833 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(l1_dl.dl_info.chan_nr,
6834 l1_dl.dl_info.link_id,
6835 l1h, l2));
6836
6837 /* Shall we keep going? */
6838 num_blocks := num_blocks - 1;
6839 log("as_TC_ms_pwr_ctrl(): ", num_blocks, " SACCH blocks remaining");
6840 if (num_blocks > 0) { repeat; }
6841 }
6842 [] L1CTL.receive { repeat; }
6843}
6844
6845private function f_TC_ms_pwr_ctrl_cb_def(inout SacchL1Header l1h, integer num_blocks)
6846runs on ConnHdlr return octetstring {
6847 /* Command the L1 to apply received parameters */
6848 f_L1CTL_PARAM(L1CTL, l1h.actual_ta, l1h.ms_power_lvl);
6849
6850 /* Dummy measurement report (the results are invalid) */
6851 return f_pad_oct('010349'O & '0615004001C0'O, 21, '00'O);
6852}
6853
6854private function f_TC_ms_pwr_ctrl_cb_const(inout SacchL1Header l1h, integer num_blocks)
6855runs on ConnHdlr return octetstring {
6856 if (l1h.ms_power_lvl != g_pars.l1_pars.ms_power_level) {
6857 setverdict(fail, "Unexpected MS Power level change: ",
6858 g_pars.l1_pars.ms_power_level, " -> ",
6859 l1h.ms_power_lvl);
6860 }
6861
6862 return f_TC_ms_pwr_ctrl_cb_def(l1h, num_blocks);
6863}
6864
6865/* Make sure that MS power level remains constant when 'rx-current' equals 'rx-target' */
6866private function f_TC_ms_pwr_ctrl_constant(charstring id)
6867runs on ConnHdlr {
6868 var integer num_blocks := 8;
6869 timer T := int2float(num_blocks);
6870
6871 f_l1_tune(L1CTL);
6872 RSL.clear;
6873
6874 /* These IEs are needed for autonomous MS power control */
6875 var template (value) RSL_IE_List ies := {
6876 t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{
6877 ms_power := ts_RSL_IE_MS_Power(g_pars.l1_pars.ms_power_level)
6878 }),
6879 t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{
6880 ms_power_params := ts_RSL_IE_MS_Power_Parameters(''O)
6881 })
6882 };
6883
6884 /* Ensure that 'rx-current' equals 'rx-target' */
6885 f_trxc_fake_rssi(mp_uplink_power_target);
6886
6887 /* Establish a dedicated channel */
6888 f_est_dchan(more_ies := valueof(ies));
6889
6890 L1CTL.clear;
6891 T.start;
6892 alt {
6893 [] as_TC_ms_pwr_ctrl(refers(f_TC_ms_pwr_ctrl_cb_const), num_blocks);
6894 [] T.timeout {
6895 setverdict(fail, "Not all SACCH blocks were processed in time, ",
6896 num_blocks, " were not handled");
6897 }
6898 }
6899}
6900testcase TC_ms_pwr_ctrl_constant() runs on test_CT {
6901 var ConnHdlr vc_conn;
6902 var ConnHdlrPars pars;
6903
6904 f_init();
6905
6906 /* Explicitly configure the Uplink power target (in dBm) */
6907 f_vty_config(BTSVTY, "bts 0", "uplink-power-target " & int2str(mp_uplink_power_target));
6908
6909 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i + 1) {
6910 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
6911 log(testcasename(), ": starting on ", pars.chan_nr);
6912
6913 vc_conn := f_start_handler(refers(f_TC_ms_pwr_ctrl_constant),
6914 pars, trxc_comp := true);
6915 vc_conn.done;
6916 }
6917
6918 /* No need to reset Uplink power parameters - the IUT restarts anyway */
6919 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
6920}
6921
Harald Welte0472ab42018-03-12 15:02:26 +01006922/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6923/* protocol error as per 44.006 */
6924/* link layer failure (repetition of I-frame N200 times without ACK */
6925/* repetition of SABM or DISC N200 times without ACK */
6926/* receptiom of SABM in multi-frame established state */
6927
6928
Harald Welte68e495b2018-02-25 00:05:57 +01006929/* TODO Areas:
6930
6931* channel activation
6932** with BS_Power / MS_Power, bypassing power control loop
6933** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006934** with timing advance from initial activation on
6935* mode modify
6936** encryption
6937** multirate
6938* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006939** unsupported algorithm
6940* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006941* BS Power Control
6942* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006943* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006944* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006945** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006946* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006947** DATA_IND from BTS->PCU
6948** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006949
6950*/
Harald Welte70767382018-02-21 12:16:40 +01006951
6952control {
6953 execute( TC_chan_act_stress() );
6954 execute( TC_chan_act_react() );
6955 execute( TC_chan_deact_not_active() );
6956 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006957 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006958 execute( TC_sacch_filling() );
6959 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006960 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006961 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006962 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006963 execute( TC_sacch_chan_act_ho_async() );
6964 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006965 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006966 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006967 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006968 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006969 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006970 execute( TC_rach_load_idle_thresh0() );
6971 execute( TC_rach_load_idle_below_thresh() );
6972 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006973 execute( TC_meas_res_sign_tchf() );
6974 execute( TC_meas_res_sign_tchh() );
6975 execute( TC_meas_res_sign_sdcch4() );
6976 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006977 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006978 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006979 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006980 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006981 execute( TC_rsl_bs_pwr_static_ass() );
6982 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006983 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006984 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006985 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006986 execute( TC_rsl_ms_pwr_dyn_up() );
6987 execute( TC_rsl_ms_pwr_dyn_down() );
6988 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6989 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006990 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006991 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006992 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006993 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006994 execute( TC_paging_imsi_80percent() );
6995 execute( TC_paging_tmsi_80percent() );
6996 execute( TC_paging_imsi_200percent() );
6997 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006998 execute( TC_rsl_protocol_error() );
6999 execute( TC_rsl_mand_ie_error() );
7000 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01007001 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01007002 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01007003 execute( TC_si_sched_2bis() );
7004 execute( TC_si_sched_2ter() );
7005 execute( TC_si_sched_2ter_2bis() );
7006 execute( TC_si_sched_2quater() );
7007 execute( TC_si_sched_13() );
7008 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01007009 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01007010 execute( TC_ipa_crcx_twice_not_active() );
7011 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01007012 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01007013 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01007014
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007015 if (mp_pcu_socket != "") {
7016 execute( TC_pcu_act_req() );
7017 execute( TC_pcu_act_req_wrong_ts() );
7018 execute( TC_pcu_act_req_wrong_bts() );
7019 execute( TC_pcu_act_req_wrong_trx() );
7020 execute( TC_pcu_deact_req() );
7021 execute( TC_pcu_deact_req_wrong_ts() );
7022 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02007023 if (mp_l1_supports_gprs) {
7024 execute( TC_pcu_data_req_pdtch() );
7025 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02007026 execute( TC_pcu_data_req_wrong_bts() );
7027 execute( TC_pcu_data_req_wrong_trx() );
7028 execute( TC_pcu_data_req_wrong_ts() );
7029 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02007030 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07007031 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007032 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02007033 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007034 execute( TC_pcu_data_req_imm_ass_pch() );
7035 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07007036 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07007037 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007038 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02007039 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02007040 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02007041 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02007042 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02007043 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02007044 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02007045 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007046 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007047 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007048 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02007049 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07007050 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02007051 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01007052 execute( TC_dyn_osmo_pdch_act_deact() );
7053 execute( TC_dyn_osmo_pdch_double_act() );
7054 execute( TC_dyn_ipa_pdch_act_deact() );
7055 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
7056
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007057 if (PCUIF_Types.mp_pcuif_version >= 10) {
7058 execute( TC_pcu_info_ind_fh_params() );
Alexander Couzens5283f552020-07-28 15:39:04 +02007059 execute( TC_pcu_socket_nsvc_ipv4() );
7060 execute( TC_pcu_socket_nsvc_ipv6() );
Vadim Yanitskiy7faef072020-08-03 04:22:04 +07007061 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01007062 } else {
7063 log("PCU socket path not available, skipping PCU tests");
7064 }
Harald Welte3d04ae62018-04-04 20:29:05 +02007065
Harald Welte3d04ae62018-04-04 20:29:05 +02007066 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02007067 execute( TC_dyn_osmo_pdch_tchf_act() );
7068 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02007069 execute( TC_dyn_ipa_pdch_tchf_act() );
7070 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01007071
7072 execute( TC_rll_est_ind() );
7073 execute( TC_rll_est_req_DCCH_3() );
7074 execute( TC_rll_est_req_ACCH_3() );
7075 execute( TC_rll_rel_ind_DCCH_0() );
7076 execute( TC_rll_rel_ind_DCCH_3() );
7077 execute( TC_rll_rel_ind_ACCH_0() );
7078 execute( TC_rll_rel_ind_ACCH_3() );
7079 execute( TC_rll_rel_req() );
7080 execute( TC_rll_unit_data_req_DCCH() );
7081 execute( TC_rll_unit_data_req_ACCH() );
7082 execute( TC_rll_unit_data_ind_DCCH() );
7083 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02007084
7085 execute( TC_chan_act_a51() );
7086 execute( TC_chan_act_a52() );
7087 execute( TC_chan_act_a53() );
7088 execute( TC_encr_cmd_a51() );
7089 execute( TC_encr_cmd_a52() );
7090 execute( TC_encr_cmd_a53() );
7091
Harald Welteee25aae2019-05-19 14:32:37 +02007092 execute( TC_err_rep_wrong_mdisc() );
7093 execute( TC_err_rep_wrong_msg_type() );
7094 execute( TC_err_rep_wrong_sequence() );
7095
Harald Weltee613f962018-04-18 22:38:16 +02007096 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02007097
7098 execute( TC_tch_sign_l2_fill_frame() );
7099 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02007100
7101 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007102 execute( TC_chopped_ipa_payload() );
Vadim Yanitskiyc7ef0302020-10-18 19:24:18 +07007103
7104 execute( TC_ms_pwr_ctrl_constant() );
Harald Welte70767382018-02-21 12:16:40 +01007105}
7106
7107
7108}