blob: 1c8127bd4d2360619fe9f3f9704e6a1bdd2edd3d [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;
Harald Welte70767382018-02-21 12:16:40 +010038import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020039import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010040
41import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010042import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010043import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020044import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010045import from RSL_Emulation all;
46
47import from IPL4asp_Types all;
48import from TRXC_Types all;
49import from TRXC_CodecPort all;
50import from TRXC_CodecPort_CtrlFunct all;
51
Harald Welte883340c2018-02-28 18:59:29 +010052import from PCUIF_Types all;
53import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020054import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010055
Harald Welte7484fc42018-02-24 14:09:45 +010056import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010057import from MobileL3_RRM_Types all;
58import from MobileL3_Types all;
59import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020060import from L3_Common all;
61import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010062
Harald Welte8da48242018-02-27 20:41:32 +010063import from Osmocom_VTY_Functions all;
64import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020065import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010066
Harald Welte505cf9b2018-09-15 17:47:23 +030067friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020068friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020069friend module BTS_Tests_LAPDm;
Pau Espin Pedrol5a012ee2020-02-06 19:33:22 +010070friend module BTS_Tests_perf;
Harald Welte505cf9b2018-09-15 17:47:23 +030071
Harald Welte70767382018-02-21 12:16:40 +010072/* The tests assume a BTS with the following timeslot configuration:
73 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020074 * TS1 : TCH/F
75 * TS2 : TCH/F
76 * TS3 : TCH/F_PDCH (IPA Style)
77 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010078 * TS5 : TCH/H
79 * TS6 : SDCCH/8
80 * TS7 : PDCH
81 */
82
83modulepar {
84 charstring mp_rsl_ip := "127.0.0.2";
85 integer mp_rsl_port := 3003;
86 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +070087 integer mp_trx1_arfcn := 873;
88 integer mp_trx2_arfcn := 875;
89 integer mp_trx3_arfcn := 877;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070090 charstring mp_bts_trxc_ip := "127.0.0.1";
91 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010092 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020093 charstring mp_ctrl_ip := "127.0.0.1";
94 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020095 charstring mp_bsc_ctrl_ip := "127.0.0.1";
96 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020097 integer mp_tolerance_rxqual := 1;
98 integer mp_tolerance_rxlev := 3;
99 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200100 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200101 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200102 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +0200103 integer mp_bts_tx_nom_pwr_exp := 50; /* Expected Tx Nominal Output Power of the BTS, in dBm */
104 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 +0200105 integer mp_ms_actual_ta_exp := 0;
106 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100107 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200108 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200109 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200110 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
111 boolean mp_l1_supports_gprs := false;
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700112 /* how many transceivers do we expect to connect */
113 integer mp_transceiver_num := 1;
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700114 /* frequency hopping status */
115 boolean mp_freq_hop_enabled := false;
116 /* frequency hopping parameters */
117 FreqHopConfig mp_fh_config;
Harald Welte70767382018-02-21 12:16:40 +0100118}
119
Harald Welte629cc6b2018-03-11 17:19:05 +0100120type record of RslChannelNr ChannelNrs;
121
Harald Welte70767382018-02-21 12:16:40 +0100122type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100123 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100124 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100125 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100126 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100127 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100128 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100129
130 /* L1CTL port (for classic tests) */
131 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100132
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700133 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700134 port TRXC_CODEC_PT BTS_TRXC;
135 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100136
Harald Weltef50e3ae2018-09-10 10:27:56 +0200137 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100138 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200139 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100140
Harald Welte883340c2018-02-28 18:59:29 +0100141 /* PCU Interface of BTS */
142 port PCUIF_CODEC_PT PCU;
143 var integer g_pcu_conn_id;
144 /* Last PCU INFO IND we received */
145 var PCUIF_Message g_pcu_last_info;
146
Harald Welte48494ca2018-02-25 16:59:50 +0100147 /* SI configuration */
148 var SystemInformationConfig si_cfg := {
149 bcch_extended := false,
150 si1_present := false,
151 si2bis_present := false,
152 si2ter_present := false,
153 si2quater_present := false,
154 si7_present := false,
155 si8_present := false,
156 si9_present := false,
157 si13_present := false,
158 si13alt_present := false,
159 si15_present := false,
160 si16_present := false,
161 si17_present := false,
162 si2n_present := false,
163 si21_present := false,
164 si22_present := false
165 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100166
167 /* all logical channels available on the BTS */
168 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100169 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100170}
171
172/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200173type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100174 port L1CTL_PT L1CTL;
175
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700176 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700177 port TRXC_CODEC_PT BTS_TRXC;
178 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100179
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200180 /* port to be initialized optionally to access BSC VTY */
181 port TELNETasp_PT BSCVTY;
182
Harald Welte70767382018-02-21 12:16:40 +0100183 timer g_Tguard;
184 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
185
186 var ConnHdlrPars g_pars;
187 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100188 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200189
190 /* PCU Interface of BTS */
191 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100192}
193
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700194private function f_init_rsl(charstring id) runs on test_CT {
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700195 var bitstring trx_mask := '00000000'B;
196 var integer trx_count := 0;
197 var RSLEm_Event ev;
198 timer T;
199
Harald Welte70767382018-02-21 12:16:40 +0100200 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
201 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
202
203 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
204 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
205 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
206
207 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
208 vc_RSL.start(RSL_Emulation.main(false));
Vadim Yanitskiyc9c9e292020-05-18 23:31:40 +0700209
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700210 /* We expect (N = mp_transceiver_num) IPA/RSL transceiver connections here.
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700211 * See https://gerrit.osmocom.org/q/Ib5ad31388ae25399ad09739aac3fdcb0b3a1f78b. */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700212 T.start(mp_ipa_up_timeout);
213 alt {
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700214 /* These events are sent by the RSL_Emulation_CT */
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700215 [] RSL_CCHAN.receive(tr_RSLEm_EV(RSLEM_EV_TRX_UP, ?)) -> value ev {
216 /* Make sure that all transceivers use unique stream ID */
217 if (trx_mask[enum2int(ev.sid)] == '1'B) {
218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
219 log2str("Duplicate RSL stream ID (", ev.sid, ")"));
220 }
Vadim Yanitskiyfc631d12020-06-02 23:48:49 +0700221
Vadim Yanitskiy89db3e02020-06-22 17:49:39 +0700222 /* This message (RF RESource INDication) is sent by the IUT itself */
223 RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RF_RES_IND, ev.sid));
224 trx_mask[enum2int(ev.sid)] := '1'B;
225 trx_count := trx_count + 1;
226
227 log(trx_count, "/", mp_transceiver_num, " transceiver(s) connected");
228 if (trx_count < mp_transceiver_num) { repeat; }
229 }
230 /* osmo-bts may send us CCCH LOAD INDication or whatever else */
231 [] RSL_CCHAN.receive(ASP_RSL_Unitdata:?) { repeat; }
232 [] T.timeout {
233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
234 "Timeout waiting for RSL bring up");
235 }
236 }
Harald Welte70767382018-02-21 12:16:40 +0100237}
238
239type record ConnHdlrPars {
240 RslChannelNr chan_nr,
241 RSL_IE_ChannelMode chan_mode,
242 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100243 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200244 TestSpecUnion spec optional,
Eric Wild61edb7e2019-06-03 12:38:31 +0200245 RSL_IE_EncryptionInfo encr optional,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700246 BtsBand bts0_band optional,
247
248 /* Frequency hopping parameters (disabled if absent) */
249 MaioHsn maio_hsn optional,
250 /* MA bitmap to be indicated in RR Immediate Assignment */
251 MobileAllocation ma_map,
252 /* The actual Mobile Allocation (ARFCN list) to be used */
253 L1ctlMA ma
Harald Welte0472ab42018-03-12 15:02:26 +0100254}
255
256/* Test-specific parameters */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700257private type union TestSpecUnion {
Harald Welte0472ab42018-03-12 15:02:26 +0100258 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100259}
260
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700261private template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100262 max_retrans := RACH_MAX_RETRANS_7,
263 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100264 cell_barr_access := false,
265 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100266 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100267};
268
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700269private template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100270 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200271 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100272 acs := '0'B,
273 neci := true,
274 rxlev_access_min := 0
275}
276
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700277private template (value) LocationAreaIdentification ts_LAI_default := {
Harald Weltef10153f2018-02-25 16:34:05 +0100278 mcc_mnc := '262F42'H,
279 lac := 42
280}
281
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700282private template (value) GPRSIndicator ts_GPRSIndicator_def := {
283 ra_colour := 0,
284 si13_pos := '0'B
285}
286
287private template (value) SI3RestOctets ts_SI3RestOctets_def
288modifies ts_SI3RestOctets := {
289 gprs_ind := {
290 presence := CSN1_H,
291 ind := ts_GPRSIndicator_def
292 }
293}
294
295private template (value) SI4RestOctets ts_SI4RestOctets_def
296modifies ts_SI4RestOctets := {
297 gprs_ind := {
Vadim Yanitskiyab5363f2020-05-05 00:30:22 +0700298 presence := CSN1_H,
299 ind := ts_GPRSIndicator_def
Vadim Yanitskiy12cf3d92020-05-05 00:19:50 +0700300 }
301}
302
Harald Welte7484fc42018-02-24 14:09:45 +0100303/* Default SYSTEM INFORMATION 3 */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700304private template (value) SystemInformation ts_SI3_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100305 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100306 payload := {
307 si3 := {
308 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100309 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100310 ctrl_chan_desc := {
311 msc_r99 := true,
312 att := true,
313 bs_ag_blks_res := 1,
314 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100315 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100316 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
317 spare := '00'B,
318 bs_pa_mfrms := 0, /* 2 multiframes */
319 t3212 := 1 /* 6 minutes */
320 },
Harald Welte82ccef72018-02-25 16:17:33 +0100321 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100322 dn_ind := false,
323 pwrc := false,
324 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100325 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100326 },
Harald Weltef10153f2018-02-25 16:34:05 +0100327 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100328 rach_control := ts_RachCtrl_default,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200329 rest_octets := valueof(ts_SI3RestOctets_def)
Harald Welte7484fc42018-02-24 14:09:45 +0100330 }
331 }
332}
Harald Welte70767382018-02-21 12:16:40 +0100333
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700334private template (value) SystemInformation ts_SI2_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100335 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100336 payload := {
337 si2 := {
338 bcch_freq_list := '00000000000000000000000000000000'O,
339 ncc_permitted := '11111111'B,
340 rach_control := ts_RachCtrl_default
341 }
342 }
343}
344
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700345private template (value) SystemInformation ts_SI4_default := {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100346 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100347 payload := {
348 si4 := {
349 lai := ts_LAI_default,
350 cell_sel_par := ts_CellSelPar_default,
351 rach_control := ts_RachCtrl_default,
352 cbch_chan_desc := omit,
353 cbch_mobile_alloc := omit,
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +0200354 rest_octets := valueof(ts_SI4RestOctets_def)
Harald Weltef10153f2018-02-25 16:34:05 +0100355 }
356 }
357}
358
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700359private function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
Harald Weltef10153f2018-02-25 16:34:05 +0100360runs on test_CT {
361 log("Setting ", rsl_si_type, ": ", si_enc);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +0700362 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
Harald Weltef10153f2018-02-25 16:34:05 +0100363}
364
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700365private function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
Harald Weltef10153f2018-02-25 16:34:05 +0100366runs on test_CT {
367 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
368 log("Setting ", rsl_si_type, ": ", si_dec);
369 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
370}
371
Harald Welte505cf9b2018-09-15 17:47:23 +0300372friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100373 map(self:BTSVTY, system:BTSVTY);
374 f_vty_set_prompts(BTSVTY);
375 f_vty_transceive(BTSVTY, "enable");
376}
377
Harald Welte505cf9b2018-09-15 17:47:23 +0300378friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200379 map(self:BSCVTY, system:BSCVTY);
380 f_vty_set_prompts(BSCVTY, "OsmoBSC");
381 f_vty_transceive(BSCVTY, "enable");
382}
383
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +0200384friend function f_connhdlr_init_vty_bsc() runs on ConnHdlr {
385 map(self:BSCVTY, system:BSCVTY);
386 f_vty_set_prompts(BSCVTY, "OsmoBSC");
387 f_vty_transceive(BSCVTY, "enable");
388}
389
Harald Welte883340c2018-02-28 18:59:29 +0100390/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200391private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
392 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100393 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200394 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
395 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100396 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200397 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100399 }
400}
401
Harald Weltef26de0b2018-04-04 20:28:05 +0200402private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
403 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100404 timer T := 2.0;
405 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100406 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200407 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100408 return;
409 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200410 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100411
412 T.start;
413 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200414 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100415 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100417 }
418 }
419}
420
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700421private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
422 out integer trxc_conn_id) {
423 var Result res;
424
425 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
426 "", -1, -1, { udp := {} }, {});
427 if (not ispresent(res.connId)) {
428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
429 "Could not connect to the control (TRXC) interface " &
430 "of FakeTRX, check your configuration");
431 }
432 trxc_conn_id := res.connId;
433}
434
Harald Welte70767382018-02-21 12:16:40 +0100435/* global init function */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700436friend function f_init() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +0200437 var charstring id := testcasename();
Harald Welte629cc6b2018-03-11 17:19:05 +0100438 g_AllChannels := {
439 /* TS 1..4: TCH/F */
440 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
441 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
442 /* TS 5: TCH/H */
443 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
444 /* TS 0: SDCCH/4 */
445 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
446 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
447 /* TS 6: SDCCH/8 */
448 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
449 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
450 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
451 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
452 };
453
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200454 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700455 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200456 g_AllChanTypes := {
457 /* TS 1..4: TCH/F */
458 valueof(ts_RslChanNr_Bm(1)),
459 /* TS 5: TCH/H */
460 valueof(ts_RslChanNr_Lm(5,1)),
461 /* TS 0: SDCCH/4 */
462 valueof(ts_RslChanNr_SDCCH4(0,2)),
463 /* TS 6: SDCCH/8 */
464 valueof(ts_RslChanNr_SDCCH8(6,4))
465 };
466 } else {
467 g_AllChanTypes := {
468 /* TS 1..4: TCH/F */
469 valueof(ts_RslChanNr_Bm(1)),
470 /* TS 0: SDCCH/4 */
471 valueof(ts_RslChanNr_SDCCH4(0,2)),
472 /* TS 6: SDCCH/8 */
473 valueof(ts_RslChanNr_SDCCH8(6,4))
474 };
475 }
Harald Welte70767382018-02-21 12:16:40 +0100476 f_init_rsl(id);
Harald Welte2d142592018-02-25 13:19:44 +0100477 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100478 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200479 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100480
481 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100482 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
483 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
484 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
485 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100486
Harald Weltef26de0b2018-04-04 20:28:05 +0200487 map(self:PCU, system:PCU);
488 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100489
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700490 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100491 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700492
493 /* Init TRXC interface to FakeTRX */
494 map(self:BTS_TRXC, system:BTS_TRXC);
495 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
496
Vadim Yanitskiy10d72462019-06-04 22:27:52 +0700497 /* Start with a default moderate timing offset equalling TA=2, and RSSI=-60 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700498 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 +0700499 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(-60)));
Vadim Yanitskiyde535e02019-07-26 16:29:27 +0700500 /* OsmoBTS may have different AB / NB threshold (see MIN_QUAL_NORM, MIN_QUAL_RACH) */
501 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_CI(60)));
Harald Welte84271622018-03-10 17:21:03 +0100502 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200503
504 /* Wait some extra time to make sure the BTS emits a stable carrier.
505 * (this is only relevant when running the tests with a physical BTS.) */
506 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100507}
508
Harald Welte68e495b2018-02-25 00:05:57 +0100509/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700510friend function f_init_l1ctl() runs on test_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100511 map(self:L1CTL, system:L1CTL);
512 f_connect_reset(L1CTL);
513}
514
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700515private type function void_fn(charstring id) runs on ConnHdlr;
Harald Welte70767382018-02-21 12:16:40 +0100516
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700517private type record length(8) of FreqHopGroups FreqHopConfig;
518
519private type record of FreqHopGroup FreqHopGroups;
520private type record FreqHopGroup {
521 uint6_t hsn,
522 FreqHopGroupItems trx_maio
523};
524
525private type record of FreqHopGroupItem FreqHopGroupItems;
526private type record FreqHopGroupItem {
527 uint8_t trx_nr,
528 uint6_t maio
529};
530
531friend function f_resolve_fh_params(inout ConnHdlrPars pars, uint8_t trx_nr := 0)
532{
533 var FreqHopGroups groups := mp_fh_config[pars.chan_nr.tn];
534 var integer i, j;
535
536 for (i := 0; i < lengthof(groups); i := i + 1) {
537 var FreqHopGroup g := groups[i];
538 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
539 var FreqHopGroupItem gi := g.trx_maio[j];
540 if (gi.trx_nr == trx_nr) {
541 pars.maio_hsn := valueof(ts_HsnMaio(g.hsn, gi.maio));
542 pars.ma := { }; /* to be composed below */
543 break;
544 }
545 }
546
547 if (ispresent(pars.maio_hsn)) {
548 /* Compose the Mobile Allocation */
549 for (j := 0; j < lengthof(g.trx_maio); j := j + 1) {
550 var FreqHopGroupItem gi := g.trx_maio[j];
551 pars.ma := pars.ma & { l1ctl_ma_def[gi.trx_nr] };
552 }
553
554 log("Freq. hopping parameters: ", pars.maio_hsn, pars.ma);
555 break; /* We're done */
556 }
557 }
558}
559
Harald Welte70767382018-02-21 12:16:40 +0100560/* create a new test component */
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700561friend function f_start_handler(void_fn fn, ConnHdlrPars pars,
562 boolean pcu_comp := false,
563 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100564runs on test_CT return ConnHdlr {
565 var charstring id := testcasename();
566 var ConnHdlr vc_conn;
567
568 vc_conn := ConnHdlr.create(id);
569 /* connect to RSL Emulation main component */
570 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
571 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700572
573 /* The ConnHdlr component may want to talk to some ports directly,
574 * so we disconnect it from the test_CT and connect it to the component.
575 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200576 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200577 unmap(self:PCU, system:PCU);
578 map(vc_conn:PCU, system:PCU);
579 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700580 if (trxc_comp) {
581 unmap(self:BTS_TRXC, system:BTS_TRXC);
582 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
583 }
Harald Welte70767382018-02-21 12:16:40 +0100584
Vadim Yanitskiya9894282020-07-14 01:56:15 +0700585 /* Obtain frequency hopping parameters for a given timeslot */
586 if (mp_freq_hop_enabled and mp_transceiver_num > 1) {
587 f_resolve_fh_params(pars);
588 }
589
Harald Welte70767382018-02-21 12:16:40 +0100590 vc_conn.start(f_handler_init(fn, id, pars));
591 return vc_conn;
592}
593
Harald Welte70767382018-02-21 12:16:40 +0100594private altstep as_Tguard() runs on ConnHdlr {
595 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200596 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100597 }
598}
599
Harald Welte990a3612019-05-27 14:02:13 +0200600friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
601 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100602}
603
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700604private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100605 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700606 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100607}
608
Vadim Yanitskiydc8db922019-06-04 21:58:15 +0700609private function f_trxc_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100610 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700611 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100612}
613
614/* first function started in ConnHdlr component */
615private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
616runs on ConnHdlr {
617 g_pars := pars;
618 g_chan_nr := pars.chan_nr;
619
620 map(self:L1CTL, system:L1CTL);
621 f_connect_reset(L1CTL);
622
Harald Welted48c0c72019-06-05 10:01:15 +0200623 if (mp_bts_trxc_port != -1 and BTS_TRXC.checkstate("Mapped")) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700624 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100625 }
Harald Welte70767382018-02-21 12:16:40 +0100626
627 g_Tguard.start(pars.t_guard);
628 activate(as_Tguard());
629
630 f_rslem_register(0, pars.chan_nr);
631
632 /* call the user-supplied test case function */
633 fn.apply(id);
634}
635
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +0700636private function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx,
637 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200638runs on ConnHdlr return RSL_Message {
639 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100640 timer T := 3.0;
641 RSL.send(tx);
642 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100643 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200644 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100645 T.stop;
646 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100647 }
Harald Welte1eba3742018-02-25 12:48:14 +0100648 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100650 }
Harald Welte21240e62018-03-11 21:43:35 +0100651 [not ignore_other] as_l1_sacch();
652 [not ignore_other] as_meas_res();
653 [not ignore_other] as_l1_dcch();
654 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200655 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100656 }
Harald Welte21240e62018-03-11 21:43:35 +0100657 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100658 }
Harald Welteb1726c92018-03-30 11:56:38 +0200659 return rx;
660}
661
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700662friend function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx,
663 charstring id, boolean ignore_other := false)
Harald Welteb1726c92018-03-30 11:56:38 +0200664runs on ConnHdlr {
665 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100666}
667
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700668friend function f_rsl_chan_act(RSL_IE_ChannelMode mode,
669 boolean encr_enable := false,
670 RSL_IE_List more_ies := {},
671 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA)
672runs on ConnHdlr {
Harald Welte8b01c792019-05-19 22:51:25 +0200673 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200674 if (encr_enable) {
675 /* append encryption related IEs, if requested */
676 var RSL_IE_EncryptionInfo encr_info;
677 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
678 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
679encr_info})) };
680 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200681 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200682 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100683}
684
Vadim Yanitskiyb2a90db2020-07-04 20:33:47 +0700685friend function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100686 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 +0100687 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100688}
689
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700690/* Default Mobile Allocation to be used for frequency hopping */
691private const L1ctlMA l1ctl_ma_def := { { false, mp_trx0_arfcn }, { false, mp_trx1_arfcn },
692 { false, mp_trx2_arfcn }, { false, mp_trx3_arfcn } };
693
Harald Welte2f2b2b72019-05-31 22:24:57 +0200694friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100695 template RSL_IE_ChannelMode chan_mode,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700696 template (omit) MaioHsn maio_hsn := omit,
Harald Welte70767382018-02-21 12:16:40 +0100697 float t_guard := 20.0) := {
698 chan_nr := valueof(chan_nr),
699 chan_mode := valueof(chan_mode),
700 t_guard := t_guard,
701 l1_pars := {
702 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100703 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100704 meas_ul := {
705 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200706 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100707 rxqual := 0
708 },
709 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200710 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100711 rxqual := 0
712 }
713 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200714 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100715 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200716 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200717 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100718 },
Harald Weltee613f962018-04-18 22:38:16 +0200719 spec := omit,
Eric Wild61edb7e2019-06-03 12:38:31 +0200720 encr := omit,
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +0700721 bts0_band := omit,
722 maio_hsn := maio_hsn,
723 ma_map := c_MA_null,
724 ma := l1ctl_ma_def
Harald Welte70767382018-02-21 12:16:40 +0100725}
726
Harald Welte93640c62018-02-25 16:59:33 +0100727/***********************************************************************
728 * Channel Activation / Deactivation
729 ***********************************************************************/
730
Harald Welte70767382018-02-21 12:16:40 +0100731/* Stress test: Do 500 channel activations/deactivations in rapid succession */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700732private function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100733 for (var integer i := 0; i < 500; i := i+1) {
734 f_rsl_chan_act(g_pars.chan_mode);
735 f_rsl_chan_deact();
736 }
737 setverdict(pass);
738}
739testcase TC_chan_act_stress() runs on test_CT {
740 var ConnHdlr vc_conn;
741 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200742 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100743 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
744 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200745 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100746}
747
748/* Test if re-activation of an already active channel fails as expected */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700749private function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100750 f_rsl_chan_act(g_pars.chan_mode);
751 /* attempt to activate the same lchan again -> expect reject */
752 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
753 alt {
754 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200755 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100756 }
757 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
758 setverdict(pass);
759 }
760 }
761 f_rsl_chan_deact();
762}
763testcase TC_chan_act_react() runs on test_CT {
764 var ConnHdlr vc_conn;
765 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100766 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100767 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
768 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200769 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100770}
771
772/* Attempt to de-activate a channel that's not active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700773private function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100774 timer T := 3.0;
775 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
776 T.start;
777 alt {
778 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
779 setverdict(pass);
780 }
781 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100783 }
784 }
785}
786testcase TC_chan_deact_not_active() runs on test_CT {
787 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100788 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100789 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
790 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200791 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100792}
793
794/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +0700795private function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +0100796 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
797 alt {
798 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200799 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100800 }
801 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
802 setverdict(pass);
803 }
804 }
805}
806private type record WrongChanNrCase {
807 RslChannelNr chan_nr,
808 charstring description
809}
810private type record of WrongChanNrCase WrongChanNrCases;
811private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
812 chan_nr := chan_nr,
813 description := desc
814}
815
816testcase TC_chan_act_wrong_nr() runs on test_CT {
817 var ConnHdlr vc_conn;
818 var ConnHdlrPars pars;
819
Harald Welte294b0a22018-03-10 23:26:48 +0100820 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100821
822 var WrongChanNrCases wrong := {
823 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
824 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
825 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
826 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
827 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
828 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
829 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
830 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
831 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
832 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
833 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
834 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
835 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
836 };
837
838 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
839 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
840 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
841 vc_conn.done;
842 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200843 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100844}
845
Harald Weltee613f962018-04-18 22:38:16 +0200846/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200847friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200848 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200849 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200850
851 /* test on each of the channels we have */
852 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
853 pars.chan_nr := valueof(g_AllChanTypes[i]);
854
855 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
856 vc_conn := f_start_handler(fn, pars);
857 vc_conn.done;
858 }
859
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200861}
862
Harald Welte93640c62018-02-25 16:59:33 +0100863/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100864 * SACCH handling
865 ***********************************************************************/
866
867private function f_exp_sacch(boolean exp) runs on ConnHdlr {
868 timer T_sacch := 3.0;
869 T_sacch.start;
870 alt {
871 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200872 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100873 }
874 [not exp] T_sacch.timeout {
875 setverdict(pass);
876 }
877 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
878 setverdict(pass);
879 }
880 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200881 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100882 }
883 [] L1CTL.receive { repeat; }
884 [] RSL.receive { repeat; }
885 }
886}
887
888/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
889private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
890 f_l1_tune(L1CTL);
891 RSL.clear;
892
893 /* activate the logical channel */
894 f_est_dchan();
895 L1CTL.clear;
896
897 /* check that SACCH actually are received as expected */
898 f_exp_sacch(true);
899
900 /* deactivate SACCH on the logical channel */
901 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
902 f_sleep(1.0);
903 L1CTL.clear;
904
905 /* check that no SACCH are received anymore */
906 f_exp_sacch(false);
907
908 /* release the channel */
909 f_rsl_chan_deact();
910 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
911}
912testcase TC_deact_sacch() runs on test_CT {
913 var ConnHdlr vc_conn;
914 var ConnHdlrPars pars;
915 f_init();
916 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
917 //for (var integer i := 0; i < 1; i := i+1) {
918 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
919 log(testcasename(), ": Starting for ", g_AllChannels[i]);
920 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
921 vc_conn.done;
922 }
923 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200924 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100925}
926
Harald Welte55700662018-03-12 13:15:43 +0100927/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100928private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
929 var L1ctlDlMessage dl;
930 /* check that the specified SI5 value is actually sent */
931 timer T_sacch := 3.0;
932 L1CTL.clear;
933 T_sacch.start;
934 alt {
935 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
936 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
937 if (match(l3, l3_exp)) {
938 setverdict(pass);
939 } else {
940 repeat;
941 }
942 }
943 [] L1CTL.receive { repeat; }
944 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200945 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100946 }
947 }
948}
949
Harald Welte55700662018-03-12 13:15:43 +0100950/* verify that given SACCH payload is not present */
951private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
952 var L1ctlDlMessage dl;
953 /* check that the specified SI5 value is actually sent */
954 timer T_sacch := 3.0;
955 L1CTL.clear;
956 T_sacch.start;
957 alt {
958 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
959 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
960 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200961 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100962 } else {
963 repeat;
964 }
965 }
966 [] L1CTL.receive { repeat; }
967 [] T_sacch.timeout {
968 setverdict(pass);
969 }
970 }
971}
972
Harald Welte629cc6b2018-03-11 17:19:05 +0100973/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100974private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
975 /* Set a known default SACCH filling for SI5 */
976 var octetstring si5 := f_rnd_octstring(19);
977 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
978
979 f_l1_tune(L1CTL);
980 RSL.clear;
981
982 /* activate the logical channel */
983 f_est_dchan();
984
985 /* check that the specified SI5 value is actually sent */
986 f_sacch_present(si5);
987
988 /* release the channel */
989 RSL.clear;
990 f_rsl_chan_deact();
991 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
992}
993testcase TC_sacch_filling() runs on test_CT {
994 var ConnHdlr vc_conn;
995 var ConnHdlrPars pars;
996 f_init();
997 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
998 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
999 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1000 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
1001 vc_conn.done;
1002 }
1003 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001004 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001005}
1006
Harald Welte629cc6b2018-03-11 17:19:05 +01001007/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +01001008private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
1009 /* Set a known default SACCH filling for SI5 */
1010 var octetstring si5 := f_rnd_octstring(19);
1011 var octetstring si5_diff := f_rnd_octstring(19);
1012 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1013
1014 f_l1_tune(L1CTL);
1015 RSL.clear;
1016
1017 log("Activating channel, expecting standard SI5");
1018 /* activate the logical channel */
1019 f_est_dchan();
1020 /* check that the specified SI5 value is actually sent */
1021 f_sacch_present(si5);
1022
1023 /* set channel-specific different SI5 */
1024 log("Setting channel specific SACCH INFO, expecting it");
1025 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
1026 /* check that the specified lchan-specific value is now used */
1027 f_sacch_present(si5_diff);
1028
1029 /* deactivate the channel and re-activate it, this should result in default SI5 */
1030 log("De-activating and re-activating channel, expecting standard SI5");
1031 f_rsl_chan_deact();
1032 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
1033 /* Verify that the TRX-wide default SACCH filling is present again */
1034 f_sacch_present(si5);
1035
1036 /* release the channel */
1037 RSL.clear;
1038 f_rsl_chan_deact();
1039 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1040}
1041testcase TC_sacch_info_mod() runs on test_CT {
1042 var ConnHdlr vc_conn;
1043 var ConnHdlrPars pars;
1044 f_init();
1045 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1046 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1047 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1048 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
1049 vc_conn.done;
1050 }
1051 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001052 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +01001053}
1054
Harald Welte075d84c2018-03-12 13:07:24 +01001055/* Test SACCH scheduling of multiple different SI message types */
1056private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
1057 var octetstring si5 := f_rnd_octstring(19);
1058 var octetstring si5bis := f_rnd_octstring(19);
1059 var octetstring si5ter := f_rnd_octstring(19);
1060 var octetstring si6 := f_rnd_octstring(19);
1061
1062 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1063 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
1064 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
1065 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1066
1067 f_l1_tune(L1CTL);
1068 RSL.clear;
1069
1070 /* activate the logical channel */
1071 f_est_dchan();
1072 L1CTL.clear;
1073
1074 /* check that SACCH actually are received as expected */
1075 f_sacch_present(si5);
1076 f_sacch_present(si5bis);
1077 f_sacch_present(si5ter);
1078 f_sacch_present(si6);
1079
1080 /* release the channel */
1081 f_rsl_chan_deact();
1082 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1083}
1084testcase TC_sacch_multi() runs on test_CT {
1085 var ConnHdlr vc_conn;
1086 var ConnHdlrPars pars;
1087 f_init();
1088 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1089 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1090 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1091 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
1092 vc_conn.done;
1093 }
1094 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001095 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +01001096}
1097
Harald Welte55700662018-03-12 13:15:43 +01001098/* Test if SACH information is modified as expected */
1099private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
1100 var octetstring si5 := f_rnd_octstring(19);
1101 var octetstring si6 := f_rnd_octstring(19);
1102
1103 /* First, configure both SI5 and SI6 to be transmitted */
1104 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1105 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1106
1107 f_l1_tune(L1CTL);
1108 RSL.clear;
1109
1110 /* activate the logical channel */
1111 f_est_dchan();
1112 L1CTL.clear;
1113
1114 /* check that SACCH actually are received as expected */
1115 f_sacch_present(si5);
1116 f_sacch_present(si6);
1117
1118 /* disable SI6 */
1119 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
1120
1121 /* check that SI5 is still transmitted */
1122 f_sacch_present(si5);
1123 /* check if SI6 is now gone */
1124 f_sacch_missing(si6);
1125
1126 /* release the channel */
1127 f_rsl_chan_deact();
1128 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1129}
1130testcase TC_sacch_multi_chg() runs on test_CT {
1131 var ConnHdlr vc_conn;
1132 var ConnHdlrPars pars;
1133 f_init();
1134 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1135 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1136 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1137 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1138 vc_conn.done;
1139 }
1140 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001141 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001142}
1143
Harald Weltec8d363c2019-05-19 20:36:48 +02001144/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1145private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1146 var octetstring si5 := f_rnd_octstring(19);
1147 var octetstring si6 := f_rnd_octstring(19);
1148 var octetstring si5_specific := f_rnd_octstring(19);
1149 var octetstring si6_specific := f_rnd_octstring(19);
1150
1151 /* First, configure both SI5 and SI6 to be transmitted */
1152 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1153 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1154
1155 f_l1_tune(L1CTL);
1156 RSL.clear;
1157
1158 /* activate channel with different SACCH filling */
1159 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1160 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1161 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1162 }));
1163 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1164 RSL_IE_Body:{sacch_info := sacch_info})) };
1165 f_est_dchan(more_ies := addl_ies);
1166
1167 /* check that SACCH actually are received as expected */
1168 f_sacch_present(si5_specific);
1169 f_sacch_present(si6_specific);
1170
1171 /* release the channel */
1172 f_rsl_chan_deact();
1173 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1174}
1175testcase TC_sacch_chan_act() runs on test_CT {
1176 var ConnHdlr vc_conn;
1177 var ConnHdlrPars pars;
1178 f_init();
1179
1180 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1181 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1182 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1183 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1184 vc_conn.done;
1185 }
1186 /* TODO: do the above in parallel, rather than sequentially? */
1187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1188}
1189
Harald Welte8b01c792019-05-19 22:51:25 +02001190/* verify that SACCH DL transmission is started only if MS power IE present
1191 * see section 4.1.3 of 3GPP TS 48.058 */
1192private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1193 var octetstring si5 := f_rnd_octstring(19);
1194
1195 f_l1_tune(L1CTL);
1196 RSL.clear;
1197
1198 /* Step 1: Activate ASYNC HO channel without MS power IE */
1199
1200 /* Activate channel on BTS side */
1201 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1202 /* don't perform immediate assignment here, as we're testing non-IA case */
1203 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001204 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001205
1206 /* Verify that no DL SACCH is being received */
1207 f_sacch_missing(?);
1208
1209 f_rsl_chan_deact();
1210 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1211
1212
1213 /* Step 2: Activate ASYNC HO channel with MS power IE */
1214
1215 /* Activate channel on BTS side */
1216 var RSL_IE_List addl_ies := {
1217 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1218 };
1219 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1220 /* don't perform immediate assignment here, as we're testing non-IA case */
1221 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001222 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001223
1224 /* Verify that DL SACCH is being received */
1225 f_sacch_present(si5);
1226
1227 f_rsl_chan_deact();
1228 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1229}
1230testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1231 var ConnHdlr vc_conn;
1232 var ConnHdlrPars pars;
1233 f_init();
1234
1235 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1236 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1237 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1238 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1239 vc_conn.done;
1240 }
1241 /* TODO: do the above in parallel, rather than sequentially? */
1242 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1243}
1244
1245/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1246 * see section 4.1.4 of 3GPP TS 48.058 */
1247private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1248 var octetstring si5 := f_rnd_octstring(19);
1249 var RSL_IE_List addl_ies;
1250
1251 f_l1_tune(L1CTL);
1252 RSL.clear;
1253
1254 /* Step 1: Activate SYNC HO channel without MS power IE */
1255
1256 /* Activate channel on BTS side */
1257 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
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 no DL SACCH is being received */
1263 f_sacch_missing(?);
1264
1265 f_rsl_chan_deact();
1266 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1267
1268
1269 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1270
1271 /* Activate channel on BTS side */
1272 addl_ies := {
1273 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1274 };
1275 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1276 /* don't perform immediate assignment here, as we're testing non-IA case */
1277 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001278 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001279
1280 /* Verify that no DL SACCH is being received */
1281 f_sacch_missing(?);
1282
1283 f_rsl_chan_deact();
1284 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1285
1286
1287 /* Step 2b: Activate SYNC HO channel with TA IE */
1288
1289 /* Activate channel on BTS side */
1290 addl_ies := {
1291 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1292 };
1293 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1294 /* don't perform immediate assignment here, as we're testing non-IA case */
1295 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001296 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001297
1298 /* Verify that no DL SACCH is being received */
1299 f_sacch_missing(?);
1300
1301 f_rsl_chan_deact();
1302 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1303
1304
1305 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1306
1307 /* Activate channel on BTS side */
1308 addl_ies := {
1309 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1310 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1311 };
1312 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1313 /* don't perform immediate assignment here, as we're testing non-IA case */
1314 /* enable dedicated mode */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001315 f_l1ctl_est_dchan(L1CTL, g_pars);
Harald Welte8b01c792019-05-19 22:51:25 +02001316
1317 /* Verify that DL SACCH is being received */
1318 f_sacch_present(si5);
1319
1320 f_rsl_chan_deact();
1321 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1322}
1323testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1324 var ConnHdlr vc_conn;
1325 var ConnHdlrPars pars;
1326 f_init();
1327
1328 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1329 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1330 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1331 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1332 vc_conn.done;
1333 }
1334 /* TODO: do the above in parallel, rather than sequentially? */
1335 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1336}
Harald Welte629cc6b2018-03-11 17:19:05 +01001337
1338
1339/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001340 * RACH Handling
1341 ***********************************************************************/
1342
Harald Welte8c24c2b2018-02-26 08:31:31 +01001343/* like L1SAP_IS_PACKET_RACH */
1344private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001345 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001346 return true;
1347 }
1348 return false;
1349}
1350
Philipp Maier16ade782020-07-08 21:36:00 +02001351private function ra_is_emerg(OCT1 ra) return boolean {
1352 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1353 if ((ra and4b 'E0'O == 'A0'O) and (ra and4b '1F'O != '1F'O)) {
1354 return true;
1355 }
1356 return false;
1357}
1358
Harald Welte8c24c2b2018-02-26 08:31:31 +01001359/* generate a random RACH for circuit-switched */
1360private function f_rnd_ra_cs() return OCT1 {
1361 var OCT1 ra;
1362 do {
1363 ra := f_rnd_octstring(1);
1364 } while (ra_is_ps(ra));
1365 return ra;
1366}
1367
Philipp Maier16ade782020-07-08 21:36:00 +02001368/* generate a random RACH for emergency */
1369private function f_rnd_ra_emerg() return OCT1 {
1370 var OCT1 ra;
1371 do {
1372 ra := f_rnd_octstring(1);
1373 } while (not ra_is_emerg(ra));
1374 return ra;
1375}
1376
Harald Welte883340c2018-02-28 18:59:29 +01001377/* generate a random RACH for packet-switched */
1378private function f_rnd_ra_ps() return OCT1 {
1379 var OCT1 ra;
1380 do {
1381 ra := f_rnd_octstring(1);
1382 } while (not ra_is_ps(ra));
1383 return ra;
1384}
1385
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001386/* generate a random 11-bit RA (packet-switched only) */
1387private function f_rnd_ra11_ps() return BIT11 {
1388 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1389 return int2bit(ra11, 11);
1390}
1391
Harald Welte8c24c2b2018-02-26 08:31:31 +01001392/* Send 1000 RACH requests and check their RA+FN on the RSL side */
Philipp Maier16ade782020-07-08 21:36:00 +02001393private function f_TC_rach_content(boolean emerg) runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001394 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001395 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001396 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001397
Harald Welte8c24c2b2018-02-26 08:31:31 +01001398 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001399 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001400 for (var integer i := 0; i < 1000; i := i+1) {
Philipp Maier16ade782020-07-08 21:36:00 +02001401 var OCT1 ra := f_rnd_ra_emerg();
1402 if (emerg == true) {
1403 ra := f_rnd_ra_emerg();
1404 } else {
1405 ra := f_rnd_ra_cs();
1406 }
Harald Welte8c24c2b2018-02-26 08:31:31 +01001407 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1408 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001410 }
1411 fn_last := fn;
1412
1413 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001414 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001415 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001416 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001417 T.stop;
1418 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001419 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001420 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001421 }
1422 [] RSL_CCHAN.receive { repeat; }
1423 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001424 test_failed := true;
1425 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001426 }
1427 }
1428 }
Maxba06feb2019-03-05 10:52:46 +01001429 if (test_failed) {
1430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001431 }
Maxba06feb2019-03-05 10:52:46 +01001432 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001434}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001435
Philipp Maier16ade782020-07-08 21:36:00 +02001436/* Normal variant */
1437testcase TC_rach_content() runs on test_CT {
1438 f_TC_rach_content(emerg := false);
1439}
1440
1441/* Emergency call variant */
1442testcase TC_rach_content_emerg() runs on test_CT {
1443 f_TC_rach_content(emerg := true);
1444}
1445
Harald Welte8c24c2b2018-02-26 08:31:31 +01001446/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1447testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001448 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001449 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001450 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001451 f_l1_tune(L1CTL);
1452
1453 var GsmFrameNumber fn_last := 0;
1454 for (var integer i := 0; i < 1000; i := i+1) {
1455 var OCT1 ra := f_rnd_ra_cs();
1456 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1457 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001459 }
1460 fn_last := fn;
1461 }
1462 var integer rsl_chrqd := 0;
1463 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001464 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001465 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001466 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001467 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001468 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001469 repeat;
1470 }
1471 [] RSL_CCHAN.receive { repeat; }
1472 [] T.timeout { }
1473 }
1474 if (rsl_chrqd == 1000) {
1475 setverdict(pass);
1476 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001477 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001478 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001479 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001480}
1481
Harald Welte3453ab42019-05-24 21:19:58 +02001482private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1483 var charstring bts_str := "bts " & int2str(bts_nr);
1484 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1485}
1486
1487/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1488private template integer tr_rach_slots_per_interval := (90 .. 130);
1489
1490/* Expect 0 RACH load on an idle BTS that has just started up */
1491testcase TC_rach_load_idle_thresh0() runs on test_CT {
1492 var ASP_RSL_Unitdata rx_ud;
1493
1494 f_init_vty_bsc();
1495 /* send load indications even at 0% load */
1496 f_vty_load_ind_thresh(0);
1497 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1498 f_sleep(2.0);
1499
1500 f_init();
1501
1502 timer T := 5.0;
1503 T.start;
1504 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001505 [] 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 +02001506 setverdict(pass);
1507 repeat;
1508 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001509 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001510 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1511 repeat;
1512 }
1513 [] RSL_CCHAN.receive {
1514 repeat;
1515 }
1516 [] T.timeout { }
1517 }
1518
1519 f_vty_load_ind_thresh(10);
1520 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1521}
1522
1523/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1524testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1525 var ASP_RSL_Unitdata rx_ud;
1526
1527 f_init_vty_bsc();
1528 f_init();
1529
1530 timer T := 5.0;
1531 T.start;
1532 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001533 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001534 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1535 repeat;
1536 }
1537 [] RSL_CCHAN.receive {
1538 repeat;
1539 }
1540 [] T.timeout {
1541 setverdict(pass);
1542 }
1543 }
1544
1545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1546}
1547
1548/* Expect 0 RACH load on an idle BTS that has just started up */
1549testcase TC_rach_load_count() runs on test_CT {
1550 var ASP_RSL_Unitdata rx_ud;
1551 var integer load_access_count := 0;
1552
1553 f_init_vty_bsc();
1554 /* send load indications even at 0% load */
1555 f_vty_load_ind_thresh(0);
1556 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1557 f_sleep(2.0);
1558 f_init();
1559
1560 f_init_l1ctl();
1561 f_sleep(1.0);
1562 f_l1_tune(L1CTL);
1563
1564 var GsmFrameNumber fn_last := 0;
1565 for (var integer i := 0; i < 1000; i := i+1) {
1566 var OCT1 ra := f_rnd_ra_cs();
1567 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1568 if (fn == fn_last) {
1569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1570 }
1571 fn_last := fn;
1572 }
1573
1574 timer T := 5.0;
1575 T.start;
1576 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001577 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
Harald Welte3453ab42019-05-24 21:19:58 +02001578 -> value rx_ud {
1579 var RSL_IE_Body ie;
1580 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1581 load_access_count := load_access_count + ie.rach_load.access_count;
1582 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1583 setverdict(fail, "Access count cannot be < Busy count");
1584 }
1585 repeat;
1586 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001587 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
Harald Welte3453ab42019-05-24 21:19:58 +02001588 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1589 repeat;
1590 }
1591 [] RSL_CCHAN.receive {
1592 repeat;
1593 }
1594 [] T.timeout { }
1595 }
1596 if (load_access_count == 1000) {
1597 setverdict(pass);
1598 } else {
1599 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1600 }
1601
1602 f_vty_load_ind_thresh(10);
1603 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1604}
1605
Harald Welte54a2a2d2018-02-26 09:14:05 +01001606private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001607 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001608 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001609 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001610 f_sleep(0.5);
1611
1612 /* Transmit RACH request + wait for confirmation */
1613 var OCT1 ra := f_rnd_ra_cs();
1614 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1615
1616 /* Check for expected result */
1617 timer T := 1.5;
1618 T.start;
1619 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001620 [expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welte54a2a2d2018-02-26 09:14:05 +01001621 setverdict(pass);
1622 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07001623 [not expect_pass] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001624 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001625 }
1626 [] RSL_CCHAN.receive { repeat; }
1627 [not expect_pass] T.timeout {
1628 setverdict(pass);
1629 }
1630 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001631 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001632 }
1633 }
1634}
1635
1636/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1637testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001638 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001639 f_init_l1ctl();
1640 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001641 f_sleep(1.0);
1642
1643 /* default max-ta is 63 (full range of GSM timing advance */
1644
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001645 /* We allow early arrival up to 2 symbols */
1646 f_rach_toffs(-1*256, true);
1647 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001648 f_rach_toffs(-10*256, false);
1649
1650 /* 0 / 32 / 63 bits is legal / permitted */
1651 f_rach_toffs(0, true);
1652 f_rach_toffs(32*256, true);
1653 f_rach_toffs(63*256, true);
1654
1655 /* more than 63 bits is not legal / permitted */
1656 f_rach_toffs(64*256, false);
1657 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001659}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001660
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07001661private function f_TC_ho_rach(charstring id) runs on ConnHdlr {
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001662 var GsmFrameNumber fn;
1663 var RSL_Message rm;
1664
1665 f_l1_tune(L1CTL);
1666 RSL.clear;
1667
1668 /* Generate a random Handover Reference */
1669 var integer ho_ref := oct2int(f_rnd_octstring(1));
1670
1671 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1672 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1673 RSL_IE_Body:{ handover_ref := ho_ref }));
1674
1675 /* Activate a channel on the BTS side (no encryption) */
1676 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1677 act_type := t_RSL_IE_ActType_HO_SYNC);
1678
1679 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1680 * waiting for Immediate Assignment and sending Access Burst */
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07001681 f_l1ctl_est_dchan(L1CTL, g_pars);
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001682
1683 /* Send handover Access Burst */
1684 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1685
1686 /* TODO: test mismatching Handover Reference, and missing IE */
1687
1688 /* Wait for handover detection */
1689 timer T := 3.0;
1690 T.start;
1691 alt {
1692 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1693 log("Handover RACH has been detected: ", rm);
1694 setverdict(pass);
1695 }
1696 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1697 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1698 log2str("RSL_CHAN_RQD was not expected: ", rm));
1699 }
1700 [] RSL.receive { repeat; }
1701 [] T.timeout {
1702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1703 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1704 }
1705 }
1706
1707 /* Release the channel */
1708 f_rsl_chan_deact();
1709 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1710}
1711
1712/* Test handover RACH detection */
1713testcase TC_ho_rach() runs on test_CT {
1714 var ConnHdlrPars pars;
1715 var ConnHdlr vc_conn;
1716
1717 f_init();
1718
1719 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1720 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1721 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1722 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1723 vc_conn.done;
1724 }
1725
1726 /* TODO: do the above in parallel, rather than sequentially? */
1727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1728}
1729
Harald Welte93640c62018-02-25 16:59:33 +01001730/***********************************************************************
1731 * Measurement Processing / Reporting
1732 ***********************************************************************/
1733
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001734private template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
Harald Welte70767382018-02-21 12:16:40 +01001735 spare := '0'B,
1736 lpd := 0,
1737 sapi := sapi,
1738 c_r := c_r,
1739 ea := true
1740}
1741
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001742private template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001743 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001744 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001745 len := 0, /* overwritten */
1746 m := false,
1747 el := 1,
1748 payload := pl
1749}
1750
1751/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001752private altstep as_l1_sacch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001753 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001754 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001755 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001756 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, mp_rxlev_exp, mp_rxlev_exp, 0, 0, omit));
Harald Welted879bd92018-03-12 15:01:23 +01001757 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001758 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001759
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001760 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1761 g_pars.l1_pars.ms_power_level, false,
1762 g_pars.l1_pars.ms_actual_ta);
1763
1764 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1765 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1766
1767 log("Sending Measurement Report: ", l1h, l2);
1768 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001769 repeat;
1770 }
1771}
1772
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001773private altstep as_l1_dcch() runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001774 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001775 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001776 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1777 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001778 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1779 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001780 repeat;
1781 }
1782}
1783
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001784private type record MeasElem {
Harald Welte70767382018-02-21 12:16:40 +01001785 uint6_t rxlev,
1786 uint3_t rxqual
1787}
1788
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001789private type record MeasElemFS {
Harald Welte70767382018-02-21 12:16:40 +01001790 MeasElem full,
1791 MeasElem sub
1792}
1793
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001794private type record ConnL1Pars {
Harald Welte70767382018-02-21 12:16:40 +01001795 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001796 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001797 MeasElemFS meas_ul,
1798 int16_t timing_offset_256syms,
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07001799 uint4_t bs_power_level,
Harald Welte70767382018-02-21 12:16:40 +01001800 uint5_t ms_power_level,
1801 uint8_t ms_actual_ta
1802}
1803
1804/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1805private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1806 return 63 + (toffs256s/256);
1807}
1808
Harald Welted5684392018-03-10 18:22:04 +01001809private function f_max(integer a, integer b) return integer {
1810 if (a > b) {
1811 return a;
1812 } else {
1813 return b;
1814 }
1815}
1816
1817private function f_min(integer a, integer b) return integer {
1818 if (a < b) {
1819 return a;
1820 } else {
1821 return b;
1822 }
1823}
1824
1825/* compute negative tolerance val-tolerance, ensure >= min */
1826private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1827 val := val - tolerance;
1828 return f_max(val, min);
1829}
1830
1831/* compute positive tolerance val+tolerance, ensure <= max */
1832private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1833 val := val + tolerance;
1834 return f_min(val, max);
1835}
1836
1837/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1838private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1839return template integer {
1840 var template integer ret;
1841 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1842 return ret;
1843}
1844
1845
Harald Welte70767382018-02-21 12:16:40 +01001846/* build a template for matching measurement results against */
1847private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1848 var ConnL1Pars l1p := g_pars.l1_pars;
1849 var template RSL_IE_UplinkMeas ul_meas := {
1850 len := 3,
1851 rfu := '0'B,
1852 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001853 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001854 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001855 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001856 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001857 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1858 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001859 supp_meas_info := omit
1860 };
Harald Welte685d5982018-02-27 20:42:05 +01001861 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001862 ul_meas.len := (3+8);
1863 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001864 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001865 toa256_min := ?,
1866 toa256_max := ?,
1867 toa256_std_dev := ?
1868 }
Harald Welte685d5982018-02-27 20:42:05 +01001869 }
Harald Welte70767382018-02-21 12:16:40 +01001870 var template RSL_IE_BS_Power bs_power := {
1871 reserved := 0,
1872 epc := false,
1873 fpc := false,
1874 power_level := l1p.bs_power_level
1875 };
1876 var template RSL_IE_L1Info l1_info := {
1877 ms_power_lvl := l1p.ms_power_level,
1878 fpc := false,
1879 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001880 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001881 };
1882 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001883 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001884 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1885 ?, t_toffs);
1886}
1887
Philipp Maierdd841d32019-12-17 14:44:54 +01001888/* build a template for matching measurement results that do not contain any
1889 * MS related measurement (l1_info, l3_info and ms timing offset). */
1890private function f_build_meas_res_tmpl_empty() runs on ConnHdlr return template RSL_Message {
1891 var ConnL1Pars l1p := g_pars.l1_pars;
1892 var template RSL_IE_UplinkMeas ul_meas := {
1893 len := 3,
1894 rfu := '0'B,
1895 dtx_d := l1p.dtx_enabled,
1896 rxlev_f_u := ?,
1897 reserved1 := '00'B,
1898 rxlev_s_u := ?,
1899 reserved2 := '00'B,
1900 rxq_f_u := ?,
1901 rxq_s_u := ?,
1902 supp_meas_info := omit
1903 };
1904 if (l1p.toa256_enabled) {
1905 ul_meas.len := (3+8);
1906 ul_meas.supp_meas_info := {
1907 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
1908 toa256_min := ?,
1909 toa256_max := ?,
1910 toa256_std_dev := ?
1911 }
1912 }
1913 var template RSL_IE_BS_Power bs_power := {
1914 reserved := 0,
1915 epc := false,
1916 fpc := false,
1917 power_level := l1p.bs_power_level
1918 };
1919
1920 return tr_RSL_MEAS_RES_EMPTY(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power);
1921}
1922
Harald Welte70767382018-02-21 12:16:40 +01001923/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07001924private altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001925 var RSL_Message rsl;
Philipp Maierdd841d32019-12-17 14:44:54 +01001926 var boolean chan_est := false;
1927
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001928 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Philipp Maierdd841d32019-12-17 14:44:54 +01001929
1930 /* Receive osmocom specific measurement reports. This is the normal
1931 * case. Here we verify that the measurement reports we sent are
1932 * comming back as we expect them. */
Harald Welte70767382018-02-21 12:16:40 +01001933 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1934 /* increment counter of next to-be-expected meas rep */
1935 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1936 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001937 f_timer_safe_restart(g_Tmeas_exp);
Philipp Maierdd841d32019-12-17 14:44:54 +01001938
1939 /* The following two cases may only happen in the beginning
1940 * of the channel establishment phase. Once we have received
1941 * the "our" measurement report the first time, the channel
1942 * is established and empty or hardcoded TRXCON reports must
1943 * not occur anymore. */
1944 chan_est := true;
1945
1946 repeat;
1947 }
1948
1949 /* When the BTS has established the channel, the MS might need slightly
1950 * more time to establish the channel and actually start sending. The
1951 * result is then a measurement report that just lacks the measurement
1952 * information of the MS. This is normal and we tolerate this behavior. */
1953 [chan_est == false] RSL.receive(f_build_meas_res_tmpl_empty()) -> value rsl {
1954 /* increment counter of next to-be-expected meas rep */
1955 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1956 /* Re-start the timer expecting the next MEAS RES */
1957 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001958 repeat;
1959 }
Philipp Maierdd841d32019-12-17 14:44:54 +01001960
1961 /* Due to the TDMA nature of GSM, TRXCON implements a way to emit dummy
1962 * measurements if the TTCN3 side does not supply measurement input in
1963 * time. In those cases TRXCON will either use a cached measurement
1964 * report or a hardcoded one. If TRXCON picks the hardcoded measurement
1965 * report the templates above will not match. We tolerate this
1966 * behavior, but only once. */
1967 [chan_est == false] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001968 /* increment counter of next to-be-expected meas rep */
1969 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1970 if (g_first_meas_res) {
1971 g_first_meas_res := false;
1972 repeat;
1973 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001975 }
Harald Welte70767382018-02-21 12:16:40 +01001976 }
1977 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001978 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001979 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001980 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001982 }
1983}
1984
Harald Weltee613f962018-04-18 22:38:16 +02001985private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1986 select (rsl_alg_id) {
1987 case (RSL_ALG_ID_A5_0) { return 0; }
1988 case (RSL_ALG_ID_A5_1) { return 1; }
1989 case (RSL_ALG_ID_A5_2) { return 2; }
1990 case (RSL_ALG_ID_A5_3) { return 3; }
1991 case (RSL_ALG_ID_A5_4) { return 4; }
1992 case (RSL_ALG_ID_A5_5) { return 5; }
1993 case (RSL_ALG_ID_A5_6) { return 6; }
1994 case (RSL_ALG_ID_A5_7) { return 7; }
1995 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001996 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1997 /* Make compiler happy by calling mtc.stop here. It is already
1998 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001999 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002000 }
2001 }
2002}
2003
2004private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
2005 select (rsl_alg_id) {
2006 case (RSL_ALG_ID_A5_1) { return '000'B; }
2007 case (RSL_ALG_ID_A5_2) { return '001'B; }
2008 case (RSL_ALG_ID_A5_3) { return '010'B; }
2009 case (RSL_ALG_ID_A5_4) { return '011'B; }
2010 case (RSL_ALG_ID_A5_5) { return '100'B; }
2011 case (RSL_ALG_ID_A5_6) { return '101'B; }
2012 case (RSL_ALG_ID_A5_7) { return '110'B; }
2013 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
2015 /* Make compiler happy by calling mtc.stop here. It is already
2016 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02002017 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02002018 }
2019 }
2020}
2021
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002022/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
2023private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
2024 var GsmFrameNumber fn;
2025 timer T := 8.0;
2026
2027 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
2028 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
2029
2030 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
2031 /* Send the actual RACH */
2032 fn := f_L1CTL_RACH(L1CTL, ra);
2033
2034 T.start;
2035 alt {
2036 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
2037 [] T.timeout {
2038 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
2039 }
2040 }
2041 T.stop
2042 return fn;
2043}
Harald Weltee613f962018-04-18 22:38:16 +02002044
Vadim Yanitskiy6c71c172020-07-13 21:49:48 +07002045/* Tune to a dedicated channel: L1CTL only */
2046private function f_l1ctl_est_dchan(L1CTL_PT pt, ConnHdlrPars pars) {
2047 if (not ispresent(pars.maio_hsn)) {
2048 pt.send(ts_L1CTL_DM_EST_REQ_H0(pars.chan_nr,
2049 7 /* TODO: mp_tsc */,
2050 mp_trx0_arfcn));
2051 } else {
2052 pt.send(ts_L1CTL_DM_EST_REQ_H1(pars.chan_nr,
2053 7 /* TODO: mp_tsc */,
2054 pars.maio_hsn.hsn,
2055 pars.maio_hsn.maio,
2056 pars.ma));
2057 }
2058}
2059
Harald Welte70767382018-02-21 12:16:40 +01002060/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002061private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01002062 var GsmFrameNumber fn;
2063 var ImmediateAssignment imm_ass;
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002064 var ChannelDescription ch_desc;
Harald Welte70767382018-02-21 12:16:40 +01002065 var integer ra := 23;
2066
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02002067 /* Send RACH request and wait for ChanReq */
2068 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01002069
2070 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02002071 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01002072
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002073 /* Craft channel description (with or without frequency hopping parameters) */
2074 if (ispresent(g_pars.maio_hsn)) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002075 ch_desc := valueof(ts_ChanDescH1(g_pars.chan_nr, g_pars.maio_hsn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002076 } else {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07002077 ch_desc := valueof(ts_ChanDescH0(g_pars.chan_nr, mp_trx0_arfcn));
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002078 }
2079
Harald Welte70767382018-02-21 12:16:40 +01002080 /* Send IMM.ASS via CCHAN */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002081 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, g_pars.ma_map));
Harald Welte70767382018-02-21 12:16:40 +01002082 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
2083
2084 /* receive IMM.ASS on MS side */
2085 var ImmediateAssignment ia_um;
2086 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002087
2088 /* Make sure that IMM.ASS contains hopping parameters (if enabled) */
2089 if (ch_desc.h != ia_um.chan_desc.h) {
2090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Hopping parameters mismatch");
2091 }
2092
Harald Welte70767382018-02-21 12:16:40 +01002093 /* enable dedicated mode */
Vadim Yanitskiy28cabc42020-05-27 19:44:44 +07002094 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um, ma := g_pars.ma);
Harald Weltee613f962018-04-18 22:38:16 +02002095 /* enable encryption, if requested */
2096 if (encr_enable) {
2097 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
2098 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
2099 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01002100
2101 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01002102}
2103
2104/* establish DChan, verify existance + contents of measurement reports */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002105private function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002106 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002107 RSL.clear;
2108
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07002109 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02002110 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07002111 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02002112 }
Harald Welte70767382018-02-21 12:16:40 +01002113
2114 f_est_dchan();
2115
2116 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
2117 * RSL measurement reports on Abis side */
2118 timer T := 8.0;
2119 T.start;
2120 alt {
2121 [] as_l1_sacch();
2122 [] as_meas_res();
2123 [] as_l1_dcch();
2124 [] L1CTL.receive { repeat; }
2125 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002126 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01002127 * of any earlier errors, so if we reach this timeout, we're good */
2128 setverdict(pass);
2129 }
2130 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01002132 }
2133 }
2134 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01002135 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01002136}
Harald Welte0472ab42018-03-12 15:02:26 +01002137
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002138/* Wait until the BTS has reached full tx power (nominal tx power minus configured attenuation) */
2139private function f_wait_ramp_up() runs on ConnHdlr return integer {
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002140 var L1ctlDlMessage l1_dl;
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002141 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2142 timer Tup := 10.0;
2143 Tup.start;
2144 alt {
2145 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2146 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2147 log("Received rx_level=", rx_lvl);
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002148
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002149 if (rx_lvl != max_rx_lvl) {
2150 repeat;
2151 }
2152 Tup.stop;
2153 }
2154 [] L1CTL.receive { repeat; }
2155 [] Tup.timeout {
2156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2157 log2str("Didn't reach full power ", max_rx_lvl));
2158 }
2159 }
2160 return max_rx_lvl;
2161}
2162
2163/* verify BTS ramps power up to full tx power (nominal tx power minus configured attenuation) */
2164private function f_verify_ramp_up() runs on ConnHdlr {
2165 var L1ctlDlMessage l1_dl;
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002166 var integer initial_rx_lvl := -1;
2167 var integer last_rx_lvl := -1;
2168 var integer max_rx_lvl := mp_bts_tx_nom_pwr_exp - mp_bts_tx_pwr_att_exp;
2169
2170 timer T := 2.0;
2171 alt {
2172 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2173 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2174 log("Received rx_level=", rx_lvl);
2175 if (initial_rx_lvl == -1) {
2176 initial_rx_lvl := rx_lvl;
2177 last_rx_lvl := rx_lvl;
2178
2179 /* Expect a somehow low value during first received messages */
2180 if (initial_rx_lvl >= max_rx_lvl / 2) {
2181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2182 log2str("Detected high initial tx power during ramp up: ",
2183 initial_rx_lvl , ", full power is", max_rx_lvl));
2184 }
2185 }
2186
2187 /* received Rx level bigger than maximum allowed power by CN */
2188 if (rx_lvl > max_rx_lvl) {
2189 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2190 log2str("Detected Tx power higher than full power: ",
2191 rx_lvl , " > ", max_rx_lvl));
2192 }
2193
2194 /* Make sure it never decreases, since we are rumping up */
2195 if (last_rx_lvl > rx_lvl) {
2196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2197 log2str("Detected Tx power decrease during ramp up: ",
2198 last_rx_lvl , " -> ", rx_lvl));
2199 }
2200
2201 if (rx_lvl == max_rx_lvl and not T.running) {
2202 /* We reached the maximum power, start timer and receive
2203 /* a few more to make sure we don't surpass it */
2204 log("Reached full power, wating a bit more until success");
2205 T.start;
2206 }
2207
2208 last_rx_lvl := rx_lvl;
2209 repeat;
2210 }
2211 [] L1CTL.receive { repeat; }
2212 [] T.timeout { }
2213 }
2214
2215 /* We didn't increase tx power during ramp up */
2216 if (initial_rx_lvl < last_rx_lvl) {
2217 log("Tx power increased during ramp up: ", initial_rx_lvl , " -> ", last_rx_lvl);
2218 } else {
2219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2220 log2str("No Tx power increase during whole ramp up: ",
2221 initial_rx_lvl , " -> ", last_rx_lvl));
2222 }
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002223}
2224
2225/* verify BTS ramps power down to rx_level 0 */
2226private function f_verify_ramp_down(integer max_rx_lvl) runs on ConnHdlr {
2227 var L1ctlDlMessage l1_dl;
2228 var integer last_rx_lvl := max_rx_lvl;
2229
2230 timer Tdown := 5.0;
2231 Tdown.start;
2232 alt {
2233 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2234 var GsmRxLev rx_lvl := l1_dl.dl_info.rx_level;
2235 log("Received rx_level=", rx_lvl);
2236
2237 /* received Rx level bigger than maximum allowed power by CN */
2238 if (rx_lvl > max_rx_lvl) {
2239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2240 log2str("Detected Tx power higher than full power: ",
2241 rx_lvl , " > ", max_rx_lvl));
2242 }
2243
2244 /* Make sure it never increases, since we are rumping down */
2245 if (last_rx_lvl < rx_lvl) {
2246 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2247 log2str("Detected Tx power increase during ramp up: ",
2248 last_rx_lvl , " -> ", rx_lvl));
2249 }
2250
2251 last_rx_lvl := rx_lvl;
2252 if (last_rx_lvl != 0) {
2253 repeat;
2254 }
2255 /* we reached power level 0, we are done */
2256 Tdown.stop;
2257 }
2258 [] L1CTL.receive { repeat; }
2259 [] Tdown.timeout { }
2260 }
2261
2262 /* We didn't increase tx power during ramp down */
2263 if (max_rx_lvl > last_rx_lvl) {
2264 log("Tx power decreased during ramp down: ", max_rx_lvl , " -> ", last_rx_lvl);
2265 } else {
2266 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2267 log2str("No Tx power decrease during whole ramp down: ",
2268 max_rx_lvl , " -> ", last_rx_lvl));
2269 }
2270}
2271
2272/* Verify Tx power reduction and ramping up during BTS bring up */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002273private function f_TC_tx_power_start_ramp_up_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002274 f_l1_tune(L1CTL);
2275 RSL.clear;
2276
2277 f_verify_ramp_up();
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02002278
2279 setverdict(pass);
2280}
2281testcase TC_tx_power_start_ramp_up_bcch() runs on test_CT {
2282 var ConnHdlr vc_conn;
2283 var ConnHdlrPars pars;
2284 f_init();
2285 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2286 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_up_bcch), pars,
2287 pcu_comp := false, trxc_comp := true);
2288 vc_conn.done;
2289 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2290}
2291
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002292/* Verify Tx power reduction and ramping downd uring BTS bring shutdown due to Abis link failure */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002293private function f_TC_tx_power_start_ramp_down_bcch(charstring id) runs on ConnHdlr {
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02002294 f_connhdlr_init_vty_bsc();
2295
2296 f_l1_tune(L1CTL);
2297 RSL.clear;
2298
2299 /* Wait until BTS is started and at full power */
2300 var integer max_rx_lvl := f_wait_ramp_up();
2301 log("Reached nominal level ", max_rx_lvl, ", shutting down OML link");
2302
2303 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2304 f_verify_ramp_down(max_rx_lvl);
2305
2306 setverdict(pass);
2307}
2308testcase TC_tx_power_start_ramp_down_bcch() runs on test_CT {
2309 var ConnHdlr vc_conn;
2310 var ConnHdlrPars pars;
2311 f_init();
2312 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2313 vc_conn := f_start_handler(refers(f_TC_tx_power_start_ramp_down_bcch), pars,
2314 pcu_comp := false, trxc_comp := true);
2315 vc_conn.done;
2316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2317}
2318
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002319/* Verify Tx power:
2320 * + ramping down during ADM state UNLOCKED->LOCKED
2321 * + ramping up during ADM state LOCKED->UNLOCKED
2322 */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002323private function f_TC_tx_power_ramp_adm_state_change(charstring id) runs on ConnHdlr {
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02002324 var L1ctlDlMessage l1_dl;
2325 var integer last_rx_lvl;
2326
2327 f_connhdlr_init_vty_bsc();
2328
2329 f_l1_tune(L1CTL);
2330 RSL.clear;
2331
2332 /* Wait until BTS is started and at full power */
2333 var integer max_rx_lvl := f_wait_ramp_up();
2334 log("Reached nominal level ", max_rx_lvl, ", changing ADM state to LOCKED");
2335
2336 log("ADM STATE UNLOCKED->LOCKED");
2337 f_vty_enter_cfg_trx(BSCVTY);
2338 f_vty_transceive(BSCVTY, "rf_locked 1");
2339 last_rx_lvl := max_rx_lvl;
2340 f_verify_ramp_down(max_rx_lvl);
2341
2342 /* Let some time after we received 0dBm, then check we don't receive BCCH
2343 * anymore because scheduler has stopped after ramping down */
2344 f_sleep(2.0);
2345 L1CTL.clear;
2346 timer Tlocked := 2.0;
2347 Tlocked.start;
2348 alt {
2349 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
2350 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2351 log2str("Received data_ind during rf_locked: ", l1_dl));
2352 }
2353 [] L1CTL.receive { repeat; }
2354 [] Tlocked.timeout { setverdict(pass, "Didn't receive data_ind while in rf_locked state."); }
2355 }
2356
2357 log("ADM STATE LOCKED->UNLOCKED");
2358 f_vty_transceive(BSCVTY, "rf_locked 0");
2359 f_verify_ramp_up();
2360 setverdict(pass);
2361}
2362testcase TC_tx_power_ramp_adm_state_change() runs on test_CT {
2363 var ConnHdlr vc_conn;
2364 var ConnHdlrPars pars;
2365 f_init();
2366 pars := valueof(t_Pars(t_RslChanNr_Bm(0), ts_RSL_ChanMode_SIGN));
2367 vc_conn := f_start_handler(refers(f_TC_tx_power_ramp_adm_state_change), pars,
2368 pcu_comp := false, trxc_comp := true);
2369 vc_conn.done;
2370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2371}
2372
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002373private function f_check_meas_bs_power_level(integer level) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002374 timer T := 8.0;
2375 T.start;
2376 var RSL_Message rsl;
2377 alt {
2378 [] as_l1_sacch();
2379 [] L1CTL.receive { repeat; }
2380 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, ?, ?, ?)) -> value rsl {
2381 if (rsl.ies[3].body.bs_power.power_level == level) {
2382 setverdict(pass)
2383 } else {
2384 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received wrong BS power level in MEAS RES ", rsl));
2385 }
2386 }
2387 [] T.timeout {
2388 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
2389 }
2390 }
2391}
2392
2393/* see if the rsl meas res contains our expeced bs power level
2394bs power set during assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002395private function f_TC_rsl_bs_pwr_static_ass(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002396 f_l1_tune(L1CTL);
2397 RSL.clear;
2398
2399 if (mp_bts_trxc_port != -1) {
2400 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2401 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2402 }
2403
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002404 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002405 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2406 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power});
2407
2408 f_est_dchan(more_ies :={valueof(pwr)});
2409
2410 f_check_meas_bs_power_level(pwr_var);
2411
2412 f_rsl_chan_deact();
2413 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2414}
2415
2416/* see if the rsl meas res contains our expeced bs power level
2417bs power set after assignment */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002418private function f_TC_rsl_bs_pwr_static_power_control(charstring id) runs on ConnHdlr {
Eric Wildae8f2622019-06-18 17:05:11 +02002419 f_l1_tune(L1CTL);
2420 RSL.clear;
2421
2422 if (mp_bts_trxc_port != -1) {
2423 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
2424 f_trxc_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
2425 }
2426
Vadim Yanitskiy117c1762020-06-16 01:40:10 +07002427 var uint4_t pwr_var := 1;
Eric Wildae8f2622019-06-18 17:05:11 +02002428 var template (value) RSL_IE_BS_Power bs_power := ts_RSL_IE_BS_Power(pwr_var);
2429
2430 f_est_dchan();
2431
2432 RSL.send(ts_RSL_BS_PWR_CTRL(g_chan_nr, bs_power));
2433
2434 f_check_meas_bs_power_level(pwr_var);
2435
2436 f_rsl_chan_deact();
2437 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2438}
2439
2440testcase TC_rsl_bs_pwr_static_ass() runs on test_CT {
2441 var ConnHdlr vc_conn;
2442 var ConnHdlrPars pars;
2443 f_init();
2444 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2445 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2446 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_ass), pars,
2447 pcu_comp := false, trxc_comp := true);
2448 vc_conn.done;
2449 }
2450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2451}
2452
2453testcase TC_rsl_bs_pwr_static_power_control() runs on test_CT {
2454 var ConnHdlr vc_conn;
2455 var ConnHdlrPars pars;
2456 f_init();
2457 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2458 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2459 vc_conn := f_start_handler(refers(f_TC_rsl_bs_pwr_static_power_control), pars,
2460 pcu_comp := false, trxc_comp := true);
2461 vc_conn.done;
2462 }
2463 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2464}
2465
Eric Wild61edb7e2019-06-03 12:38:31 +02002466/* target level -100, first rssi -90, ms power 7, expected increase to 7+6 within 6 seconds,
2467second rssi -110, ms power 7+6, expected decrease to 7 within 6 seconds,
2468These power levels are valid for all bands and require no special handling */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002469private function f_TC_rsl_ms_pwr_dyn_ass_updown(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002470 var uint5_t pwr_var := 7;
2471 var L1ctlDlMessage l1_dl;
2472
2473 f_trxc_fake_rssi(rxlev2dbm(10));
2474 f_l1_tune(L1CTL);
2475 RSL.clear;
2476
2477 var RSL_IE_List addl_ies;
2478 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2479
2480 addl_ies := {
2481 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2482 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2483 };
2484
2485 /* establish with power parameters */
2486 f_est_dchan(more_ies := addl_ies);
2487
2488 /* set a high value to ensure L1 power control level increases */
2489 f_trxc_fake_rssi(rxlev2dbm(20));
2490
2491 timer T2 := 6.0;
2492 T2.start;
2493 alt {
2494 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002495 /* Update sent MS power to follow what BTS requests */
2496 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2497 if (oct2int(l1_dl.payload.data_ind.payload[0]) < (pwr_var + 6)) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002498 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002499 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002500 T2.stop;
2501 }
2502 [] L1CTL.receive { repeat; }
2503 [] T2.timeout {
2504 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2505 "Power Level in L1 header has not increased sufficiently");
2506 }
2507 }
2508
2509 /* set a low value to ensure L1 power control level decreases */
2510 f_trxc_fake_rssi(rxlev2dbm(0));
2511
2512 timer T4 := 6.0;
2513 T4.start;
2514 alt {
2515 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002516 /* Update sent MS power to follow what BTS requests */
2517 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2518 if (oct2int(l1_dl.payload.data_ind.payload[0]) > pwr_var) {
Eric Wild61edb7e2019-06-03 12:38:31 +02002519 repeat;
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002520 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002521 T4.stop;
2522 setverdict(pass, "Power level in L1 decreased/increased as expected");
2523 }
2524 [] L1CTL.receive { repeat; }
2525 [] T4.timeout {
2526 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2527 "Power Level in L1 header has not decreased sufficiently");
2528 }
2529 }
2530
2531 f_rsl_chan_deact();
2532 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2533
2534}
2535
2536/* check that we do not exceed the max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002537private function f_TC_rsl_ms_pwr_dyn_max(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002538 var uint5_t pwr_var := 7;
2539 var L1ctlDlMessage l1_dl;
2540
2541 /* set a low value to ensure power increases */
2542 f_trxc_fake_rssi(rxlev2dbm(10));
2543 f_l1_tune(L1CTL);
2544 RSL.clear;
2545
2546 var RSL_IE_List addl_ies;
2547 var template (value) RSL_IE_MS_Power_Parameters pp := (ts_RSL_IE_MS_Power_Parameters(''O));
2548
2549 addl_ies := {
2550 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_var)})),
2551 valueof(t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params := pp}))
2552 };
2553
2554 /* establish with power parameters */
2555 f_est_dchan(more_ies := addl_ies);
2556
2557 timer T1 := 10.0;
2558 T1.start;
2559 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002560 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2561 /* Update sent MS power to follow what BTS requests */
2562 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2563 repeat;
2564 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002565 [] L1CTL.receive { repeat; }
2566 [] T1.timeout {
2567 if( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var){
2568 setverdict(fail, "Power level in L1 header should not have changed");
2569 }
2570 }
2571 }
2572
2573 f_rsl_chan_deact();
2574 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2575
2576}
2577
2578/* see if we reach the band max power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002579private function f_TC_rsl_ms_pwr_dyn_up(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002580 var L1ctlDlMessage l1_dl;
2581 var uint5_t pwr_var := 15;
2582 var uint5_t pwr_max_var := f_get_max_power_from_band();
2583
2584 /* set a low value to ensure power increases */
2585 f_trxc_fake_rssi(rxlev2dbm(10));
2586 f_l1_tune(L1CTL);
2587 RSL.clear;
2588
2589 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2590 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2591
2592 /* establish with fixed power level */
2593 f_est_dchan(more_ies :={valueof(pwr)});
2594
2595 /* check our initial power level */
2596 f_wait_for_l1_power_level(pwr_var);
2597
2598 /* update power param to enable power loop
2599 48.058 The maximum power to be used is indicated in the BS and MS Power elements respectively. */
2600 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_max_var));
2601
2602 /* wait, then check that our power level was reduced */
2603 timer T1 := 10.0;
2604 T1.start;
2605 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002606 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2607 /* Update sent MS power to follow what BTS requests */
2608 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2609 repeat;
2610 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002611 [] L1CTL.receive { repeat; }
2612 [] T1.timeout {
2613 var int8_t rcv := oct2int(l1_dl.payload.data_ind.payload[0]);
2614 if( f_power_level_is_highest_dbm(rcv) ){
2615 setverdict(pass, "Power level in L1 header reduced as expected");
2616 } else {
2617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2618 log2str("Power Level in L1 header did not reach the expected value, e:",pwr_max_var," r:",rcv));
2619 }
2620 }
2621 }
2622
2623 f_rsl_chan_deact();
2624 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2625
2626}
2627
2628/* see if we reach the band min power */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002629private function f_TC_rsl_ms_pwr_dyn_down(charstring id) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002630 var L1ctlDlMessage l1_dl;
2631
2632 /* set a high value to ensure power decreases */
2633 f_trxc_fake_rssi(rxlev2dbm(50));
2634 f_l1_tune(L1CTL);
2635 RSL.clear;
2636
2637 var uint5_t pwr_var := 5;
2638 var uint5_t pwr_target_val := 15;
2639
2640 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2641 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2642
2643 /* establish with fixed power level */
2644 f_est_dchan(more_ies :={valueof(pwr)});
2645
2646 /* check our initial power level */
2647 f_wait_for_l1_power_level(pwr_var);
2648
2649 /* update power param to enable power loop
2650 as per spec the supplied ms power IE should set the max allowed power...*/
Pau Espin Pedrol61122c82019-11-05 13:50:27 +01002651 RSL.send(ts_RSL_MS_PWR_CTRL_with_pp(g_chan_nr, pwr_target_val));
Eric Wild61edb7e2019-06-03 12:38:31 +02002652
2653 /* wait, then check that our power level was increased */
2654 timer T1 := 10.0;
2655 T1.start;
2656 alt {
Pau Espin Pedrola1f7d242019-12-04 16:08:09 +01002657 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2658 /* Update sent MS power to follow what BTS requests */
2659 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, oct2int(l1_dl.payload.data_ind.payload[0]));
2660 repeat;
2661 }
Eric Wild61edb7e2019-06-03 12:38:31 +02002662 [] L1CTL.receive { repeat; }
2663 [] T1.timeout {
2664 if( f_power_level_is_lowest_dbm(oct2int(l1_dl.payload.data_ind.payload[0])) ){
2665 setverdict(pass, "Power level in L1 header increased to lowest power value");
2666 } else {
2667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2668 "Power level in L1 header NOT increased to lowest power value");
2669 }
2670 }
2671 }
2672
2673 f_rsl_chan_deact();
2674 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2675
2676}
2677
Eric Wild095024b2019-06-17 15:08:57 +02002678/* see if we change the power level without receiving power parameters, which should not happen
2679rsl chan act WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002680private function f_TC_rsl_ms_pwr_dyn_active(charstring id) runs on ConnHdlr {
Eric Wild280ccb82019-06-17 11:11:52 +02002681 var L1ctlDlMessage l1_dl;
2682
2683 /* set a high value to ensure power decreases */
2684 f_trxc_fake_rssi(rxlev2dbm(50));
2685 f_l1_tune(L1CTL);
2686 RSL.clear;
2687
2688 var uint5_t pwr_var := 5;
2689
2690 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2691 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2692
2693 /* establish with fixed power level */
2694 f_est_dchan(more_ies :={valueof(pwr)});
2695
2696 /* check our initial power level */
2697 f_wait_for_l1_power_level(pwr_var);
2698
2699 /* wait, then check that our power level did not change */
2700 timer T1 := 10.0;
2701 T1.start;
2702 alt {
2703 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2704 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2706 "BS power control should not be active unless we receive a power parameters IE!");
2707 }
2708 repeat;
2709 }
2710 [] L1CTL.receive { repeat; }
2711 [] T1.timeout { setverdict(pass); }
2712 }
2713
2714 f_rsl_chan_deact();
2715 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2716
2717}
2718
Eric Wild095024b2019-06-17 15:08:57 +02002719/* see if we change the power level without receiving power parameters, which should not happen
2720ms power control WITHOUT power parameters */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07002721private function f_TC_rsl_ms_pwr_dyn_active2(charstring id) runs on ConnHdlr {
Eric Wild095024b2019-06-17 15:08:57 +02002722 var L1ctlDlMessage l1_dl;
2723
2724 /* set a high value to ensure power decreases */
2725 f_trxc_fake_rssi(rxlev2dbm(50));
2726 f_l1_tune(L1CTL);
2727 RSL.clear;
2728
2729 var uint5_t pwr_var := 5;
2730
2731 var template (value) RSL_IE_MS_Power ms_power := ts_RSL_IE_MS_Power(pwr_var);
2732 var template (value) RSL_IE pwr := t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power});
2733
2734 /* establish with fixed power level */
2735 f_est_dchan(more_ies :={valueof(pwr)});
2736
2737 /* check our initial power level */
2738 f_wait_for_l1_power_level(pwr_var);
2739
2740 /* pwr control without power params IE, should NOT activate MS power control*/
2741 RSL.send(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
2742
2743 /* wait, then check that our power level did not change */
2744 timer T1 := 10.0;
2745 T1.start;
2746 alt {
2747 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2748 if ( oct2int(l1_dl.payload.data_ind.payload[0]) != pwr_var) {
2749 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2750 "BS power control should not be active unless we receive a power parameters IE!");
2751 }
2752 repeat;
2753 }
2754 [] L1CTL.receive { repeat; }
2755 [] T1.timeout { setverdict(pass); }
2756 }
2757
2758 f_rsl_chan_deact();
2759 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2760
2761}
2762
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002763private function f_wait_for_l1_power_level(integer level) runs on ConnHdlr {
Eric Wild61edb7e2019-06-03 12:38:31 +02002764 var L1ctlDlMessage l1_dl;
2765 timer T0 := 10.0;
2766 T0.start;
2767 alt {
2768 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2769 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(level, 1))) {
2770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2771 "Power level in L1 header != signaled (RSL) power level.");
2772 }
2773 }
2774 [] L1CTL.receive { repeat; }
2775 [] T0.timeout {
2776 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2777 "Timeout waiting for initial power level");
2778 }
2779 }
2780 T0.stop;
2781}
2782
2783private function f_power_level_is_lowest_dbm(integer level) runs on ConnHdlr return boolean {
2784 var IntegerRecord min_dbm_level;
2785 var IntegerRecord max_dbm_level;
2786 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2787
2788 for (var integer i := 0; i < sizeof(min_dbm_level); i := i+1) {
2789 if (min_dbm_level[i] == level) {
2790 return true;
2791 }
2792 }
2793 return false;
2794}
2795
2796private function f_power_level_is_highest_dbm(integer level) runs on ConnHdlr return boolean {
2797 var IntegerRecord min_dbm_level;
2798 var IntegerRecord max_dbm_level;
2799 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2800
2801 for (var integer i := 0; i < sizeof(max_dbm_level); i := i+1) {
2802 if (max_dbm_level[i] == level) {
2803 return true;
2804 }
2805 }
2806 return false;
2807}
2808
2809private function f_get_max_power_from_band() runs on ConnHdlr return integer {
2810 var IntegerRecord min_dbm_level;
2811 var IntegerRecord max_dbm_level;
2812 var IntegerRecord x := f_power_from_band(g_pars.bts0_band, min_dbm_level, max_dbm_level);
2813 return max_dbm_level[0];
2814}
2815
2816type charstring BtsBand ("GSM450","GSM480","GSM750","GSM810","GSM850","GSM900","DCS1800","PCS1900");
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07002817private template charstring BtsBand_allGSM := pattern "GSM???";
Eric Wild61edb7e2019-06-03 12:38:31 +02002818private function f_power_from_band(in BtsBand band, out IntegerRecord min_dbm_level, out IntegerRecord max_dbm_level) return IntegerRecord {
2819 // 45.005 4.1.1
2820 var IntegerRecord gsm_power :={31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19,
2821 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
2822 2, 1, 0};
2823 var IntegerRecord dcs_power :={28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15,
2824 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29};
2825 var IntegerRecord pcs_power :={15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30};
2826 var IntegerRecord rv;
2827
2828 select(band){
2829 case (BtsBand_allGSM){
2830 rv := gsm_power;
2831 min_dbm_level := {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19} ;
2832 max_dbm_level := {2, 1, 0};
2833 }
2834 case("DCS1800"){
2835 rv := dcs_power;
2836 min_dbm_level := {28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15};
2837 max_dbm_level := {0, 29}; // let's cheat here, assume MS_TXPWR_MAX_CCH might be being broadcast, so maybe no 29,30,31
2838 }
2839 case("PCS1900"){
2840 rv := pcs_power;
2841 min_dbm_level := {15};
2842 max_dbm_level := {30};
2843 }
2844 }
2845
2846 return rv;
2847}
2848
2849private function f_vty_get_bts0_band() runs on test_CT return BtsBand {
2850 return f_vty_transceive_match_regex(BTSVTY, "show bts 0", "BTS 0 is of \w+ type in band (\w+),*", 0);
2851}
2852
2853testcase TC_rsl_ms_pwr_dyn_ass_updown() runs on test_CT {
2854 var ConnHdlr vc_conn;
2855 var ConnHdlrPars pars;
2856 f_init();
2857 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2858 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2859 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2860 pars.bts0_band := f_vty_get_bts0_band();
2861 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_ass_updown), pars, trxc_comp := true);
2862 vc_conn.done;
2863 }
2864 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2865 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2866}
2867
2868testcase TC_rsl_ms_pwr_dyn_up() runs on test_CT {
2869 var ConnHdlr vc_conn;
2870 var ConnHdlrPars pars;
2871 f_init();
2872 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2873 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2874 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2875 pars.bts0_band := f_vty_get_bts0_band();
2876 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_up), pars, trxc_comp := true);
2877 vc_conn.done;
2878 }
2879 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2881}
2882
2883testcase TC_rsl_ms_pwr_dyn_max() runs on test_CT {
2884 var ConnHdlr vc_conn;
2885 var ConnHdlrPars pars;
2886 f_init();
2887 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -10");
2888 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2889 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2890 pars.bts0_band := f_vty_get_bts0_band();
2891 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_max), pars, trxc_comp := true);
2892 vc_conn.done;
2893 }
2894 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2895 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2896}
2897
2898testcase TC_rsl_ms_pwr_dyn_down() runs on test_CT {
2899 var ConnHdlr vc_conn;
2900 var ConnHdlrPars pars;
2901 f_init();
2902 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2903 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2904 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2905 pars.bts0_band := f_vty_get_bts0_band();
2906 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_down), pars, trxc_comp := true);
2907 vc_conn.done;
2908 }
2909 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2910 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2911}
2912
Eric Wild280ccb82019-06-17 11:11:52 +02002913testcase TC_rsl_ms_pwr_dyn_active() runs on test_CT {
2914 var ConnHdlr vc_conn;
2915 var ConnHdlrPars pars;
2916 f_init();
2917 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2918 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2919 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2920 pars.bts0_band := f_vty_get_bts0_band();
2921 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active), pars, trxc_comp := true);
2922 vc_conn.done;
2923 }
2924 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2925 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2926}
2927
Eric Wild095024b2019-06-17 15:08:57 +02002928testcase TC_rsl_ms_pwr_dyn_active2() runs on test_CT {
2929 var ConnHdlr vc_conn;
2930 var ConnHdlrPars pars;
2931 f_init();
2932 f_vty_config(BTSVTY, "phy 0", "osmotrx ms-power-loop -100");
2933 for (var integer tn := 1; tn <= 1; tn := tn+1) {
2934 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2935 pars.bts0_band := f_vty_get_bts0_band();
2936 vc_conn := f_start_handler(refers(f_TC_rsl_ms_pwr_dyn_active2), pars, trxc_comp := true);
2937 vc_conn.done;
2938 }
2939 f_vty_config(BTSVTY, "phy 0", "no osmotrx ms-power-loop");
2940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2941}
2942
Harald Welte70767382018-02-21 12:16:40 +01002943testcase TC_meas_res_sign_tchf() runs on test_CT {
2944 var ConnHdlr vc_conn;
2945 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002946 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002947 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2948 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002949 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2950 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002951 vc_conn.done;
2952 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002953 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002954}
2955testcase TC_meas_res_sign_tchh() runs on test_CT {
2956 var ConnHdlr vc_conn;
2957 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002958 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002959 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2960 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002961 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2962 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002963 vc_conn.done;
2964 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002965 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002966}
2967testcase TC_meas_res_sign_sdcch4() runs on test_CT {
2968 var ConnHdlr vc_conn;
2969 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002970 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002971 for (var integer ss := 0; ss <= 3; ss := ss+1) {
2972 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002973 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2974 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002975 vc_conn.done;
2976 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002978}
2979testcase TC_meas_res_sign_sdcch8() runs on test_CT {
2980 var ConnHdlr vc_conn;
2981 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002982 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002983 for (var integer ss := 0; ss <= 7; ss := ss+1) {
2984 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
Eric Wild5b9ef142019-07-11 19:28:02 +02002985 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
2986 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01002987 vc_conn.done;
2988 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002989 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01002990}
Harald Welte685d5982018-02-27 20:42:05 +01002991testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
2992 var ConnHdlr vc_conn;
2993 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002994 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01002995 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
2996 for (var integer ss := 0; ss <= 1; ss := ss+1) {
2997 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
2998 pars.l1_pars.toa256_enabled := true;
2999 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
3000 vc_conn.done;
3001 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003002 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01003003}
3004
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003005/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
3006 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003007private function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003008 var L1ctlDlMessage l1_dl;
3009 var RSL_IE_MS_Power ms_power;
3010 var RSL_Message rsl;
3011 var uint5_t power_level := 0;
3012
3013 f_l1_tune(L1CTL);
3014 RSL.clear;
3015
3016 f_est_dchan();
3017
3018 ms_power.reserved := 0;
3019 ms_power.fpc_epc := false;
3020
3021 /* Send the first power control command. This will disable any BTS/TRX
3022 * internal power control and switch the MS (which is not in scope of
3023 * this test) to a constant power level. We start with a power level
3024 * of 0 */
3025 ms_power.power_level := power_level;
3026 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3027 RSL.send(rsl);
3028
3029 alt {
3030
3031 /* Pick all SACCH blocks for checking */
3032 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3033
3034 /* The first byte of the L1 header contains the power level.
3035 * The reserved bits and the fpc bit is set to 0, so we may
3036 * compare directly. */
3037 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
3038 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
3039 }
3040
3041 /* Signal a new power level via RSL for the next turn. */
3042 if (power_level < 31) {
3043 power_level := power_level + 1;
3044 ms_power.power_level := power_level;
3045 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
3046 RSL.send(rsl);
3047 repeat;
3048 }
3049
3050 }
3051
3052 /* Ignore all other blocks */
3053 [] L1CTL.receive { repeat; }
3054
3055 }
3056
3057 f_rsl_chan_deact();
3058 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3059
3060 setverdict(pass);
3061}
3062
3063testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
3064 var ConnHdlr vc_conn;
3065 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003066 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01003067
3068 for (var integer tn := 1; tn <= 4; tn := tn+1) {
3069 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
3070 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
3071 vc_conn.done;
3072 }
3073 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3074}
Harald Welte70767382018-02-21 12:16:40 +01003075
Pau Espin Pedrol188bfd22020-06-03 20:32:45 +02003076/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
Eric Wild6833cc92019-05-23 19:34:44 +02003077TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003078private function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
Eric Wild6833cc92019-05-23 19:34:44 +02003079 var L1ctlDlMessage l1_dl;
3080 var uint5_t ta_to_test := 16;
3081
3082
3083 f_l1_tune(L1CTL);
3084 RSL.clear;
3085
3086 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiydc8db922019-06-04 21:58:15 +07003087 f_trxc_fake_toffs256(ta_to_test*256);
Eric Wild6833cc92019-05-23 19:34:44 +02003088
3089 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
3090
3091
3092 alt {
3093
3094 /* Pick all SACCH blocks for checking */
3095 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3096
3097 /* The second byte of the L1 header contains the TA. */
3098 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
3099 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
3100 }
3101
3102 }
3103
3104 /* Ignore all other blocks */
3105 [] L1CTL.receive { repeat; }
3106
3107 }
3108
3109 f_rsl_chan_deact();
3110 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3111
3112 setverdict(pass);
3113}
3114
3115testcase TC_rsl_chan_initial_ta() runs on test_CT {
3116 var ConnHdlr vc_conn;
3117 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003118 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02003119 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07003120 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
3121 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02003122 vc_conn.done;
3123 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3124}
3125
Eric Wilde57e1a62019-05-28 13:30:55 +02003126/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07003127private function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
Eric Wilde57e1a62019-05-28 13:30:55 +02003128 var L1ctlDlMessage l1_dl;
3129 var uint5_t ms_power_level := 7;
3130
3131 var RSL_IE_MS_Power ms_power;
3132 ms_power.reserved := 0;
3133 ms_power.fpc_epc := false;
3134 ms_power.power_level := ms_power_level;
3135
3136 f_l1_tune(L1CTL);
3137 RSL.clear;
3138
3139 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
3140
3141 timer T := 1.0;
3142 T.start;
3143 alt {
3144 /* Pick all SACCH blocks for checking */
3145 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
3146 /* The first byte of the L1 header contains the power level.. */
3147 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
3148 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3149 }
3150 }
3151 /* Ignore all other blocks */
3152 [] L1CTL.receive { repeat; }
3153 [] T.timeout {
3154 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
3155 }
3156 }
3157
3158 f_rsl_chan_deact();
3159 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3160 setverdict(pass);
3161}
3162
3163testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
3164 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3165 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
3166}
3167
Harald Welte0472ab42018-03-12 15:02:26 +01003168/* 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 +01003169private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01003170 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01003171 RSL.clear;
3172
3173 f_est_dchan();
3174 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01003175 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01003176
3177 timer T := 40.0;
3178 T.start;
3179 alt {
3180 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
3181 setverdict(pass)
3182 }
3183 [] RSL.receive { repeat };
3184 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003185 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01003186 }
3187 }
3188 f_rsl_chan_deact();
3189}
3190testcase TC_conn_fail_crit() runs on test_CT {
3191 var ConnHdlr vc_conn;
3192 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02003193 f_init();
Harald Welte70767382018-02-21 12:16:40 +01003194 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
3195 pars.t_guard := 60.0;
3196 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
3197 vc_conn.done;
3198}
3199
Harald Welte93640c62018-02-25 16:59:33 +01003200/***********************************************************************
3201 * Paging
3202 ***********************************************************************/
3203
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003204private function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
Harald Welte68e495b2018-02-25 00:05:57 +01003205 if (tmsi == 'FFFFFFFF'O) {
3206 return true;
3207 } else {
3208 return false;
3209 }
3210}
Harald Welte70767382018-02-21 12:16:40 +01003211
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003212private type record allowedFn { integer frame_nr }
3213private template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
3214private template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
3215private template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
3216private template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
3217private template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
3218private template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
3219private template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
3220private template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
3221private function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
Philipp Maier82cb0b12018-08-31 14:41:39 +02003222{
3223 var integer frame_nr_51;
3224 frame_nr_51 := frame_nr mod 51
3225
3226 var allowedFn fn_check;
3227 fn_check.frame_nr := frame_nr_51;
3228
3229 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003230 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003231 return;
3232 }
3233
3234 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
3235 return;
3236 }
3237 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
3238 return;
3239 }
3240 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
3241 return;
3242 }
3243 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
3244 return;
3245 }
3246 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
3247 return;
3248 }
3249 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
3250 return;
3251 }
3252 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
3253 return;
3254 }
3255 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
3256 return;
3257 }
3258
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003259 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02003260 return;
3261}
3262
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003263private altstep as_l1_count_paging(inout integer num_paging_rcv_msgs,
3264 inout integer num_paging_rcv_ids,
3265 PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01003266runs on test_CT {
3267 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01003268 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003269 repeat;
3270 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01003271 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01003272 var octetstring without_plen :=
3273 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
3274 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02003275
3276 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
3277
Vadim Yanitskiy36aa07c2020-03-31 14:33:43 +07003278 if (match(rr, tr_PAGING_REQ1(tr_MI_LV(t_MI_NoIdentity(?))))) {
3279 /* Ignore empty RR Paging Request (PCH filling) messages.
3280 * TODO: does it make sense to count them? */
3281 } else if (match(rr, tr_PAGING_REQ1)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003282 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3283 num_paging_rcv_ids := num_paging_rcv_ids + 1;
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003284 if (ispresent(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003285 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3286 }
3287 } else if (match(rr, tr_PAGING_REQ2)) {
3288 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3289 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
3290 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3291 }
3292 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
3293 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3294 }
Vadim Yanitskiyd665c232020-03-30 14:40:41 +07003295 if (ispresent(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003296 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3297 }
3298 } else if (match(rr, tr_PAGING_REQ3)) {
3299 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
3300 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
3301 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3302 }
3303 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
3304 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3305 }
3306 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
3307 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3308 }
3309 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
3310 num_paging_rcv_ids := num_paging_rcv_ids + 1;
3311 }
3312 }
3313 repeat;
3314 }
3315}
3316
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003317private type record PagingTestCfg {
Harald Welte68e495b2018-02-25 00:05:57 +01003318 boolean combined_ccch,
3319 integer bs_ag_blks_res,
3320 float load_factor,
3321 boolean exp_load_ind,
3322 boolean exp_overload,
3323 boolean use_tmsi
3324}
3325
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003326private type record PagingTestState {
Harald Welte68e495b2018-02-25 00:05:57 +01003327 integer num_paging_sent,
3328 integer num_paging_rcv_msgs,
3329 integer num_paging_rcv_ids,
3330 integer num_overload
3331}
3332
Harald Welte68e495b2018-02-25 00:05:57 +01003333/* Helper function for paging related testing */
3334private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02003335 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003336 f_init_l1ctl();
3337 f_l1_tune(L1CTL);
3338
3339 var PagingTestState st := {
3340 num_paging_sent := 0,
3341 num_paging_rcv_msgs := 0,
3342 num_paging_rcv_ids := 0,
3343 num_overload := 0
3344 };
3345
3346 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
3347 var float max_pch_imsi_per_sec;
3348 if (cfg.use_tmsi) {
3349 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
3350 } else {
3351 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
3352 }
3353 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
3354 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003355 var float time_total := 20.0;
3356 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
3357 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01003358
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003359 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
3360 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01003361
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003362 timer T_itv := 0.0;
3363 T_itv.start;
3364 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01003365 alt {
3366 /* check for presence of CCCH LOAD IND (paging load) */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003367 [cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Harald Welte68e495b2018-02-25 00:05:57 +01003368 st.num_overload := st.num_overload + 1;
3369 repeat;
3370 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003371 [not cfg.exp_overload] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003372 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01003373 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003374 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
Harald Welte68e495b2018-02-25 00:05:57 +01003375 log("Rx LOAD_IND");
3376 /* FIXME: analyze/verify interval + contents */
3377 repeat;
3378 }
3379 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02003380 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003381 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003382 [] T_itv.timeout {
3383 /* Send paging cmds based on elapsed time */
3384 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
3385 while (st.num_paging_sent < new_sent) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003386 var MobileIdentityV mi;
3387
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003388 /* build mobile Identity */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003389 if (cfg.use_tmsi) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003390 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003391 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003392 mi := valueof(ts_MI_IMSI(f_gen_imsi(st.num_paging_sent)));
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003393 }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003394
3395 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003396 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 +02003397
3398 st.num_paging_sent := st.num_paging_sent + 1;
3399 }
3400 if (st.num_paging_sent < pkt_total) {
3401 /* Wait for interval to next PAGING COMMAND */
3402 var float time_now := T_total.read;
3403 var float next_sched := int2float(st.num_paging_sent)*interval;
3404 if (next_sched > time_now) {
3405 T_itv.start(next_sched - time_now);
3406 } else {
3407 T_itv.start(0.0);
3408 }
3409 } else {
3410 /* We are done, no need to keep counting */
3411 T_total.stop;
3412 }
3413 }
3414 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01003415 }
3416 }
3417
3418 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
3419 timer T_wait := 18.0;
3420 T_wait.start;
3421 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02003422 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01003423 [] L1CTL.receive { repeat; }
3424 /* 65535 == empty paging queue, we can terminate*/
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003425 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
3426 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
Harald Welte68e495b2018-02-25 00:05:57 +01003427 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01003429 }
Harald Welte68e495b2018-02-25 00:05:57 +01003430 }
3431
3432 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
3433 " rcvd_ids=", st.num_paging_rcv_ids);
3434 return st;
3435}
3436
3437/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
3438 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3439 * - that CCCH LOAD IND (PCH) are being generated
3440 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3441testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003442 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003443 var PagingTestCfg cfg := {
3444 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003445 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003446 load_factor := 0.8,
3447 exp_load_ind := true,
3448 exp_overload := false,
3449 use_tmsi := false
3450 };
3451 var PagingTestState st := f_TC_paging(cfg);
3452 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003453 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3454 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003455 } else {
3456 setverdict(pass);
3457 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003459}
3460
3461/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
3462 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
3463 * - that CCCH LOAD IND (PCH) are being generated
3464 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3465testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003466 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003467 var PagingTestCfg cfg := {
3468 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003469 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003470 load_factor := 0.8,
3471 exp_load_ind := true,
3472 exp_overload := false,
3473 use_tmsi := true
3474 };
3475 var PagingTestState st := f_TC_paging(cfg);
3476 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003477 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
3478 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01003479 } else {
3480 setverdict(pass);
3481 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003483}
3484
3485/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
3486 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3487 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3488 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3489testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003490 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003491 var PagingTestCfg cfg := {
3492 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003493 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003494 load_factor := 2.0,
3495 exp_load_ind := true,
3496 exp_overload := true,
3497 use_tmsi := false
3498 };
3499 var PagingTestState st := f_TC_paging(cfg);
3500 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
3501 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003502 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003503 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003504 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 +01003505 } else {
3506 setverdict(pass);
3507 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003508 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003509}
3510
3511/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
3512 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
3513 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
3514 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
3515testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02003516 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01003517 var PagingTestCfg cfg := {
3518 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02003519 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01003520 load_factor := 2.0,
3521 exp_load_ind := true,
3522 exp_overload := true,
3523 use_tmsi := true
3524 };
3525 var PagingTestState st := f_TC_paging(cfg);
3526 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
3527 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02003528 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01003529 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003530 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 +01003531 } else {
3532 setverdict(pass);
3533 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003534 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003535}
3536
3537
Harald Welte93640c62018-02-25 16:59:33 +01003538/***********************************************************************
3539 * Immediate Assignment / AGCH
3540 ***********************************************************************/
Vadim Yanitskiya9eeb7b2020-05-27 01:42:49 +07003541private const MobileAllocation c_MA_null := {
Harald Weltee8d750e2018-06-10 21:41:35 +02003542 len := 0,
3543 ma := ''B
3544}
Harald Welte93640c62018-02-25 16:59:33 +01003545
Harald Weltee8d750e2018-06-10 21:41:35 +02003546private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
3547 return int2str(num_tx) & " sent, "
3548 & int2str(num_rx) & " received, "
3549 & int2str(num_del) & " deleted";
3550}
3551
3552private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
3553 var L1ctlDlMessage l1_dl;
3554 timer T := 10.0;
3555 var integer num_tx := 0;
3556 var integer num_rx := 0;
3557 var integer num_del := 0;
3558 var charstring res_str;
3559 var float rx_ratio;
3560
Harald Welte10474062019-05-30 16:48:17 +02003561 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02003562 f_init_l1ctl();
3563 f_l1_tune(L1CTL);
3564
3565 for (var integer i := 0; i < num_total; i := i+1) {
Vadim Yanitskiyf7181ed2020-07-14 20:12:02 +07003566 var ChannelDescription ch_desc := valueof(ts_ChanDescH0(t_RslChanNr_SDCCH4(0, 0), mp_trx0_arfcn));
Harald Weltee8d750e2018-06-10 21:41:35 +02003567 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
3568 var octetstring ia_enc := enc_GsmRrMessage(ia);
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003569 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02003570 num_tx := num_tx+1;
3571 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01003572 }
3573 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02003574 T.start;
3575 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07003576 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
Harald Weltee8d750e2018-06-10 21:41:35 +02003577 num_del := num_del+1;
3578 repeat;
3579 }
3580 [] RSL_CCHAN.receive {
3581 repeat;
3582 }
3583 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
Harald Weltee8d750e2018-06-10 21:41:35 +02003584 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
3585 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
3586 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003587 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02003588 } else {
3589 num_rx := num_rx+1;
3590 }
3591 repeat;
3592 }
3593 [] L1CTL.receive { repeat; }
3594 [] T.timeout { }
3595 }
3596 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
3597 log("AGCH test: " & res_str);
3598 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003599 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02003600 }
3601 rx_ratio := int2float(num_rx) / int2float(num_tx);
3602 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003603 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 +02003604 } else {
3605 setverdict(pass);
3606 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003608}
3609
Harald Weltee8d750e2018-06-10 21:41:35 +02003610/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
3611testcase TC_imm_ass_1000_20ms() runs on test_CT {
3612 f_TC_imm_ass(1000, 0.02, 0.25);
3613}
3614
3615/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
3616testcase TC_imm_ass_200_0ms() runs on test_CT {
3617 f_TC_imm_ass(200, 0.0, 0.05);
3618}
3619
3620/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
3621testcase TC_imm_ass_200_76ms() runs on test_CT {
3622 f_TC_imm_ass(150, 0.076, 1.00);
3623}
3624
3625
3626
Harald Welte48494ca2018-02-25 16:59:50 +01003627/***********************************************************************
3628 * BCCH
3629 ***********************************************************************/
3630
3631/* tuple of Frame Number + decoded SI */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003632private type record SystemInformationFn {
Harald Welte48494ca2018-02-25 16:59:50 +01003633 GsmFrameNumber frame_number,
3634 SystemInformation si
3635}
3636
3637/* an arbitrary-length vector of decoded SI + gsmtap header */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003638private type record of SystemInformationFn SystemInformationVector;
Harald Welte48494ca2018-02-25 16:59:50 +01003639
3640/* an array of SI-vectors indexed by TC value */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003641private type SystemInformationVector SystemInformationVectorPerTc[8];
Harald Welte48494ca2018-02-25 16:59:50 +01003642
3643/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003644private function f_si_vecslot_contains(SystemInformationVector arr,
3645 RrMessageType key,
3646 boolean bcch_ext := false)
3647return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003648 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3649 var integer fn_mod51 := arr[i].frame_number mod 51;
3650 if (not bcch_ext and fn_mod51 == 2 or
3651 bcch_ext and fn_mod51 == 6) {
3652 if (arr[i].si.header.message_type == key) {
3653 return true;
3654 }
3655 }
3656 }
3657 return false;
3658}
3659
3660/* 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 +07003661private function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr,
3662 integer tc, RrMessageType key,
3663 boolean ext_bcch := false)
3664{
Harald Welte48494ca2018-02-25 16:59:50 +01003665 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003666 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003667 }
3668}
3669
3670/* check if a given SI vector contains given SI type at least once on any TC */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003671private function f_si_vec_contains(SystemInformationVectorPerTc arr,
3672 RrMessageType key)
3673return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003674 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
3675 if (f_si_vecslot_contains(arr[tc], key) or
3676 f_si_vecslot_contains(arr[tc], key, true)) {
3677 return true;
3678 }
3679 }
3680 return false;
3681}
3682
3683/* determine if a given SI vector contains given SI type at least N of M times */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003684private function f_si_vecslot_contains_n_of_m(SystemInformationVector arr,
3685 RrMessageType key,
3686 boolean bcch_ext := false,
3687 integer n := 1, integer m := 4)
3688return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003689 var integer count := 0;
3690 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003691 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01003692 }
3693 for (var integer i:= 0; i < m; i := i + 1) {
3694 var integer fn_mod51 := arr[i].frame_number mod 51;
3695 if (not bcch_ext and fn_mod51 == 2 or
3696 bcch_ext and fn_mod51 == 6) {
3697 if (arr[i].si.header.message_type == key) {
3698 count := count + 1;
3699 }
3700 }
3701 }
3702 if (count >= n) {
3703 return true;
3704 } else {
3705 return false;
3706 }
3707}
3708
3709/* 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 +07003710private function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr,
3711 integer tc, RrMessageType key,
3712 boolean ext_bcch := false,
3713 integer n, integer m)
3714{
Harald Welte48494ca2018-02-25 16:59:50 +01003715 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003716 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003717 }
3718}
3719
3720/* determine if a given SI vector contains given SI type at least once */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003721private function f_si_vecslot_contains_only(SystemInformationVector arr,
3722 RrMessageType key,
3723 boolean bcch_ext := false)
3724return boolean {
Harald Welte48494ca2018-02-25 16:59:50 +01003725 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
3726 var integer fn_mod51 := arr[i].frame_number mod 51;
3727 if (not bcch_ext and fn_mod51 == 2 or
3728 bcch_ext and fn_mod51 == 6) {
3729 if (arr[i].si.header.message_type != key) {
3730 return false;
3731 }
3732 }
3733 }
3734 return true;
3735}
3736
3737/* ensure a given TC slot of the SI vector contains only given SI type */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003738private function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr,
3739 integer tc, RrMessageType key,
3740 boolean ext_bcch := false)
3741{
Harald Welte48494ca2018-02-25 16:59:50 +01003742 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003743 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01003744 }
3745}
3746
3747/* SI configuration of cell, against which we validate actual SI messages */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003748private type set SystemInformationConfig {
Harald Welte48494ca2018-02-25 16:59:50 +01003749 boolean bcch_extended,
3750 boolean si1_present,
3751 boolean si2bis_present,
3752 boolean si2ter_present,
3753 boolean si2quater_present,
3754 boolean si7_present,
3755 boolean si8_present,
3756 boolean si9_present,
3757 boolean si13_present,
3758 boolean si13alt_present,
3759 boolean si15_present,
3760 boolean si16_present,
3761 boolean si17_present,
3762 boolean si2n_present,
3763 boolean si21_present,
3764 boolean si22_present
3765}
3766
3767/* 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 +07003768private function f_validate_si_scheduling(SystemInformationConfig cfg,
3769 SystemInformationVectorPerTc si_per_tc)
3770{
Harald Welte48494ca2018-02-25 16:59:50 +01003771 var integer i;
3772 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
3773 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003774 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01003775 }
3776 }
3777 if (cfg.si1_present) {
3778 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
3779 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
3780 * when TC = 0, it can assume that System Information Type 1 is not in use. */
3781 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3782 /* make sure *ALL* contain SI1 */
3783 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
3784 }
3785 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
3786 /* iii) A SI 2 message will be sent at least every time TC = 1 */
3787 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
3788 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
3789 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
3790 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
3791
3792 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
3793 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
3794 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
3795 * consecutive occurrences of TC = 4. */
3796 if (cfg.si2bis_present and not cfg.si2ter_present) {
3797 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3798 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
3799 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
3800 } else if (cfg.si2ter_present and cfg.si2bis_present) {
3801 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
3802 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
3803 }
3804
3805 if (cfg.si7_present or cfg.si8_present) {
3806 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
3807 * if System Information type 4 does not contain all information needed for cell
3808 * selection and reselection. */
3809 if (not cfg.bcch_extended) {
3810 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
3811 }
3812 if (cfg.si7_present) {
3813 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
3814 }
3815 if (cfg.si8_present) {
3816 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
3817 }
3818 }
3819
3820 if (cfg.si2quater_present) {
3821 /* iii) System information type 2 quater is sent if needed, as determined by the system
3822 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
3823 * and 2ter are used, otherwise it shall be sent at least once within any of 4
3824 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
3825 * within any of 4 consecutive occurrences of TC = 5. */
3826 if (not (cfg.bcch_extended)) {
3827 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
3828 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
3829 } else {
3830 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
3831 }
3832 } else {
3833 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
3834 }
3835 }
3836 if (cfg.si9_present) {
3837 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
3838 * in system information type 3 as defined in 3GPP TS 44.018. */
3839 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
3840 }
3841 if (cfg.si13_present) {
3842 /* vii) System Information type 13 is only related to the GPRS service. System Information
3843 * Type 13 need only be sent if GPRS support is indicated in one or more of System
3844 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
3845 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
3846 * In the case that the message is sent on the BCCH Norm, it is sent at least once
3847 * within any of 4 consecutive occurrences of TC=4. */
3848 if (not cfg.bcch_extended) {
3849 log("not-bccch-extended");
3850 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
3851 } else {
3852 log("bccch-extended");
3853 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
3854 }
3855 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003856 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003857 }
3858 }
3859 if (cfg.si16_present or cfg.si17_present) {
3860 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
3861 * should not be sent in a cell where network sharing is used (see rule xv). */
3862 if (cfg.si22_present) {
3863 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3864 }
3865 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003866 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003867 }
3868 if (not cfg.bcch_extended) {
3869 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
3870 }
3871 if (cfg.si16_present) {
3872 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
3873 }
3874 if (cfg.si17_present) {
3875 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
3876 }
3877 }
3878
3879 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
3880 * broadcast information. The frequency with which they are sent is determined by the
3881 * system operator. System Information type 9 identifies the scheduling of System
3882 * Information type 18 and 20 messages. */
3883
3884 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
3885 * Information Type 19 is present, then its scheduling shall be indicated in System
3886 * Information Type 9. */
3887
3888 if (cfg.si15_present) {
3889 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
3890 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
3891 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
3892 * 4 consecutive occurrences of TC = 1. */
3893 if (not cfg.bcch_extended) {
3894 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
3895 } else {
3896 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
3897 }
3898 }
3899 if (cfg.si13alt_present) {
3900 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
3901 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
3902 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
3903 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
3904 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
3905 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
3906 * of TC = 4. */
3907 if (cfg.si13_present) {
3908 testcase.stop("Error: Cannot have SI13alt and SI13");
3909 }
3910 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01003912 }
3913 if (not cfg.bcch_extended) {
3914 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
3915 } else {
3916 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
3917 }
3918 }
3919 if (cfg.si2n_present) {
3920 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
3921 * as determined by the system operator. In the case that the message is sent on the
3922 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
3923 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
3924 * consecutive occurrences of TC = 4. */
3925 if (not cfg.bcch_extended) {
3926 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
3927 } else {
3928 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
3929 }
3930 }
3931 if (cfg.si21_present) {
3932 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
3933 * determined by the system operator. If Extended Access Barring is in use in the cell
3934 * then this message is sent at least once within any of 4 consecutive occurrences of
3935 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
3936 * cell then this message shall only be sent on BCCH Ext. */
3937 if (not cfg.bcch_extended) {
3938 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
3939 } else {
3940 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
3941 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003942 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01003943 }
3944 }
3945 }
3946 if (cfg.si22_present) {
3947 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
3948 * should not be sent in a cell where SoLSA is used (see rule viii). System
3949 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
3950 * =2 and TC=6. */
3951 if (cfg.si16_present or cfg.si17_present) {
3952 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
3953 }
3954 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
3955 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003956 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01003957 }
3958 if (not cfg.bcch_extended) {
3959 testcase.stop("Error: SI22 requires BCCH Extd!");
3960 } else {
3961 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
3962 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
3963 }
3964 }
3965}
3966
3967/* sample Systme Information for specified duration via L1CTL */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07003968private function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0)
3969return SystemInformationVectorPerTc {
Harald Welte48494ca2018-02-25 16:59:50 +01003970 timer T := duration;
3971 var SystemInformationVectorPerTc si_per_tc;
3972 var L1ctlDlMessage l1_dl;
3973
3974 /* initialize all per-TC vectors empty */
3975 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
3976 si_per_tc[i] := {};
3977 }
3978
3979 /* flush all previous L1 queued msgs */
3980 pt.clear;
3981
3982 T.start;
3983 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003984 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003985 var SystemInformationFn sig := { frame_number := l1_dl.dl_info.frame_nr };
3986 if (dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, sig.si) != 0) {
3987 log("Ignoring non-RR or invalid SI ", l1_dl);
Harald Welte48494ca2018-02-25 16:59:50 +01003988 repeat;
3989 }
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07003990
Harald Welte48494ca2018-02-25 16:59:50 +01003991 var integer tc := f_gsm_compute_tc(sig.frame_number);
3992 log("SI received at TC=", tc, ": ", sig.si);
3993 /* append to the per-TC bucket */
3994 si_per_tc[tc] := si_per_tc[tc] & { sig };
3995 repeat;
3996 }
3997 [] pt.receive { repeat; }
3998 [] T.timeout { }
3999 }
4000
4001 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
4002 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
4003 }
4004 log("si_per_tc=", si_per_tc);
4005 return si_per_tc;
4006}
4007
4008/* helper function: Set given SI via RSL + validate scheduling.
4009 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004010private function f_TC_si_sched() runs on test_CT {
Harald Welte48494ca2018-02-25 16:59:50 +01004011 var SystemInformationVectorPerTc si_per_tc;
4012 f_init_l1ctl();
4013 f_l1_tune(L1CTL);
4014
4015 /* Sample + Validate Scheduling */
4016 si_per_tc := f_l1_sample_si(L1CTL);
4017 f_validate_si_scheduling(si_cfg, si_per_tc);
4018
4019 setverdict(pass);
4020}
4021
4022testcase TC_si_sched_default() runs on test_CT {
4023 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01004024 /* 2+3+4 are mandatory and set in f_init() */
4025 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004026 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01004027}
4028
4029testcase TC_si_sched_1() runs on test_CT {
4030 f_init();
4031 si_cfg.si1_present := true;
4032 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004033 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004035}
4036
4037testcase TC_si_sched_2bis() runs on test_CT {
4038 f_init();
4039 si_cfg.si2bis_present := true;
4040 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4041 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004042 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004043}
4044
4045testcase TC_si_sched_2ter() runs on test_CT {
4046 f_init();
4047 si_cfg.si2ter_present := true;
4048 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4049 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004050 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004051}
4052
4053testcase TC_si_sched_2ter_2bis() runs on test_CT {
4054 f_init();
4055 si_cfg.si2bis_present := true;
4056 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4057 si_cfg.si2ter_present := true;
4058 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4059 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004061}
4062
4063testcase TC_si_sched_2quater() runs on test_CT {
4064 f_init();
4065 si_cfg.si2quater_present := true;
4066 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4067 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004069}
4070
4071testcase TC_si_sched_13() runs on test_CT {
4072 f_init();
4073 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004074 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004075 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004076 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004077}
4078
4079testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
4080 f_init();
4081 si_cfg.si2bis_present := true;
4082 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
4083 si_cfg.si2ter_present := true;
4084 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
4085 si_cfg.si2quater_present := true;
4086 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
4087 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02004088 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01004089 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01004091}
4092
4093
Harald Welte68e495b2018-02-25 00:05:57 +01004094testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004095 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01004096 /* FIXME: enable / disable individual BCCH info */
4097 //ts_RSL_BCCH_INFO(si_type, info);
4098 /* expect no ERROR REPORT after either of them *
4099 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01004101}
4102
Harald Welte93640c62018-02-25 16:59:33 +01004103/***********************************************************************
4104 * Low-Level Protocol Errors / ERROR REPORT
4105 ***********************************************************************/
4106
Harald Welte01d982c2018-02-25 01:31:40 +01004107private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
4108 timer T := 5.0;
4109 T.start;
4110 alt {
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004111 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
Harald Welte01d982c2018-02-25 01:31:40 +01004112 setverdict(pass);
4113 }
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004114 [] RSL_CCHAN.receive(tr_ASP_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004116 }
4117 [] RSL_CCHAN.receive {
4118 repeat;
4119 }
4120 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004121 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01004122 }
4123 }
4124}
4125
4126/* Provoke a protocol error (message too short) and match on ERROR REPORT */
4127testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004128 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004129 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4130 rsl.ies := omit;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004131 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004132
4133 f_exp_err_rep(RSL_ERR_PROTO);
4134}
4135
4136/* Provoke a mandatory IE error and match on ERROR REPORT */
4137testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004138 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004139
4140 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4141 rsl.ies := { rsl.ies[0] };
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004142 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004143
4144 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
4145}
4146
4147/* Provoke an IE content error and match on ERROR REPORT */
4148testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02004149 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01004150 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4151 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004152 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl));
Harald Welte01d982c2018-02-25 01:31:40 +01004153
4154 f_exp_err_rep(RSL_ERR_IE_CONTENT);
4155}
4156
Harald Welteee25aae2019-05-19 14:32:37 +02004157/* attempt to activate channel with wrong RSL Message Discriminator IE */
4158function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
4159 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4160 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
4161 RSL.send(rsl);
4162 f_rslem_unregister(0, g_chan_nr);
4163}
4164testcase TC_err_rep_wrong_mdisc() runs on test_CT {
4165 var ConnHdlr vc_conn;
4166 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4167
Harald Welte10474062019-05-30 16:48:17 +02004168 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004169
4170 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
4171 vc_conn.done;
4172 f_exp_err_rep(RSL_ERR_MSG_DISCR);
4173
4174 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4175}
4176
4177/* Send messages with wrong message type */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004178private function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004179 var template (value) RSL_Message rsl_tx;
4180 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
4181 rsl_tx.msg_type := RSL_MT_NOT_CMD;
4182 RSL.send(rsl_tx);
4183 f_rslem_unregister(0, g_chan_nr);
4184}
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004185private function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004186 var template (value) RSL_Message rsl_tx;
4187 /* we first have to activate the dedicated channel */
4188 f_rsl_chan_act(g_pars.chan_mode);
4189 /* ... to then send an invalid RLL message */
4190 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
4191 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
4192 RSL.send(rsl_tx);
4193 f_rslem_unregister(0, g_chan_nr);
4194}
4195testcase TC_err_rep_wrong_msg_type() runs on test_CT {
4196 var ConnHdlr vc_conn;
4197 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4198 var template (value) RSL_Message rsl_tx;
4199
Harald Welte10474062019-05-30 16:48:17 +02004200 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004201
4202 /* Common Channel with wrong message type */
4203 RSL_CCHAN.clear;
4204 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
4205 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004206 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004207 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4208
4209 /* TRX Management */
4210 RSL_CCHAN.clear;
4211 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
4212 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07004213 RSL_CCHAN.send(ts_ASP_RSL_UD(rsl_tx));
Harald Welteee25aae2019-05-19 14:32:37 +02004214 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4215
4216 /* Dedicated Channel */
4217 RSL_CCHAN.clear;
4218 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
4219 vc_conn.done;
4220 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4221
4222 /* RLL */
4223 RSL_CCHAN.clear;
4224 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
4225 vc_conn.done;
4226 f_exp_err_rep(RSL_ERR_MSG_TYPE);
4227}
4228
4229/* Send messages in wrong sequence (RLL to an inactive lchan) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004230private function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
Harald Welteee25aae2019-05-19 14:32:37 +02004231 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
4232 f_rslem_unregister(0, g_chan_nr);
4233}
4234testcase TC_err_rep_wrong_sequence() runs on test_CT {
4235 var ConnHdlr vc_conn;
4236 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
4237
Harald Welte10474062019-05-30 16:48:17 +02004238 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02004239
4240 RSL_CCHAN.clear;
4241 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
4242 vc_conn.done;
4243 f_exp_err_rep(RSL_ERR_MSG_SEQ);
4244}
4245
Harald Welte93640c62018-02-25 16:59:33 +01004246/***********************************************************************
4247 * IPA CRCX/MDCX/DLCS media stream handling
4248 ***********************************************************************/
4249
Harald Weltea871a382018-02-25 02:03:14 +01004250/* Send IPA DLCX to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004251private function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01004252 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4253 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01004254}
4255testcase TC_ipa_dlcx_not_active() runs on test_CT {
4256 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004257 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01004258 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
4259 vc_conn.done;
4260}
Harald Welte68e495b2018-02-25 00:05:57 +01004261
Harald Weltea3f1df92018-02-25 12:49:55 +01004262/* Send IPA CRCX twice to inactive lchan */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004263private function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004264 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4265 "IPA CRCX ACK");
4266 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
4267 "IPA CRCX NACK");
4268}
4269testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
4270 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004271 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004272 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
4273 vc_conn.done;
4274}
4275
4276/* Regular sequence of CRCX/MDCX/DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004277private function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Weltea3f1df92018-02-25 12:49:55 +01004278 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4279 "IPA CRCX ACK");
4280 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4281 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4282 var uint7_t rtp_pt2 := f_rnd_int(127);
4283 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4284 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4285 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4286 "IPA MDCX ACK");
4287 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4288 "IPA DLCX ACK");
4289}
4290testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
4291 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004292 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01004293 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
4294 vc_conn.done;
4295}
4296
Harald Welte3ae11da2018-02-25 13:36:06 +01004297/* Sequence of CRCX, 2x MDCX, DLCX */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004298private function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte3ae11da2018-02-25 13:36:06 +01004299 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
4300 "IPA CRCX ACK");
4301 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
4302 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
4303 var uint7_t rtp_pt2 := f_rnd_int(127);
4304 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
4305 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4306 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4307 "IPA MDCX ACK");
4308 /* Second MDCX */
4309 remote_ip := f_rnd_int(c_UINT32_MAX);
4310 remote_port := f_rnd_int(c_UINT16_MAX);
4311 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
4312 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
4313 "IPA MDCX ACK");
4314 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
4315 "IPA DLCX ACK");
4316}
4317testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
4318 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02004319 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01004320 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
4321 vc_conn.done;
4322}
4323
Harald Welte9912eb52018-02-25 13:30:15 +01004324/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07004325private function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
Harald Welte9912eb52018-02-25 13:30:15 +01004326 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
4327 "IPA CRCX NACK");
4328}
4329testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
4330 var ConnHdlrPars pars;
4331 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004332 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01004333
4334 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
4335 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4336 vc_conn.done;
4337
4338 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
4339 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
4340 vc_conn.done;
4341}
4342
Harald Weltea3f1df92018-02-25 12:49:55 +01004343
Harald Welte883340c2018-02-28 18:59:29 +01004344/***********************************************************************
4345 * PCU Socket related tests
4346 ***********************************************************************/
4347
Harald Welte07bd2d22019-05-25 11:03:30 +02004348/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004349friend 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 +01004350runs on test_CT {
4351 timer T := 3.0;
4352
4353 /* we don't expect any RTS.req before PDCH are active */
4354 T.start;
4355 alt {
4356 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004357 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01004358 }
4359 [] PCU.receive { repeat; }
4360 [] T.timeout { }
4361 }
4362
4363 /* Send PDCH activate request for known PDCH timeslot */
4364 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
4365
4366 /* we now expect RTS.req for this timeslot (only) */
4367 T.start;
4368 alt {
4369 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
4370 setverdict(pass);
4371 }
4372 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4373 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004374 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01004375 }
4376 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004377 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01004378 }
4379 [] PCU.receive { repeat; }
4380 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004381 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004382 }
4383 [not exp_success] T.timeout {
4384 setverdict(pass);
4385 }
4386 }
4387}
4388
Harald Welte07bd2d22019-05-25 11:03:30 +02004389/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02004390friend 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 +01004391runs on test_CT {
4392 timer T := 3.0;
4393
4394 /* Send PDCH activate request for known PDCH timeslot */
4395 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
4396
4397 PCU.clear;
4398 /* we now expect no RTS.req for this timeslot */
4399 T.start;
4400 alt {
4401 [] 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 +02004402 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01004403 }
4404 [] PCU.receive { repeat; }
4405 [] T.timeout {
4406 setverdict(pass);
4407 }
4408 }
4409}
4410
Harald Weltead033dc2019-05-25 17:28:16 +02004411friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004412 f_init();
4413 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
4414}
4415
Harald Welte883340c2018-02-28 18:59:29 +01004416/* PDCH activation via PCU socket; check for presence of RTS.req */
4417testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004418 f_init_pcu_test();
4419
Harald Welte883340c2018-02-28 18:59:29 +01004420 f_TC_pcu_act_req(0, 0, 7, true);
4421}
4422
4423/* PDCH activation via PCU socket on non-PDCU timeslot */
4424testcase TC_pcu_act_req_wrong_ts() 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, 1, false);
4428}
4429
4430/* PDCH activation via PCU socket on wrong BTS */
4431testcase TC_pcu_act_req_wrong_bts() 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(23, 0, 7, false);
4435}
4436
4437/* PDCH activation via PCU socket on wrong TRX */
4438testcase TC_pcu_act_req_wrong_trx() 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(0, 23, 7, false);
4442}
4443
4444/* PDCH deactivation via PCU socket; check for absence of RTS.req */
4445testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004446 f_init_pcu_test();
4447
Harald Welte883340c2018-02-28 18:59:29 +01004448 /* Activate PDCH */
4449 f_TC_pcu_act_req(0, 0, 7, true);
4450 f_sleep(1.0);
4451 /* and De-Activate again */
4452 f_TC_pcu_deact_req(0, 0, 7);
4453}
4454
4455/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
4456testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004457 f_init_pcu_test();
4458
Harald Welte883340c2018-02-28 18:59:29 +01004459 f_TC_pcu_deact_req(0, 0, 1);
4460}
4461
4462/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
4463testcase TC_pcu_ver_si13() runs on test_CT {
4464 const octetstring si13 := '00010203040506070909'O;
4465 var PCUIF_send_data sd;
4466 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01004467 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004468
4469 /* Set SI13 via RSL */
4470 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01004471
Harald Welte883340c2018-02-28 18:59:29 +01004472 T.start;
4473 alt {
4474 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
4475 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
4476 setverdict(pass);
4477 } else {
4478 repeat;
4479 }
4480 }
4481 [] PCU.receive { repeat; }
4482 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01004484 }
4485 }
4486}
4487
4488private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
4489
4490/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02004491friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01004492 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
4493runs on test_CT
4494{
4495 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
4496 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
4497}
4498
4499/* 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 +02004500friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
4501 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01004502runs on test_CT
4503{
4504 var PCUIF_send_data sd;
4505
4506 timer T := 3.0;
4507 T.start;
4508 alt {
4509 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
4510 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
4511 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
4512 sd.data.u.rts_req.fn, sapi, data);
4513 }
4514 [] PCU.receive { repeat; }
4515 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01004517 }
4518 }
4519}
4520
4521/* Send DATA.req on invalid BTS */
4522testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004523 var TfiUsfArr tua := f_TfiUsfArrInit();
4524 var octetstring data := '0000'O & f_rnd_octstring(21);
4525
4526 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004527
Harald Welte883340c2018-02-28 18:59:29 +01004528 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004529 f_TfiUsfArrSet(tua, 7, 0);
4530 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4531 f_sleep(1.0);
4532
4533 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004534}
4535
4536/* Send DATA.req on invalid TRX */
4537testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004538 var TfiUsfArr tua := f_TfiUsfArrInit();
4539 var octetstring data := '0000'O & f_rnd_octstring(21);
4540
4541 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004542
Harald Welte883340c2018-02-28 18:59:29 +01004543 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004544 f_TfiUsfArrSet(tua, 7, 0);
4545 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4546 f_sleep(1.0);
4547
4548 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004549}
4550
4551/* Send DATA.req on invalid timeslot */
4552testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004553 var TfiUsfArr tua := f_TfiUsfArrInit();
4554 var octetstring data := '0000'O & f_rnd_octstring(21);
4555
4556 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004557
Harald Welte883340c2018-02-28 18:59:29 +01004558 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02004559 f_TfiUsfArrSet(tua, 7, 0);
4560 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4561 f_sleep(1.0);
4562
4563 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004564}
4565
4566/* Send DATA.req on timeslot that hasn't been activated */
4567testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02004568 var TfiUsfArr tua := f_TfiUsfArrInit();
4569 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01004570
Harald Welte7162a612019-05-26 12:56:09 +02004571 f_virtphy_common();
4572
4573 f_TfiUsfArrSet(tua, 7, 0);
4574 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4575 f_sleep(1.0);
4576
4577 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01004578}
4579
Harald Weltead033dc2019-05-25 17:28:16 +02004580private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02004581 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
4582 boolean wait_rts := true)
4583runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004584 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02004585 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02004586
4587 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02004588 if (wait_rts) {
4589 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
4590 } else {
4591 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
4592 }
Harald Weltead033dc2019-05-25 17:28:16 +02004593
4594 T.start;
4595 alt {
Harald Welte7162a612019-05-26 12:56:09 +02004596 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02004597 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
4598 setverdict(pass);
4599 }
Harald Welte7162a612019-05-26 12:56:09 +02004600 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
4601 setverdict(fail, "Received unexpected ", rx_dl);
4602 }
Harald Weltead033dc2019-05-25 17:28:16 +02004603 [] L1CTL.receive {
4604 repeat;
4605 }
Harald Welte7162a612019-05-26 12:56:09 +02004606 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02004607 setverdict(fail, "Timeout waiting for ", data);
4608 }
Harald Welte7162a612019-05-26 12:56:09 +02004609 [not expect_data] T.timeout {
4610 setverdict(pass);
4611 }
Harald Weltead033dc2019-05-25 17:28:16 +02004612 }
4613}
4614
4615private function f_disable_dynamic_ts() runs on test_CT
4616{
4617 f_init_vty_bsc();
4618 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
4619 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
4620 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
4621 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01004622 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02004623}
4624
4625private function f_virtphy_common() runs on test_CT {
4626 f_disable_dynamic_ts();
4627 f_init_l1ctl();
4628 f_l1_tune(L1CTL);
4629}
4630
4631testcase TC_pcu_data_req_pdtch() runs on test_CT {
4632 var TfiUsfArr tua := f_TfiUsfArrInit();
4633 var octetstring data := '0000'O & f_rnd_octstring(21);
4634
4635 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004636
Harald Welte883340c2018-02-28 18:59:29 +01004637 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004638 f_TfiUsfArrSet(tua, 7, 0);
4639 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4640 f_sleep(1.0);
4641
4642 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01004643}
4644
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004645/* FIXME: PTTCH has nothing to do with TBFs */
Harald Welte883340c2018-02-28 18:59:29 +01004646testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02004647 var TfiUsfArr tua := f_TfiUsfArrInit();
4648 var octetstring data := '0000'O & f_rnd_octstring(21);
4649
4650 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01004651
Harald Welte883340c2018-02-28 18:59:29 +01004652 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02004653 f_TfiUsfArrSet(tua, 7, 0);
4654 f_L1CTL_TBF_CFG(L1CTL, false, tua);
4655 f_sleep(1.0);
4656
4657 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01004658}
4659
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004660private function f_TC_pcu_ptcch_ul(uint16_t ra)
4661runs on test_CT {
4662 var template PCUIF_Message pcu_rach_ind;
4663 var PCUIF_send_data sd;
4664 var GsmFrameNumber fn;
4665 timer T;
4666
4667 /* Send an Access Burst on PTCCH/U over the Um-interface */
4668 fn := f_L1CTL_RACH(L1CTL, ra := ra, combined := 0, offset := 0,
4669 chan_nr := ts_RslChanNr_PDCH(7),
4670 link_id := ts_RslLinkID_OSMO_PTCCH(0));
4671
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004672 pcu_rach_ind := tr_PCUIF_RACH_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7,
4673 ra := ra, fn := fn, sapi := PCU_IF_SAPI_PTCCH);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004674
4675 /* Expect a RACH.ind on the PCU interface (timeout is one multi-frame) */
4676 T.start(52.0 * 4.615 / 1000.0);
4677 alt {
4678 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) -> value sd {
4679 log("Rx an Access Burst on the PCU interface: ", sd.data);
4680 setverdict(pass);
4681 T.stop;
4682 }
4683 [] PCU.receive { repeat; }
4684 [] T.timeout {
4685 setverdict(fail, "Timeout waiting for RACH.ind on the PCU interface");
4686 /* Keep going, that's not the end of the world */
4687 }
4688 }
4689}
4690
4691testcase TC_pcu_ptcch() runs on test_CT {
4692 var L1ctlDlMessage dl;
4693 var octetstring data;
4694 timer T;
4695
4696 f_init_pcu_test();
4697 f_init_l1ctl();
4698 f_l1_tune(L1CTL);
4699
4700 /* Activate PDCH channel on TS7 */
4701 f_TC_pcu_act_req(0, 0, 7, true);
4702
4703 /* Tune trxcon to that PDCH channel */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004704 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004705 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
4706 { f_resolve_fh_params(pars); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004707 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiy8c242f02019-10-13 15:25:54 +07004708
4709 /* Verify PTCCH/U: send several access bursts, make sure they're received */
4710 for (var integer i := 0; i < 16; i := i + 1) {
4711 log("Sending an Access Burst towards the L1CTL interface");
4712 f_TC_pcu_ptcch_ul(oct2int(f_rnd_ra_ps()));
4713 }
4714
4715 /* Generate a random payload for PTCCH/D (23 octets, CS-1) */
4716 data := f_rnd_octstring(23);
4717
4718 /* Verify PTCCH/D: send a random data block, make sure it's received */
4719 log("Sending a PTCCH/D block towards the PCU interface: ", data);
4720 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
4721
4722 /* PTCCH/D period is 2 multi-frames (2 * 52 * 4.615 ms), but
4723 * let's give it more time in case if we miss the beginning. */
4724 T.start(2.0 * 2.0 * 52.0 * 4.615 / 1000.0);
4725 alt {
4726 /* PDCH is considered as traffic in trxcon => expect TRAFFIC.ind */
4727 [] L1CTL.receive(tr_L1CTL_TRAFFIC_IND(chan_nr := t_RslChanNr_PDCH(7),
4728 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4729 frame := data)) -> value dl {
4730 log("Rx PTCCH/D data (traffic) block on L1CTL: ", dl);
4731 setverdict(pass);
4732 T.stop;
4733 }
4734 /* Other PHYs (e.g. virt_phy) may consider PDCH as data => expect DATA.ind */
4735 [] L1CTL.receive(tr_L1CTL_DATA_IND(chan_nr := t_RslChanNr_PDCH(7),
4736 link_id := tr_RslLinkID_OSMO_PTCCH(?),
4737 l2_data := data)) -> value dl {
4738 log("Rx PTCCH/D data block on L1CTL: ", dl);
4739 setverdict(pass);
4740 T.stop;
4741 }
4742 [] L1CTL.receive { repeat; }
4743 [] T.timeout {
4744 setverdict(fail, "Timeout waiting for DATA.ind on L1CTL");
4745 }
4746 }
4747}
4748
Harald Welte883340c2018-02-28 18:59:29 +01004749/* Send AGCH from PCU; check it appears on Um side */
4750testcase TC_pcu_data_req_agch() runs on test_CT {
4751 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01004752 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004753 f_init_l1ctl();
4754 f_l1_tune(L1CTL);
4755
4756 f_TC_pcu_act_req(0, 0, 7, true);
4757 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
4758
4759 T.start;
4760 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004761 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01004762 setverdict(pass);
4763 }
4764 [] L1CTL.receive { repeat; }
4765 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004766 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004767 }
4768 }
4769}
4770
Harald Welte928622b2019-05-26 13:22:59 +02004771/* Send AGCH from PCU; check it appears on Um side */
4772testcase TC_pcu_data_req_pch() runs on test_CT {
4773 timer T := 3.0;
4774 f_init_pcu_test();
4775 f_init_l1ctl();
4776 f_l1_tune(L1CTL);
4777
4778 f_TC_pcu_act_req(0, 0, 7, true);
4779 /* three characters prefix: last 3 digits of IMSI as ASCII */
4780 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
4781
4782 T.start;
4783 alt {
4784 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
4785 setverdict(pass);
4786 }
4787 [] L1CTL.receive { repeat; }
4788 [] T.timeout {
4789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
4790 }
4791 }
4792}
4793
Harald Welte883340c2018-02-28 18:59:29 +01004794/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
4795testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
4796 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01004797 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004798 f_init_l1ctl();
4799 f_l1_tune(L1CTL);
4800
4801 /* append 3 last imsi digits so BTS can compute pagng group */
4802 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
4803
4804 timer T := 0.5;
4805 T.start;
4806 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01004807 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01004808 /* TODO: verify paging group */
4809 setverdict(pass);
4810 }
4811 [] L1CTL.receive { repeat; }
4812 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004813 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01004814 }
4815 }
4816}
4817
4818/* Send RACH from Um side, expect it to show up on PCU socket */
4819testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004820 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004821 f_init_l1ctl();
4822 f_l1_tune(L1CTL);
4823
4824 var GsmFrameNumber fn_last := 0;
4825 for (var integer i := 0; i < 1000; i := i+1) {
4826 var OCT1 ra := f_rnd_ra_ps();
4827 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
4828 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004829 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01004830 }
4831 fn_last := fn;
4832
4833 timer T := 2.0;
4834 T.start;
4835 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004836 [] 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 +01004837 T.stop;
4838 }
4839 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004840 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004841 }
4842 [] PCU.receive { repeat; }
4843 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004844 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01004845 }
4846 }
4847 }
4848 setverdict(pass);
4849}
4850
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004851/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
4852 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
4853testcase TC_pcu_ext_rach_content() runs on test_CT {
4854 var template PCUIF_Message pcu_rach_ind;
4855 var GsmFrameNumber fn_last := 0;
4856 var L1ctlRachSynchSeq synch_seq;
4857 var PCUIF_BurstType pcu_bt;
4858 var GsmFrameNumber fn;
4859 var BIT11 ra11;
4860
4861 f_init_pcu_test();
4862 f_init_l1ctl();
4863 f_l1_tune(L1CTL);
4864
4865 for (var integer i := 0; i < 1000; i := i+1) {
4866 /* We need to test both TS1 & TS2 */
4867 if (i rem 2 == 0) {
4868 synch_seq := RACH_SYNCH_SEQ_TS1;
4869 pcu_bt := BURST_TYPE_1;
4870 } else {
4871 synch_seq := RACH_SYNCH_SEQ_TS2;
4872 pcu_bt := BURST_TYPE_2;
4873 }
4874
4875 ra11 := f_rnd_ra11_ps();
4876 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
4877 if (fn == fn_last) {
4878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4879 "Two RACH in same FN?!?");
4880 }
4881 fn_last := fn;
4882
4883 /* Compose the expected message */
4884 pcu_rach_ind := tr_PCUIF_RACH_IND(
Vadim Yanitskiy36558d92019-11-17 02:23:51 +07004885 bts_nr := 0, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07004886 ra := bit2int(ra11),
4887 is_11bit := 1,
4888 burst_type := pcu_bt,
4889 fn := fn);
4890
4891 timer T := 2.0;
4892 T.start;
4893 alt {
4894 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
4895 T.stop;
4896 }
4897 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
4898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
4899 }
4900 [] PCU.receive { repeat; }
4901 [] T.timeout {
4902 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
4903 }
4904 }
4905 }
4906 setverdict(pass);
4907}
4908
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004909private function f_TC_pcu_data_ind_lqual_cb(int16_t lqual_cb_exp, int16_t thresh)
4910runs on test_CT {
4911 var template PCUIF_send_data sdt;
4912 var PCUIF_send_data sd;
4913 var int16_t lqual_cb;
4914 timer T := 1.0;
4915
4916 /* PCUIF_DATA.ind is encapsulated into a supplementary record */
4917 sdt := t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_DATA_IND);
4918
4919 /* Send a random PDTCH frame over Um */
4920 L1CTL.send(ts_L1CTL_TRAFFIC_REQ(ts_RslChanNr_PDCH(7), ts_RslLinkID_DCCH(0),
4921 '0000'O & f_rnd_octstring(21)));
4922
4923 T.start;
4924 alt {
4925 /* If expected link quality is above the threshold */
4926 [lqual_cb_exp >= thresh] PCU.receive(sdt) -> value sd {
4927 lqual_cb := sd.data.u.data_ind.lqual_cb;
4928 log("Rx PCUIF_DATA.ind (lqual_cb=", lqual_cb, ")");
4929
4930 /* Make sure the actual link quality matches the expected value */
4931 if (not match(lqual_cb, lqual_cb_exp)) {
4932 setverdict(fail, log2str("Link quality ", lqual_cb, " does not match ",
4933 "expected value ", lqual_cb_exp));
4934 } else {
4935 setverdict(pass);
4936 }
4937 }
4938 /* If expected link quality is below the threshold */
4939 [lqual_cb_exp < thresh] PCU.receive(sdt) -> value sd {
4940 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4941 log2str("Rx unexpected PCUIF_DATA.ind: ", sd.data));
4942 }
4943 /* Ignore PCUIF_RTS.req and PCUIF_TIME.ind */
4944 [] PCU.receive { repeat; }
4945 [lqual_cb_exp < thresh] T.timeout {
4946 log("Rx nothing, as expected");
4947 setverdict(pass);
4948 }
4949 [lqual_cb_exp >= thresh] T.timeout {
4950 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4951 "Timeout waiting for PCUIF_DATA.ind");
4952 }
4953 }
4954}
4955
4956/* Verify C/I (Carrier-to-Interference ratio) processing of PDTCH frames */
4957testcase TC_pcu_data_ind_lqual_cb() runs on test_CT {
4958 f_init_pcu_test();
4959 PCU.clear;
4960
4961 f_init_l1ctl();
4962 f_l1_tune(L1CTL);
4963
4964 /* Activate a PDCH channel on TS7 */
4965 f_TC_pcu_act_req(0, 0, 7, true);
4966
4967 /* Tune trxcon to that PDCH channel on TS7 */
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004968 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_PDCH(7), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiy13a29d52020-07-15 14:41:54 +07004969 if (mp_freq_hop_enabled and mp_transceiver_num > 1)
4970 { f_resolve_fh_params(pars); }
Vadim Yanitskiy1d55dee2020-07-14 21:19:09 +07004971 f_l1ctl_est_dchan(L1CTL, pars);
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07004972
4973 /* C/I in centiBels, test range: -256 .. +1280, step 128 */
4974 for (var int16_t i := -256; i <= 1280; i := i + 128) {
4975 var TrxcMessage ret;
4976
4977 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id,
4978 valueof(ts_TRXC_FAKE_CI(i)));
4979
4980 /* FIXME: OsmoBTS may have different threshold (see MIN_QUAL_NORM) */
4981 f_TC_pcu_data_ind_lqual_cb(i, thresh := 0);
4982 }
4983}
4984
Harald Welte883340c2018-02-28 18:59:29 +01004985/* Send PAGING via RSL, expect it to shw up on PCU socket */
4986testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01004987 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01004988
4989 for (var integer i := 0; i < 100; i := i+1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004990 var MobileIdentityLV mi_lv;
4991 var octetstring mi_lv_enc;
4992 var MobileIdentityV mi;
Harald Welte883340c2018-02-28 18:59:29 +01004993 timer T := 3.0;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004994
Harald Welte883340c2018-02-28 18:59:29 +01004995 if (i < 50) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004996 mi := valueof(t_MI_TMSI(f_rnd_octstring(4)));
Harald Welte883340c2018-02-28 18:59:29 +01004997 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07004998 mi := valueof(ts_MI_IMSI(f_gen_imsi(i)));
Harald Welte883340c2018-02-28 18:59:29 +01004999 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005000
5001 /* Fancy encoding for PCUIF */
5002 mi_lv := valueof(ts_MI_LV(mi));
5003 mi_lv_enc := enc_MobileIdentityLV(mi_lv);
5004 mi_lv_enc := f_pad_oct(mi_lv_enc, 9, '00'O);
Harald Welte883340c2018-02-28 18:59:29 +01005005
5006 /* Send RSL PAGING COMMAND */
Vadim Yanitskiy493abe72020-05-25 22:03:48 +07005007 RSL_CCHAN.send(ts_ASP_RSL_UD(ts_RSL_PAGING_CMD(mi, i mod 4)));
Harald Welte883340c2018-02-28 18:59:29 +01005008 T.start;
5009 alt {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07005010 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, mi_lv_enc))) {
Harald Welte883340c2018-02-28 18:59:29 +01005011 }
5012 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005014 }
5015 [] PCU.receive { repeat; }
5016 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005017 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01005018 }
5019 }
5020 }
5021 setverdict(pass);
5022}
5023
Harald Welted66c9b82019-05-25 09:03:15 +02005024/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
5025testcase TC_pcu_time_ind() runs on test_CT {
5026 var PCUIF_send_data pcu_sd;
5027 var integer num_time_ind := 0;
5028 var integer first_fn, last_fn;
5029 var float test_duration := 5.0;
5030 timer T;
5031
5032 f_init_pcu_test();
5033 f_TC_pcu_act_req(0, 0, 7, true);
5034
5035 PCU.clear;
5036 T.start(test_duration);
5037 alt {
5038 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
5039 num_time_ind := num_time_ind + 1;
5040 if (not isbound(first_fn)) {
5041 first_fn := pcu_sd.data.u.time_ind.fn;
5042 }
5043 last_fn := pcu_sd.data.u.time_ind.fn;
5044 repeat;
5045 }
5046 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
5047 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
5048 repeat;
5049 }
5050 [] PCU.receive {
5051 repeat;
5052 }
5053 [] T.timeout {}
5054 }
5055 var integer fn_expired := last_fn - first_fn;
5056 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
5057
5058 /* verify the number of frames expired matches our expectation */
5059 const float c_GSM_FN_DURATION_MS := 4.61538;
5060 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005061 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02005062 if (not match(fn_expired, t_fn_expected)) {
5063 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5064 }
5065
5066 /* There are three TIME.ind in every fn MOD 13 */
5067 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
5068 /* Add some tolerance */
5069 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
5070 if (not match(num_time_ind, t_time_ind_exp)) {
5071 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
5072 }
5073
5074 setverdict(pass);
5075}
5076
Harald Welte4832c862019-05-25 14:57:18 +02005077/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
5078testcase TC_pcu_rts_req() runs on test_CT {
5079 var PCUIF_send_data pcu_sd;
5080 var integer first_fn, last_fn;
5081 var integer num_rts_pdtch := 0;
5082 var integer num_rts_ptcch := 0;
5083 var float test_duration := 5.0;
5084 timer T;
5085
5086 f_init_pcu_test();
5087 f_TC_pcu_act_req(0, 0, 7, true);
5088
5089 PCU.clear;
5090 T.start(test_duration);
5091 alt {
5092 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
5093 -> value pcu_sd {
5094 num_rts_pdtch := num_rts_pdtch + 1;
5095 if (not isbound(first_fn)) {
5096 first_fn := pcu_sd.data.u.rts_req.fn;
5097 }
5098 last_fn := pcu_sd.data.u.rts_req.fn;
5099 repeat;
5100 }
5101 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
5102 -> value pcu_sd {
5103 num_rts_ptcch := num_rts_ptcch + 1;
5104 if (not isbound(first_fn)) {
5105 first_fn := pcu_sd.data.u.rts_req.fn;
5106 }
5107 last_fn := pcu_sd.data.u.rts_req.fn;
5108 repeat;
5109 }
5110 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
5111 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
5112 repeat;
5113 }
5114 [] PCU.receive {
5115 repeat;
5116 }
5117 [] T.timeout {}
5118 }
5119 var integer fn_expired := last_fn - first_fn;
5120 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
5121 ", num_rts_ptcch=", num_rts_ptcch);
5122
5123 /* verify the number of frames expired matches our expectation */
5124 const float c_GSM_FN_DURATION_MS := 4.61538;
5125 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02005126 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02005127 if (not match(fn_expired, t_fn_expected)) {
5128 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
5129 }
5130
5131 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
5132 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
5133 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
5134 if (not match(num_rts_ptcch, t_ptcch_exp)) {
5135 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
5136 t_ptcch_exp);
5137 }
5138
5139 /* We have 12 PDTCH blocks every 52-multiframe */
5140 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
5141 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
5142 if (not match(num_rts_pdtch, t_pdtch_exp)) {
5143 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
5144 t_pdtch_exp);
5145 }
5146
5147 setverdict(pass);
5148}
5149
Harald Welte07bd2d22019-05-25 11:03:30 +02005150/* test for generating Abis side OML ALERT from the PCU */
5151testcase TC_pcu_oml_alert() runs on test_CT {
5152 var PCUIF_send_data pcu_sd;
5153 var integer num_time_ind := 0;
5154 var integer first_fn, last_fn;
5155 var float test_duration := 5.0;
5156 timer T;
5157
5158 f_init_pcu_test();
5159 f_TC_pcu_act_req(0, 0, 7, true);
5160
5161 /* re-connect CTRL port from BTS to BSC */
5162 f_ipa_ctrl_stop();
5163 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
5164
5165 /* Send that OML Alert */
5166 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
5167
5168 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
5169 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
5170 setverdict(pass);
5171}
5172
Harald Welteeaa9a862019-05-26 23:01:08 +02005173/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
5174private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
5175 var PCUIF_Message first_info;
5176 var integer pcu_conn_id := -1;
5177 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5178 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
5179 var OCT4 tlli := '01020304'O;
5180 var OCT1 cause := '23'O;
5181 timer T := 5.0;
5182
5183 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5184
5185 f_l1_tune(L1CTL);
5186 RSL.clear;
5187
5188 f_est_dchan();
5189 L1CTL.clear;
5190
5191 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5192
5193 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
5194 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
5195 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
5196
5197 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
5198 T.start;
5199 alt {
5200 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
5201 setverdict(pass);
5202 }
5203 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
5204 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
5205 }
5206 [] PCU.receive {
5207 repeat;
5208 }
5209 [] T.timeout {
5210 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
5211 }
5212 }
Alexander Couzensa0634832019-06-07 00:28:56 +02005213
5214 /* release the channel */
5215 f_rsl_chan_deact();
5216 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5217 f_rslem_unregister(0, g_chan_nr);
Harald Welteeaa9a862019-05-26 23:01:08 +02005218}
5219testcase TC_pcu_rr_suspend() runs on test_CT {
5220 var ConnHdlrPars pars;
5221 var ConnHdlr vc_conn;
5222
5223 f_init();
5224
5225 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
5226 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
5227 vc_conn.done;
5228}
Harald Welte07bd2d22019-05-25 11:03:30 +02005229
Harald Weltea2e0e942019-05-27 18:12:53 +02005230/* Ensure that PCUIF socket can accept only a single connection */
5231testcase TC_pcu_socket_connect_multi() runs on test_CT {
5232 timer T := 5.0;
5233
5234 /* this (among other things) establishes the first connection to the PCUIF socket */
5235 f_init();
5236
5237 /* try to establish a second connection, expect it to fail */
5238 PCU.send(UD_connect:{mp_pcu_socket, -1});
5239 T.start;
5240 alt {
5241 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
5242 setverdict(pass);
5243 }
5244 [] PCU.receive(UD_connect_result:?) {
5245 setverdict(fail, "Unexpected unix domain connect result");
5246 }
5247 [] T.timeout {
5248 setverdict(pass);
5249 }
5250 }
5251 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5252}
5253
Harald Weltec8effb72019-05-27 18:23:04 +02005254/* Ensure that PCUIF socket can disconnect + reconnect */
5255testcase TC_pcu_socket_reconnect() runs on test_CT {
5256 /* this (among other things) establishes the first connection to the PCUIF socket */
5257 f_init();
5258
5259 f_sleep(1.0);
5260
5261 f_pcuif_close(PCU, g_pcu_conn_id);
5262 g_pcu_conn_id := -1;
5263
5264 f_sleep(1.0);
5265
5266 /* re-connect */
5267 PCU.clear;
5268 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5269 setverdict(pass);
5270
5271 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5272}
5273
Harald Weltebe030482019-05-27 22:29:35 +02005274/* Ensure that GPRS capability is not advertised before PCU socket conncet */
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005275private function f_get_si(L1CTL_PT pt, RrMessageType si_type)
5276runs on test_CT return SystemInformation {
Harald Weltebe030482019-05-27 22:29:35 +02005277 var L1ctlDlMessage l1_dl;
5278 var SystemInformation si;
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005279 var integer rc;
Harald Weltebe030482019-05-27 22:29:35 +02005280 timer T := 5.0;
5281 T.start;
5282 alt {
5283 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Vadim Yanitskiycb478ec2020-07-11 02:37:17 +07005284 rc := dec_SystemInformationSafe(l1_dl.payload.data_ind.payload, si);
5285 if (rc != 0 or si.header.message_type != si_type) {
Harald Weltebe030482019-05-27 22:29:35 +02005286 repeat;
5287 }
5288 }
5289 [] pt.receive {
5290 repeat;
5291 }
5292 [] T.timeout {
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005293 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5294 log2str("Timeout waiting for ", si_type));
Harald Weltebe030482019-05-27 22:29:35 +02005295 }
5296 }
Vadim Yanitskiy3c185382020-05-04 14:55:02 +07005297 return si;
Harald Weltebe030482019-05-27 22:29:35 +02005298}
5299
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005300/* Check if GPRS Indicator is present in RR System Information of a given type */
5301private function f_si_has_gprs_indicator(RrMessageType si_type)
5302runs on test_CT return boolean {
5303 var SystemInformation si := f_get_si(L1CTL, si_type);
5304
5305 if (si_type == SYSTEM_INFORMATION_TYPE_3) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005306 return si.payload.si3.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005307 } else if (si_type == SYSTEM_INFORMATION_TYPE_4) {
Neels Hofmeyra5f0ed22020-07-06 02:39:40 +02005308 return si.payload.si4.rest_octets.gprs_ind.presence == '1'B;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005309 }
5310
5311 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unhandled SI type");
5312 return false;
Harald Weltebe030482019-05-27 22:29:35 +02005313}
5314
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005315/* Make sure that GPRS Indicator is absent when the PCU is not connected */
5316private function f_TC_pcu_socket_noconnect(RrMessageType si_type)
5317runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005318 /* don't call f_init() as this would connect PCU socket */
5319 f_init_rsl(testcasename());
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005320
5321 /* Send both System Information Type 3 and 4 (with GPRS Indicator) */
Harald Weltebe030482019-05-27 22:29:35 +02005322 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005323 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Weltebe030482019-05-27 22:29:35 +02005324
5325 f_init_l1ctl();
5326 f_l1_tune(L1CTL);
Harald Weltebe030482019-05-27 22:29:35 +02005327 f_sleep(2.0);
5328 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005329
5330 if (f_si_has_gprs_indicator(si_type)) {
5331 setverdict(fail, si_type, " indicates GPRS even before PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005332 } else {
5333 setverdict(pass);
5334 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005335
Harald Weltebe030482019-05-27 22:29:35 +02005336 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5337}
5338
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005339testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
5340 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_3);
5341}
Harald Weltebe030482019-05-27 22:29:35 +02005342
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005343testcase TC_pcu_socket_noconnect_nosi4gprs() runs on test_CT {
5344 f_TC_pcu_socket_noconnect(SYSTEM_INFORMATION_TYPE_4);
5345}
5346
5347/* Ensure that GPRS capability is advertised after PCU socket connect */
5348private function f_TC_pcu_socket_connect(RrMessageType si_type)
5349runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005350 /* this (among other things) establishes the first connection to the PCUIF socket */
5351 f_init();
5352 f_init_l1ctl();
5353 f_l1_tune(L1CTL);
5354
5355 f_sleep(2.0);
5356 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005357
5358 if (not f_si_has_gprs_indicator(si_type)) {
5359 setverdict(fail, si_type, " indicates no GPRS despite PCU socket connected");
Harald Weltebe030482019-05-27 22:29:35 +02005360 } else {
5361 setverdict(pass);
5362 }
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005363
Harald Weltebe030482019-05-27 22:29:35 +02005364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5365}
5366
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005367testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
5368 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_3);
5369}
Harald Weltebe030482019-05-27 22:29:35 +02005370
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005371testcase TC_pcu_socket_connect_si4gprs() runs on test_CT {
5372 f_TC_pcu_socket_connect(SYSTEM_INFORMATION_TYPE_4);
5373}
5374
5375/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
5376private function f_TC_pcu_socket_disconnect(RrMessageType si_type)
5377runs on test_CT {
Harald Weltebe030482019-05-27 22:29:35 +02005378 /* this (among other things) establishes the first connection to the PCUIF socket */
5379 f_init();
5380 f_init_l1ctl();
5381 f_l1_tune(L1CTL);
5382
5383 f_pcuif_close(PCU, g_pcu_conn_id);
5384 g_pcu_conn_id := -1;
5385
5386 f_sleep(1.0);
5387
5388 /* re-connect */
5389 PCU.clear;
5390 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
5391
5392 f_sleep(2.0);
5393 L1CTL.clear;
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005394
5395 if (f_si_has_gprs_indicator(si_type)) {
5396 setverdict(fail, si_type, " indicates GPRS after PCU socket disconnected");
Harald Weltebe030482019-05-27 22:29:35 +02005397 } else {
5398 setverdict(pass);
5399 }
5400
5401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
5402}
5403
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07005404testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
5405 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_3);
5406}
5407
5408testcase TC_pcu_socket_disconnect_nosi4gprs() runs on test_CT {
5409 f_TC_pcu_socket_disconnect(SYSTEM_INFORMATION_TYPE_4);
5410}
5411
Oliver Smithf5239c72019-08-28 10:01:25 +02005412/* 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) */
5413testcase TC_pcu_socket_verify_info_ind() runs on test_CT {
5414 var SystemInformation si3 := valueof(ts_SI3_default);
5415
5416 f_init();
5417
5418 /* Verify cell_id */
5419 var uint16_t cell_id_si3 := si3.payload.si3.cell_id;
5420 var uint16_t cell_id_pcu := g_pcu_last_info.u.info_ind.cell_id;
5421 if (cell_id_si3 != cell_id_pcu) {
Oliver Smithe1c00f02019-09-04 11:35:56 +02005422 setverdict(fail, "Expected cell_id '", cell_id_si3, "' and got '", cell_id_pcu, "'. This either means,",
5423 " that the BTS is sending the wrong cell_id, or that the BTS sent it too early",
5424 " (OS#4179)");
Oliver Smithf5239c72019-08-28 10:01:25 +02005425 }
5426
5427 /* Verify LAC */
5428 var uint16_t lac_si3 := si3.payload.si3.lai.lac;
5429 var uint16_t lac_pcu := g_pcu_last_info.u.info_ind.lac;
5430 if (lac_si3 != lac_pcu) {
5431 setverdict(fail, "Expected LAC ", lac_si3, " got: ", lac_pcu);
5432 }
5433
5434 setverdict(pass);
5435}
Harald Welted66c9b82019-05-25 09:03:15 +02005436
Harald Welte3d04ae62018-04-04 20:29:05 +02005437/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02005438 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02005439 ***********************************************************************/
5440
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005441private altstep as_pcuif_check_pdch_mask(integer pcu_conn_id, BIT1 exp,
5442 integer bts_nr, integer trx_nr)
Harald Welte3d04ae62018-04-04 20:29:05 +02005443runs on ConnHdlr {
5444 var PCUIF_send_data sd;
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005445
5446 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
5447 var bitstring pdch_mask := sd.data.u.info_ind.trx[trx_nr].pdch_mask;
5448 if (substr(pdch_mask, g_chan_nr.tn, 1) != exp) {
5449 repeat;
5450 }
5451 }
5452}
5453
5454private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5455runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005456 /* Expect BTS to immediately acknowledge activation as PDCH */
5457 PCU.clear;
5458 f_rsl_chan_act(g_pars.chan_mode);
5459 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005460 timer T_wait := 2.0;
5461 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005462 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005463 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005464 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005465 [] T_wait.timeout {
5466 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5467 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5468 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005469 }
5470 /* try to activate this PDCH from the PCU point of view */
5471 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5472 /* FIXME: is there a response? */
5473}
5474
5475private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5476runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005477 /* Send RSL CHAN REL (deactivate) */
5478 PCU.clear;
5479 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5480 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005481 timer T_wait := 2.0;
5482 T_wait.start;
Harald Welte3d04ae62018-04-04 20:29:05 +02005483 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005484 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte3d04ae62018-04-04 20:29:05 +02005485 [] PCU.receive { repeat; }
Pau Espin Pedrol202c2f72019-10-08 13:11:05 +02005486 [] T_wait.timeout {
5487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5488 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5489 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005490 }
5491 /* Emulate PCU asking BTS to deactivate PDCH */
5492 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5493 alt {
5494 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
5495 setverdict(pass);
5496 }
5497 [] RSL.receive { repeat; }
5498 }
5499}
5500
5501/* Activate Osmocom-style dynamic PDCH from BSC side */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005502private function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005503 var PCUIF_Message first_info;
5504 var integer ts_nr := g_chan_nr.tn;
5505 var integer trx_nr := 0;
5506 var integer bts_nr := 0;
5507 var integer pcu_conn_id := -1;
5508
5509 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5510
5511 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5512 f_sleep(3.0);
5513 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5514 setverdict(pass);
5515}
5516testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
5517 var ConnHdlrPars pars;
5518 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005519 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005520
5521 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5522 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
5523 vc_conn.done;
5524}
5525
5526/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005527private function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005528 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02005529 var integer pcu_conn_id := -1;
5530
5531 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5532
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02005533 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
5534 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
5535 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02005536 setverdict(pass);
5537}
5538testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
5539 var ConnHdlrPars pars;
5540 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005541 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005542
5543 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5544 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
5545 vc_conn.done;
5546}
5547
5548/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005549private function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005550 var PCUIF_Message first_info;
5551 var integer ts_nr := g_chan_nr.tn;
5552 var integer trx_nr := 0;
5553 var integer bts_nr := 0;
5554 var integer pcu_conn_id := -1;
5555
5556 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5557
5558 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02005559 /* Send a second Chan Activ and expect it to be NACKed */
5560 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5561 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02005562 setverdict(pass);
5563}
5564testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
5565 var ConnHdlrPars pars;
5566 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005567 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005568
5569 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5570 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
5571 vc_conn.done;
5572}
5573
5574/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005575private function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005576 var PCUIF_Message first_info;
5577 var integer ts_nr := g_chan_nr.tn;
5578 var integer trx_nr := 0;
5579 var integer bts_nr := 0;
5580 var integer pcu_conn_id := -1;
5581 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
5582
5583 /* register for the TCH/F channel number */
5584 f_rslem_register(0, chan_nr);
5585
5586 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5587
5588 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
5589 "RSL CHAN ACT");
5590 setverdict(pass);
5591}
5592testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
5593 var ConnHdlrPars pars;
5594 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005595 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005596
5597 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5598 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
5599 vc_conn.done;
5600}
5601
5602/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005603private function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
Harald Welte3d04ae62018-04-04 20:29:05 +02005604 var PCUIF_Message first_info;
5605 var integer ts_nr := g_chan_nr.tn;
5606 var integer trx_nr := 0;
5607 var integer bts_nr := 0;
5608 var integer pcu_conn_id := -1;
5609 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
5610 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
5611
5612 /* register for the TCH/H channel numbers */
5613 f_rslem_register(0, chan_nr[0]);
5614 f_rslem_register(0, chan_nr[1]);
5615
5616 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5617
5618 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
5619 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
5620 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
5621 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
5622 setverdict(pass);
5623}
5624testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
5625 var ConnHdlrPars pars;
5626 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005627 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02005628
5629 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
5630 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
5631 vc_conn.done;
5632}
5633
Harald Welte9bbbfb52018-04-05 09:33:19 +02005634/***********************************************************************
5635 * IPA Style Dynamic Timeslot Support
5636 ***********************************************************************/
5637
5638private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5639runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005640 /* Expect BTS to immediately acknowledge activation as PDCH */
5641 PCU.clear;
5642 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5643 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005644 timer T_wait := 2.0;
5645 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005646 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005647 [] as_pcuif_check_pdch_mask(pcu_conn_id, '1'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005648 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005649 [] T_wait.timeout {
5650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5651 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
5652 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005653 }
5654 /* try to activate this PDCH from the PCU point of view */
5655 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5656 /* FIXME: is there a response? */
5657
5658 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
5659}
5660
5661private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
5662runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005663 /* Send RSL CHAN REL (deactivate) */
5664 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
5665 PCU.clear;
5666 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005667 timer T_wait := 2.0;
5668 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02005669 alt {
Vadim Yanitskiyb1ebcc02020-07-19 17:43:02 +07005670 [] as_pcuif_check_pdch_mask(pcu_conn_id, '0'B, bts_nr, trx_nr);
Harald Welte9bbbfb52018-04-05 09:33:19 +02005671 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01005672 [] T_wait.timeout {
5673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
5674 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
5675 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02005676 }
5677 /* Emulate PCU asking BTS to deactivate PDCH */
5678 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
5679 alt {
5680 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
5681 setverdict(pass);
5682 }
5683 [] RSL.receive { repeat; }
5684 }
5685}
5686
5687/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005688private function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005689 var PCUIF_Message first_info;
5690 var integer ts_nr := g_chan_nr.tn;
5691 var integer trx_nr := 0;
5692 var integer bts_nr := 0;
5693 var integer pcu_conn_id := -1;
5694
5695 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5696
5697 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5698 f_sleep(3.0);
5699 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5700
5701 setverdict(pass);
5702
5703}
5704testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
5705 var ConnHdlrPars pars;
5706 var ConnHdlr vc_conn;
5707 f_init();
5708
5709 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5710 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
5711 vc_conn.done;
5712}
5713
5714/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07005715private function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005716 var PCUIF_Message first_info;
5717 var integer ts_nr := g_chan_nr.tn;
5718 var integer trx_nr := 0;
5719 var integer bts_nr := 0;
5720 var integer pcu_conn_id := -1;
5721
5722 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5723
5724 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5725 "RSL CHAN ACT");
5726 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5727 "RF CHAN REL", true);
5728 setverdict(pass);
5729}
5730testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
5731 var ConnHdlrPars pars;
5732 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005733 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005734
5735 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5736 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
5737 vc_conn.done;
5738}
5739
5740/* 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 +07005741private function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005742 var PCUIF_Message first_info;
5743 var integer ts_nr := g_chan_nr.tn;
5744 var integer trx_nr := 0;
5745 var integer bts_nr := 0;
5746 var integer pcu_conn_id := -1;
5747
5748 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5749
5750 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
5751 "RSL CHAN ACT");
5752
5753 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
5754 alt {
5755 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
5756 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005757 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02005758 }
5759 [] RSL.receive { repeat; }
5760 }
5761
5762 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
5763 "RF CHAN REL", true);
5764 setverdict(pass);
5765}
5766testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
5767 var ConnHdlrPars pars;
5768 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005769 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005770
5771 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5772 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
5773 vc_conn.done;
5774}
5775
5776/* 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 +07005777private function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
Harald Welte9bbbfb52018-04-05 09:33:19 +02005778 var PCUIF_Message first_info;
5779 var integer ts_nr := g_chan_nr.tn;
5780 var integer trx_nr := 0;
5781 var integer bts_nr := 0;
5782 var integer pcu_conn_id := -1;
5783
5784 /* register for the TCH/F channel number */
5785 f_rslem_register(0, g_chan_nr);
5786
5787 f_init_pcu(PCU, id, pcu_conn_id, first_info);
5788
5789 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
5790
5791 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
5792 "RSL CHAN ACT");
5793
5794 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
5795
5796 setverdict(pass);
5797}
5798testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
5799 var ConnHdlrPars pars;
5800 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005801 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02005802
5803 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
5804 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
5805 vc_conn.done;
5806}
5807
5808
Harald Welte0472ab42018-03-12 15:02:26 +01005809/***********************************************************************
5810 * LAPDm / RLL related
5811 ***********************************************************************/
5812
5813private function f_tx_lapdm(template (value) LapdmFrame l,
5814 template (value) RslLinkId link_id) runs on ConnHdlr {
5815 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005816 var template (value) SacchL1Header l1h;
5817
5818 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01005819 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005820 /* Compose dummy L1 header */
5821 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
5822 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 +02005823 } else {
5824 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07005825 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 +01005826 }
Harald Welte0472ab42018-03-12 15:02:26 +01005827}
5828
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005829private type record RllTestCase {
Harald Welte0472ab42018-03-12 15:02:26 +01005830 uint3_t sapi,
5831 RslLinkId link_id,
5832 octetstring l3,
5833 boolean exp
5834}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07005835private type record of RllTestCase RllTestCases;
5836private template RllTestCase t_EITC(uint3_t sapi, RslLinkId id,
5837 octetstring l3, boolean exp) := {
Harald Welte0472ab42018-03-12 15:02:26 +01005838 sapi := sapi,
5839 link_id := id,
5840 l3 := l3,
5841 exp := exp
5842}
5843
5844/* execute the same callback function with a set of different parameters (tcs) on a
5845 * variety of logical channels */
5846private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
5847 var ConnHdlrPars pars;
5848 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02005849 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01005850
5851 /* test on each of the channels we have */
5852 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
5853 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
5854
5855 /* test each of the test cases on the current channel */
5856 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
5857 pars.spec.rll := tcs[j];
5858 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
5859 vc_conn := f_start_handler(fn, pars);
5860 vc_conn.done;
5861 }
5862 }
5863
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005864 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01005865}
5866
5867/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
5868private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
5869 var RllTestCase tc := g_pars.spec.rll;
5870 timer T := 3.0;
5871
5872 f_l1_tune(L1CTL);
5873 RSL.clear;
5874
5875 /* activate the logical channel */
5876 f_est_dchan();
5877 L1CTL.clear;
5878
5879 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
5880 T.start;
5881 alt {
5882 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
5883 if (tc.exp) {
5884 setverdict(pass);
5885 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005886 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005887 }
5888 }
5889 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
5890 if (tc.exp) {
5891 setverdict(pass);
5892 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01005894 }
5895 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07005896 /* We also expect to receive the measurements */
5897 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01005898 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005899 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01005900 }
5901 [not tc.exp] T.timeout {
5902 setverdict(pass);
5903 }
5904 }
5905
5906 f_rsl_chan_deact();
5907 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5908 f_rslem_unregister(0, g_chan_nr);
5909}
5910testcase TC_rll_est_ind() runs on test_CT {
5911 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02005912 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01005913 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02005914 /* normal SAPI0 establishment */
5915 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01005916 /* SAPI 3 doesn't support contention resolution */
5917 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
5918 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
5919 /* normal SAPI3 establishment on main DCCH */
5920 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
5921 /* normal SAPI3 establishment on SACCH */
5922 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5923 };
5924 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
5925}
5926
5927/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
5928private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
5929 var RllTestCase tc := g_pars.spec.rll;
5930 var L1ctlDlMessage dl;
5931 timer T := 3.0;
5932
5933 f_l1_tune(L1CTL);
5934 RSL.clear;
5935
5936 /* activate the logical channel */
5937 f_est_dchan();
5938 L1CTL.clear;
5939
5940 /* Send a RSL EST REQ for SAPI3 on main DCCH */
5941 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
5942 T.start;
5943 alt {
5944 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5945 var LapdmFrame lapdm;
5946 var octetstring l2 := dl.payload.data_ind.payload;
5947 if (dl.dl_info.link_id.c == SACCH) {
5948 /* remove L1 header */
5949 l2 := substr(l2, 2, lengthof(l2)-2);
5950 }
5951 lapdm.ab := dec_LapdmFrameAB(l2);
5952 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
5953 setverdict(pass);
5954 } else {
5955 repeat;
5956 }
5957 }
5958 [] L1CTL.receive { repeat; }
5959 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01005961 }
5962 }
5963
5964 f_rsl_chan_deact();
5965 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5966 f_rslem_unregister(0, g_chan_nr);
5967}
5968testcase TC_rll_est_req_DCCH_3() runs on test_CT {
5969 var RllTestCases tcs := {
5970 /* normal SAPI3 establishment on main DCCH */
5971 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
5972 };
5973 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5974}
5975testcase TC_rll_est_req_ACCH_3() runs on test_CT {
5976 var RllTestCases tcs := {
5977 /* normal SAPI3 establishment on SACCH */
5978 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
5979 }
5980 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
5981}
5982
5983/* altstep to receive a LAPDm frame matching the given template */
5984private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
5985 var L1ctlDlMessage dl;
5986 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5987 var LapdmFrame lapdm;
5988 var octetstring l2 := dl.payload.data_ind.payload;
5989 if (dl.dl_info.link_id.c == SACCH) {
5990 /* remove L1 header */
5991 l2 := substr(l2, 2, lengthof(l2)-2);
5992 }
5993 if (ischosen(exp.ab)) {
5994 lapdm.ab := dec_LapdmFrameAB(l2);
5995 } else if (ischosen(exp.b4)) {
5996 lapdm.b4 := dec_LapdmFrameB4(l2);
5997 } else if (ischosen(exp.bbis)) {
5998 lapdm.bbis := dec_LapdmFrameBbis(l2);
5999 }
6000 log("Rx LAPDm ", lapdm);
6001 if (match(lapdm, exp)) {
6002 setverdict(pass);
6003 } else {
6004 repeat;
6005 }
6006 }
6007 [] L1CTL.receive { repeat; }
6008}
6009private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
6010 timer T := t;
6011 T.start;
6012 alt {
6013 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006014 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01006015 }
6016 [] as_l1_exp_lapdm(exp);
6017 }
6018}
6019
6020/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
6021private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
6022 /* send SABM from MS -> BTS */
6023 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
6024 /* expect RLL EST IND on Abis */
6025 alt {
6026 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
6027 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
6028 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01006030 }
6031 [] RSL.receive { repeat; }
6032 }
6033 /* expect UA from BTS -> MS */
6034 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
6035}
6036
6037/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
6038private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
6039 var RllTestCase tc := g_pars.spec.rll;
6040
6041 f_l1_tune(L1CTL);
6042 RSL.clear;
6043
6044 /* activate the logical channel */
6045 f_est_dchan();
6046 L1CTL.clear;
6047
6048 /* first establish the link-layer */
6049 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6050
6051 /* then send the DISC */
6052 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
6053 /* ... and expect the REL IND on the RSL side */
6054 alt {
6055 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
6056 setverdict(pass);
6057 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07006058 /* We also expect to receive the measurements */
6059 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01006060 }
6061
6062 /* release the channel */
6063 f_rsl_chan_deact();
6064 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6065 f_rslem_unregister(0, g_chan_nr);
6066}
6067testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
6068 var RllTestCases tcs := {
6069 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
6070 };
6071 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6072}
6073
6074testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
6075 var RllTestCases tcs := {
6076 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
6077 };
6078 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6079}
6080testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
6081 var RllTestCases tcs := {
6082 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
6083 };
6084 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6085}
6086testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
6087 var RllTestCases tcs := {
6088 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6089 };
6090 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
6091}
6092
6093/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
6094private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
6095 var RllTestCase tc := g_pars.spec.rll;
6096 f_l1_tune(L1CTL);
6097 RSL.clear;
6098
6099 /* activate the logical channel */
6100 f_est_dchan();
6101 L1CTL.clear;
6102
6103 /* first establish the link-layer */
6104 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
6105
6106 /* then send the REL REQ via RSL */
6107 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
6108 /* ... and expect the DISC on the Um side */
6109 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02006110 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01006111 /* FIXME: send a UA in resposne to the DISC */
6112 }
6113 }
6114
6115 /* release the channel */
6116 f_rsl_chan_deact();
6117 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6118 f_rslem_unregister(0, g_chan_nr);
6119}
6120testcase TC_rll_rel_req() runs on test_CT {
6121 var RllTestCases tcs := {
6122 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
6123 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
6124 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
6125 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
6126 };
6127 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
6128}
6129
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006130/* TODO: test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
Harald Welte0472ab42018-03-12 15:02:26 +01006131testcase TC_rll_data_req() runs on test_CT {
6132}
6133
Vadim Yanitskiy89be0602020-07-04 21:20:57 +07006134/* TODO: test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
Harald Welte0472ab42018-03-12 15:02:26 +01006135testcase TC_rll_data_ind() runs on test_CT {
6136}
6137
6138/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
6139private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
6140 var RllTestCase tc := g_pars.spec.rll;
6141
6142 f_l1_tune(L1CTL);
6143 RSL.clear;
6144
6145 f_est_dchan();
6146 L1CTL.clear;
6147
6148 /* Send UNITDATA REQ on RSL side */
6149 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
6150 /* Expect it to arrive on the other side */
6151 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02006152 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006153 } else {
Harald Weltee613f962018-04-18 22:38:16 +02006154 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01006155 }
6156
6157 /* release the channel */
6158 f_rsl_chan_deact();
6159 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6160 f_rslem_unregister(0, g_chan_nr);
6161}
6162testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
6163 var octetstring l3 := f_rnd_octstring(15);
6164 var RllTestCases tcs := {
6165 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6166 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6167 };
6168 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6169}
6170testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
6171 var octetstring l3 := f_rnd_octstring(19);
6172 var RllTestCases tcs := {
6173 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6174 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6175 };
6176 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
6177}
6178
6179/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
6180private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
6181 var RllTestCase tc := g_pars.spec.rll;
6182
6183 f_l1_tune(L1CTL);
6184 RSL.clear;
6185
6186 f_est_dchan();
6187 L1CTL.clear;
6188
6189 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02006190 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01006191 /* Expdct RLL UNITDATA IND on RSL side */
6192 alt {
6193 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
6194 setverdict(pass);
6195 }
6196 [] RSL.receive { repeat; }
6197 }
6198
6199 /* release the channel */
6200 f_rsl_chan_deact();
6201 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6202 f_rslem_unregister(0, g_chan_nr);
6203}
6204testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02006205 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01006206 var RllTestCases tcs := {
6207 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
6208 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
6209 };
6210 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6211}
6212testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
6213 var octetstring l3 := f_rnd_octstring(18);
6214 var RllTestCases tcs := {
6215 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
6216 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
6217 };
6218 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
6219}
6220
Harald Weltee613f962018-04-18 22:38:16 +02006221/***********************************************************************
6222 * Encryption Related
6223 ***********************************************************************/
6224
6225/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006226private function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006227 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
6228 if (link_id.c == SACCH) {
6229 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
6230 } else {
6231 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
6232 }
6233}
6234
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006235/* Expect (or not expect) other kinds of messages */
6236private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
6237 [exp_any] RSL.receive { repeat; }
6238 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006240 }
6241}
6242
Harald Weltee613f962018-04-18 22:38:16 +02006243/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07006244private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006245 RslLinkId link_id,
6246 octetstring l3,
6247 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006248 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07006249) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006250 timer T := 3.0;
6251 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
6252 T.start;
6253 /* Expect RLL UNITDATA IND on RSL side */
6254 alt {
6255 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
6256 setverdict(pass);
6257 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006258 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07006259 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02006260 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02006262 }
Harald Weltee613f962018-04-18 22:38:16 +02006263 }
6264}
6265
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006266/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
6267private function f_data_mo(
6268 RslLinkId link_id,
6269 boolean p, uint3_t nr, uint3_t ns,
6270 octetstring l3,
6271 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07006272 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006273) runs on ConnHdlr {
6274 timer T := 3.0;
6275 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
6276 T.start;
6277 /* Expect RLL DATA IND on RSL side */
6278 alt {
6279 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
6280 setverdict(pass);
6281 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07006282 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006283 [] as_rsl_any_ind(exp_any);
6284 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006285 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006286 }
6287 }
6288}
6289
Harald Weltee613f962018-04-18 22:38:16 +02006290/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006291private function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006292 f_l1_tune(L1CTL);
6293 f_est_dchan(true);
6294
6295 /* now we actually need to transmit some data both ways to check if the encryption works */
6296 var L1ctlDlMessage dl;
6297
Stefan Sperling603d98e2018-07-25 16:47:28 +02006298 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02006299 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6300
6301 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6302 f_unitdata_mt(link_id, l3);
6303
6304 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6305 f_unitdata_mo(link_id, l3);
6306
6307 /* release the channel */
6308 f_rsl_chan_deact();
6309 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6310 f_rslem_unregister(0, g_chan_nr);
6311}
6312testcase TC_chan_act_a51() runs on test_CT {
6313 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6314 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6315 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6316}
6317testcase TC_chan_act_a52() runs on test_CT {
6318 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6319 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6320 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6321}
6322testcase TC_chan_act_a53() runs on test_CT {
6323 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6324 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6325 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
6326}
6327
Eric Wildf1827a72019-05-28 17:37:35 +02006328/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
6329 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 +07006330private function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
Eric Wildf1827a72019-05-28 17:37:35 +02006331 f_l1_tune(L1CTL);
6332 f_est_dchan(true);
6333
6334 /* now we actually need to transmit some data both ways to check if the encryption works */
6335 var L1ctlDlMessage dl;
6336
6337 var octetstring l3 := f_rnd_octstring(20);
6338 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6339
6340 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
6341 f_unitdata_mt(link_id, l3);
6342
6343 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
6344 f_unitdata_mo(link_id, l3);
6345
6346 var RSL_Message rsl;
6347 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
6348
6349 /* modify key to break proper encryption */
6350 g_pars.encr.key := f_rnd_octstring(8);
6351 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
6352 rsl.ies := rsl.ies & { ei };
6353 RSL.send(rsl);
6354
6355 timer T0 := 1.0;
6356 T0.start;
6357 /* Expect RSL MODIFY ACK */
6358 alt {
6359 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
6360 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
6361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
6362 }
6363 [] T0.timeout {
6364 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
6365 }
6366 }
6367
6368 var octetstring l3msg := f_rnd_octstring(15);
6369 timer T1 := 3.0;
6370 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
6371 due to broken encryption */
6372 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
6373 T1.start;
6374 alt {
6375 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
6376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
6377 }
6378 [] T1.timeout {
6379 setverdict(pass);
6380 }
6381 }
6382
6383 /* release the channel */
6384 f_rsl_chan_deact();
6385 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6386 f_rslem_unregister(0, g_chan_nr);
6387}
6388testcase TC_rsl_modify_encr() runs on test_CT {
6389 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6390 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6391 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
6392}
Harald Weltee613f962018-04-18 22:38:16 +02006393
6394/* Test unencrypted channel activation followed by explicit ENCR CMD later */
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006395private function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02006396 /* L3 payload doesn't matter, as it is passed transparently */
6397 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
6398 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
6399 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
6400
6401 f_l1_tune(L1CTL);
6402
6403 /* first establish a dedicated channel in the clear */
6404 f_est_dchan(false);
6405
6406 /* Establish ABM */
6407 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
6408
6409 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
6410 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
6411 /* expect the L3 to arrive still unencrypted on the MS side */
6412 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
6413
6414 /* configure L1 to apply ciphering */
6415 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
6416 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
6417
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07006418 /* send first ciphered I-frame in response and expect it on RSL */
6419 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02006420
6421 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
6422 * and hence enable encryption also on the downlink */
6423
6424 /* expect bi-directional communication work in encrypted mode */
6425 f_unitdata_mo(link_id, f_rnd_octstring(15));
6426 f_unitdata_mt(link_id, f_rnd_octstring(15));
6427
6428 /* release the channel */
6429 f_rsl_chan_deact();
6430 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
6431 f_rslem_unregister(0, g_chan_nr);
6432}
6433testcase TC_encr_cmd_a51() runs on test_CT {
6434 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6435 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
6436 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6437}
6438testcase TC_encr_cmd_a52() runs on test_CT {
6439 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6440 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
6441 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6442}
6443testcase TC_encr_cmd_a53() runs on test_CT {
6444 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
6445 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
6446 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
6447}
6448
6449private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
6450 var LapdmFrame lf;
6451 var octetstring reenc;
6452
6453 /* decode the LAPDm frame */
6454 if (ischosen(exp_match.ab)) {
6455 lf.ab := dec_LapdmFrameAB(enc);
6456 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006457 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02006458 }
6459
6460 /* check if decoder result matches expectation */
6461 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006462 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006463 } else {
6464 log(name, ": matched");
6465 setverdict(pass);
6466 }
6467
6468 /* test if re-encoded frame equals original input */
6469 reenc := enc_LapdmFrame(lf);
6470 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02006472 } else {
6473 setverdict(pass);
6474 }
6475}
6476
6477testcase TC_lapdm_selftest() runs on test_CT {
6478 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
6479 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
6480 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
6481 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
6482 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
6483 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
6484 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
6485}
6486
Stefan Sperling4880be42018-08-07 18:12:59 +02006487/***********************************************************************
6488 * DTX Related (see GSM 05.08, section 8.3)
6489 ***********************************************************************/
6490
6491/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006492private function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006493 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
6494 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
6495 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
6496 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
6497}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006498private function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006499 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
6500 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
6501}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006502private function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006503 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
6504 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
6505 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
6506 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
6507}
Vadim Yanitskiy8239dd92020-07-04 20:31:35 +07006508private function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
Stefan Sperling4880be42018-08-07 18:12:59 +02006509 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
6510 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
6511 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
6512 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
6513 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
6514 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
6515 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
6516 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
6517}
6518
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006519private function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006520 var L1ctlDlMessage dl;
6521 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
6522 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
6523 var GsmFrameNumber first_fn;
6524 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006525 var integer nfill_frames_sacch := 0;
6526 var integer nfill_frames_nonsacch := 0;
6527 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02006528 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
6529 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006530 const integer frame_dtx_tchf_mod := 104;
6531 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
6532 * which operates in terms of blocks rather than frames. */
6533 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
6534 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02006535 timer T := 5.0;
6536
6537 f_l1_tune(L1CTL);
6538 RSL.clear;
6539 L1CTL.clear;
6540
6541 /* activate TCHF signalling channel */
6542 f_est_dchan(false);
6543
6544 T.start;
6545 alt {
6546 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
6547 var GsmFrameNumber fn := dl.dl_info.frame_nr;
6548 var octetstring l2 := dl.payload.data_ind.payload;
6549
6550 if (is_first_frame) {
6551 is_first_frame := false;
6552 first_fn := dl.dl_info.frame_nr;
6553 }
6554
6555 if (dl.dl_info.link_id.c == SACCH) {
6556 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
6557 if (not match(l2_fill_frame_sacch, l2)) {
6558 repeat;
6559 }
6560 } else if (not match(l2_fill_frame, l2)) {
6561 repeat;
6562 }
6563
6564 if (dtxd) {
6565 if (not f_g_chan_is_tchf()) {
6566 T.stop;
6567 f_rsl_chan_deact();
6568 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006569 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 +02006570 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006571 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006572 T.stop;
6573 f_rsl_chan_deact();
6574 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006575
6576 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
6577 * 2 SACCH, 1 TCH/F */
6578 expected_fill_frames := 3;
6579
6580 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
6581 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6582 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006584 } else {
6585 setverdict(pass);
6586 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006587 } else {
6588 if (dl.dl_info.link_id.c == SACCH) {
6589 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02006590 repeat;
6591 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006592 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
6593 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
6594 * we should only see the subset of frames numbers which correspond to a block boundary.
6595 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
6596 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
6597 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
6598 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6599 repeat;
6600 }
6601 }
6602 log("Received DTX TCH fill frame with bad frame number: ", fn,
6603 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
6604 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
6605 f_rsl_chan_deact();
6606 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006607 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006608 }
Stefan Sperling4880be42018-08-07 18:12:59 +02006609 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006610 if (dl.dl_info.link_id.c == SACCH) {
6611 nfill_frames_sacch := nfill_frames_sacch + 1;
6612 } else {
6613 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
6614 }
6615 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006616 T.stop;
6617 if (f_g_chan_is_tchf()) {
6618 /* Without DTX we can expect 25 fill frames for every 104 frames.
6619 * (24 FACCH + 1 SACCH filling) */
6620 expected_fill_frames := 25;
6621 } else if (f_g_chan_is_tchh()) {
6622 /* We can expect 2 fill frames for every 104 frames. */
6623 expected_fill_frames := 2;
6624 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
6625 /* We can expect 5 fill frames for every 104 frames. */
6626 expected_fill_frames := 5;
6627 } else {
6628 f_rsl_chan_deact();
6629 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006630 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02006631 }
6632
6633 f_rsl_chan_deact();
6634 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006635
6636 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02006637 setverdict(pass);
6638 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02006639 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
6640 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006641 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02006642 }
6643 } else {
6644 repeat;
6645 }
6646 }
6647 }
6648 [] L1CTL.receive { repeat; }
6649 [] T.timeout {
6650 f_rsl_chan_deact();
6651 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02006652 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02006653 }
6654 }
6655}
6656
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006657private function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006658 f_test_l2_fill_frames(false);
6659}
6660
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006661private function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
Stefan Sperling4880be42018-08-07 18:12:59 +02006662 f_test_l2_fill_frames(true);
6663}
6664
Vadim Yanitskiy71c39ea2020-07-04 20:44:42 +07006665private function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
Stefan Sperling4880be42018-08-07 18:12:59 +02006666 var ConnHdlr vc_conn;
6667 var ConnHdlrPars pars;
6668 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02006669 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02006670 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
6671 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
6672 if (dtxd) {
6673 if (i >= 4) { /* DTX is only allowed on TCH/F */
6674 break;
6675 }
6676 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
6677 } else {
6678 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
6679 }
6680 vc_conn.done;
6681 }
6682}
6683
6684/* Verify that L2 fill frames are sent on TCH in signaling mode if
6685 * there is nothing to transmit while DTX is disabled on downlink. */
6686testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
6687 f_tch_sign_l2_fill_frame(false);
6688}
6689
6690/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
6691 * there is nothing to transmit while DTX is enabled on downlink. */
6692testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
6693 f_tch_sign_l2_fill_frame(true);
6694}
Harald Welte0472ab42018-03-12 15:02:26 +01006695
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006696testcase TC_chopped_ipa_ping() runs on test_CT {
6697 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6698}
6699
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006700testcase TC_chopped_ipa_payload() runs on test_CT {
6701 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
6702}
6703
Harald Welte0472ab42018-03-12 15:02:26 +01006704/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
6705/* protocol error as per 44.006 */
6706/* link layer failure (repetition of I-frame N200 times without ACK */
6707/* repetition of SABM or DISC N200 times without ACK */
6708/* receptiom of SABM in multi-frame established state */
6709
6710
Harald Welte68e495b2018-02-25 00:05:57 +01006711/* TODO Areas:
6712
6713* channel activation
6714** with BS_Power / MS_Power, bypassing power control loop
6715** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01006716** with timing advance from initial activation on
6717* mode modify
6718** encryption
6719** multirate
6720* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01006721** unsupported algorithm
6722* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01006723* BS Power Control
6724* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01006725* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01006726* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01006727** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01006728* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01006729** DATA_IND from BTS->PCU
6730** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01006731
6732*/
Harald Welte70767382018-02-21 12:16:40 +01006733
6734control {
6735 execute( TC_chan_act_stress() );
6736 execute( TC_chan_act_react() );
6737 execute( TC_chan_deact_not_active() );
6738 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01006739 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01006740 execute( TC_sacch_filling() );
6741 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01006742 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01006743 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02006744 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02006745 execute( TC_sacch_chan_act_ho_async() );
6746 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006747 execute( TC_rach_content() );
Philipp Maier16ade782020-07-08 21:36:00 +02006748 execute( TC_rach_content_emerg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01006749 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01006750 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07006751 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02006752 execute( TC_rach_load_idle_thresh0() );
6753 execute( TC_rach_load_idle_below_thresh() );
6754 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01006755 execute( TC_meas_res_sign_tchf() );
6756 execute( TC_meas_res_sign_tchh() );
6757 execute( TC_meas_res_sign_sdcch4() );
6758 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01006759 execute( TC_meas_res_sign_tchh_toa256() );
Pau Espin Pedrola2e079c2020-06-03 17:31:04 +02006760 execute( TC_tx_power_start_ramp_up_bcch() );
Pau Espin Pedrolb6985f92020-06-23 14:01:02 +02006761 execute( TC_tx_power_start_ramp_down_bcch() );
Pau Espin Pedrol45fe5e02020-06-23 19:00:00 +02006762 execute( TC_tx_power_ramp_adm_state_change() );
Eric Wildae8f2622019-06-18 17:05:11 +02006763 execute( TC_rsl_bs_pwr_static_ass() );
6764 execute( TC_rsl_bs_pwr_static_power_control() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01006765 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild280ccb82019-06-17 11:11:52 +02006766 execute( TC_rsl_ms_pwr_dyn_active() );
Eric Wild095024b2019-06-17 15:08:57 +02006767 execute( TC_rsl_ms_pwr_dyn_active2() );
Eric Wild61edb7e2019-06-03 12:38:31 +02006768 execute( TC_rsl_ms_pwr_dyn_up() );
6769 execute( TC_rsl_ms_pwr_dyn_down() );
6770 execute( TC_rsl_ms_pwr_dyn_ass_updown() );
6771 execute( TC_rsl_ms_pwr_dyn_max() );
Eric Wilde57e1a62019-05-28 13:30:55 +02006772 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02006773 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02006774 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01006775 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01006776 execute( TC_paging_imsi_80percent() );
6777 execute( TC_paging_tmsi_80percent() );
6778 execute( TC_paging_imsi_200percent() );
6779 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01006780 execute( TC_rsl_protocol_error() );
6781 execute( TC_rsl_mand_ie_error() );
6782 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01006783 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01006784 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01006785 execute( TC_si_sched_2bis() );
6786 execute( TC_si_sched_2ter() );
6787 execute( TC_si_sched_2ter_2bis() );
6788 execute( TC_si_sched_2quater() );
6789 execute( TC_si_sched_13() );
6790 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01006791 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01006792 execute( TC_ipa_crcx_twice_not_active() );
6793 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01006794 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01006795 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01006796
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006797 if (mp_pcu_socket != "") {
6798 execute( TC_pcu_act_req() );
6799 execute( TC_pcu_act_req_wrong_ts() );
6800 execute( TC_pcu_act_req_wrong_bts() );
6801 execute( TC_pcu_act_req_wrong_trx() );
6802 execute( TC_pcu_deact_req() );
6803 execute( TC_pcu_deact_req_wrong_ts() );
6804 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02006805 if (mp_l1_supports_gprs) {
6806 execute( TC_pcu_data_req_pdtch() );
6807 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02006808 execute( TC_pcu_data_req_wrong_bts() );
6809 execute( TC_pcu_data_req_wrong_trx() );
6810 execute( TC_pcu_data_req_wrong_ts() );
6811 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02006812 }
Vadim Yanitskiy970b1532019-10-24 15:22:19 +07006813 execute( TC_pcu_ptcch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006814 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02006815 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006816 execute( TC_pcu_data_req_imm_ass_pch() );
6817 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07006818 execute( TC_pcu_ext_rach_content() );
Vadim Yanitskiya2c68e82019-07-03 13:07:20 +07006819 execute( TC_pcu_data_ind_lqual_cb() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006820 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02006821 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02006822 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02006823 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02006824 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02006825 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02006826 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02006827 execute( TC_pcu_socket_noconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006828 execute( TC_pcu_socket_noconnect_nosi4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006829 execute( TC_pcu_socket_connect_si3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006830 execute( TC_pcu_socket_connect_si4gprs() );
Harald Weltebe030482019-05-27 22:29:35 +02006831 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Vadim Yanitskiya8e83a82020-05-04 16:05:12 +07006832 execute( TC_pcu_socket_disconnect_nosi4gprs() );
Oliver Smithf5239c72019-08-28 10:01:25 +02006833 execute( TC_pcu_socket_verify_info_ind() );
Philipp Maier15cd6872020-01-08 13:41:41 +01006834 execute( TC_dyn_osmo_pdch_act_deact() );
6835 execute( TC_dyn_osmo_pdch_double_act() );
6836 execute( TC_dyn_ipa_pdch_act_deact() );
6837 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
6838
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01006839 } else {
6840 log("PCU socket path not available, skipping PCU tests");
6841 }
Harald Welte3d04ae62018-04-04 20:29:05 +02006842
Harald Welte3d04ae62018-04-04 20:29:05 +02006843 execute( TC_dyn_osmo_pdch_unsol_deact() );
Harald Welte3d04ae62018-04-04 20:29:05 +02006844 execute( TC_dyn_osmo_pdch_tchf_act() );
6845 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02006846 execute( TC_dyn_ipa_pdch_tchf_act() );
6847 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01006848
6849 execute( TC_rll_est_ind() );
6850 execute( TC_rll_est_req_DCCH_3() );
6851 execute( TC_rll_est_req_ACCH_3() );
6852 execute( TC_rll_rel_ind_DCCH_0() );
6853 execute( TC_rll_rel_ind_DCCH_3() );
6854 execute( TC_rll_rel_ind_ACCH_0() );
6855 execute( TC_rll_rel_ind_ACCH_3() );
6856 execute( TC_rll_rel_req() );
6857 execute( TC_rll_unit_data_req_DCCH() );
6858 execute( TC_rll_unit_data_req_ACCH() );
6859 execute( TC_rll_unit_data_ind_DCCH() );
6860 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02006861
6862 execute( TC_chan_act_a51() );
6863 execute( TC_chan_act_a52() );
6864 execute( TC_chan_act_a53() );
6865 execute( TC_encr_cmd_a51() );
6866 execute( TC_encr_cmd_a52() );
6867 execute( TC_encr_cmd_a53() );
6868
Harald Welteee25aae2019-05-19 14:32:37 +02006869 execute( TC_err_rep_wrong_mdisc() );
6870 execute( TC_err_rep_wrong_msg_type() );
6871 execute( TC_err_rep_wrong_sequence() );
6872
Harald Weltee613f962018-04-18 22:38:16 +02006873 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02006874
6875 execute( TC_tch_sign_l2_fill_frame() );
6876 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02006877
6878 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006879 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01006880}
6881
6882
6883}