blob: e56e033163054db1db2ce4be1d3e7fc1ce4fb18d [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +01004import from General_Types all;
5import from GSM_Types all;
6import from GSM_RR_Types all;
7import from Osmocom_Types all;
8import from GSM_Types all;
Harald Welte82ccef72018-02-25 16:17:33 +01009import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010010import from L1CTL_PortType all;
11import from L1CTL_Types all;
12import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020013import from LAPDm_RAW_PT all;
Harald Welte70767382018-02-21 12:16:40 +010014import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020015import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010016
17import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010018import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010019import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020020import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010021import from RSL_Emulation all;
22
23import from IPL4asp_Types all;
24import from TRXC_Types all;
25import from TRXC_CodecPort all;
26import from TRXC_CodecPort_CtrlFunct all;
27
Harald Welte883340c2018-02-28 18:59:29 +010028import from PCUIF_Types all;
29import from PCUIF_CodecPort all;
30
Harald Welte7484fc42018-02-24 14:09:45 +010031import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010032import from MobileL3_RRM_Types all;
33import from MobileL3_Types all;
34import from L3_Templates all;
Harald Welte7484fc42018-02-24 14:09:45 +010035
Harald Welte8da48242018-02-27 20:41:32 +010036import from Osmocom_VTY_Functions all;
37import from TELNETasp_PortType all;
38
Harald Welte505cf9b2018-09-15 17:47:23 +030039friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020040friend module BTS_Tests_virtphy;
Harald Welte505cf9b2018-09-15 17:47:23 +030041
Harald Welte70767382018-02-21 12:16:40 +010042/* The tests assume a BTS with the following timeslot configuration:
43 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020044 * TS1 : TCH/F
45 * TS2 : TCH/F
46 * TS3 : TCH/F_PDCH (IPA Style)
47 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010048 * TS5 : TCH/H
49 * TS6 : SDCCH/8
50 * TS7 : PDCH
51 */
52
53modulepar {
54 charstring mp_rsl_ip := "127.0.0.2";
55 integer mp_rsl_port := 3003;
56 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070057 charstring mp_bts_trxc_ip := "127.0.0.1";
58 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010059 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020060 charstring mp_ctrl_ip := "127.0.0.1";
61 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020062 charstring mp_bsc_ctrl_ip := "127.0.0.1";
63 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020064 integer mp_tolerance_rxqual := 1;
65 integer mp_tolerance_rxlev := 3;
66 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020067 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020068 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020069 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020070 integer mp_ms_actual_ta_exp := 0;
71 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +010072 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +020073 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +020074 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +020075 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
76 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +010077}
78
Harald Welte629cc6b2018-03-11 17:19:05 +010079type record of RslChannelNr ChannelNrs;
80
Harald Welte70767382018-02-21 12:16:40 +010081type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +010082 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +010083 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +010084 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +010085 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +010086 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +010087 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +010088
89 /* L1CTL port (for classic tests) */
90 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +010091
Harald Welte54a2a2d2018-02-26 09:14:05 +010092 /* TRXC port (for classic tests) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070093 port TRXC_CODEC_PT BTS_TRXC;
94 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +010095
Harald Weltef50e3ae2018-09-10 10:27:56 +020096 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +010097 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +020098 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +010099
Harald Welte883340c2018-02-28 18:59:29 +0100100 /* PCU Interface of BTS */
101 port PCUIF_CODEC_PT PCU;
102 var integer g_pcu_conn_id;
103 /* Last PCU INFO IND we received */
104 var PCUIF_Message g_pcu_last_info;
105
Harald Welte48494ca2018-02-25 16:59:50 +0100106 /* SI configuration */
107 var SystemInformationConfig si_cfg := {
108 bcch_extended := false,
109 si1_present := false,
110 si2bis_present := false,
111 si2ter_present := false,
112 si2quater_present := false,
113 si7_present := false,
114 si8_present := false,
115 si9_present := false,
116 si13_present := false,
117 si13alt_present := false,
118 si15_present := false,
119 si16_present := false,
120 si17_present := false,
121 si2n_present := false,
122 si21_present := false,
123 si22_present := false
124 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100125
126 /* all logical channels available on the BTS */
127 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100128 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100129}
130
131/* an individual call / channel */
132type component ConnHdlr extends RSL_DchanHdlr {
133 port L1CTL_PT L1CTL;
134
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700135 port TRXC_CODEC_PT BTS_TRXC;
136 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100137
138 timer g_Tguard;
139 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
140
141 var ConnHdlrPars g_pars;
142 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100143 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200144
145 /* PCU Interface of BTS */
146 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100147}
148
149function f_init_rsl(charstring id) runs on test_CT {
150 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
151 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
152
153 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
154 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
155 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
156
157 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
158 vc_RSL.start(RSL_Emulation.main(false));
159}
160
161type record ConnHdlrPars {
162 RslChannelNr chan_nr,
163 RSL_IE_ChannelMode chan_mode,
164 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100165 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200166 TestSpecUnion spec optional,
167 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100168}
169
170/* Test-specific parameters */
171type union TestSpecUnion {
172 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100173}
174
Harald Welte82ccef72018-02-25 16:17:33 +0100175template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100176 max_retrans := RACH_MAX_RETRANS_7,
177 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100178 cell_barr_access := false,
179 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100180 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100181};
182
Harald Weltef10153f2018-02-25 16:34:05 +0100183template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100184 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200185 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100186 acs := '0'B,
187 neci := true,
188 rxlev_access_min := 0
189}
190
191template (value) LocationAreaIdentification ts_LAI_default := {
192 mcc_mnc := '262F42'H,
193 lac := 42
194}
195
Harald Welte7484fc42018-02-24 14:09:45 +0100196/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100197template (value) SystemInformation ts_SI3_default := {
198 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100199 payload := {
200 si3 := {
201 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100202 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100203 ctrl_chan_desc := {
204 msc_r99 := true,
205 att := true,
206 bs_ag_blks_res := 1,
207 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100208 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100209 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
210 spare := '00'B,
211 bs_pa_mfrms := 0, /* 2 multiframes */
212 t3212 := 1 /* 6 minutes */
213 },
Harald Welte82ccef72018-02-25 16:17:33 +0100214 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100215 dn_ind := false,
216 pwrc := false,
217 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100218 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100219 },
Harald Weltef10153f2018-02-25 16:34:05 +0100220 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100221 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100222 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100223 }
224 }
225}
Harald Welte70767382018-02-21 12:16:40 +0100226
Harald Weltef8df4cb2018-03-10 15:15:08 +0100227template (value) SystemInformation ts_SI2_default := {
228 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100229 payload := {
230 si2 := {
231 bcch_freq_list := '00000000000000000000000000000000'O,
232 ncc_permitted := '11111111'B,
233 rach_control := ts_RachCtrl_default
234 }
235 }
236}
237
Harald Weltef8df4cb2018-03-10 15:15:08 +0100238template (value) SystemInformation ts_SI4_default := {
239 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100240 payload := {
241 si4 := {
242 lai := ts_LAI_default,
243 cell_sel_par := ts_CellSelPar_default,
244 rach_control := ts_RachCtrl_default,
245 cbch_chan_desc := omit,
246 cbch_mobile_alloc := omit,
247 rest_octets := ''O
248 }
249 }
250}
251
252function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
253runs on test_CT {
254 log("Setting ", rsl_si_type, ": ", si_enc);
255 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
256}
257
258function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
259runs on test_CT {
260 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
261 log("Setting ", rsl_si_type, ": ", si_dec);
262 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
263}
264
Harald Welte505cf9b2018-09-15 17:47:23 +0300265friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100266 map(self:BTSVTY, system:BTSVTY);
267 f_vty_set_prompts(BTSVTY);
268 f_vty_transceive(BTSVTY, "enable");
269}
270
Harald Welte505cf9b2018-09-15 17:47:23 +0300271friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200272 map(self:BSCVTY, system:BSCVTY);
273 f_vty_set_prompts(BSCVTY, "OsmoBSC");
274 f_vty_transceive(BSCVTY, "enable");
275}
276
Harald Welte883340c2018-02-28 18:59:29 +0100277/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200278private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
279 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100280 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200281 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
282 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100283 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200284 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200285 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100286 }
287}
288
Harald Weltef26de0b2018-04-04 20:28:05 +0200289private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
290 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100291 timer T := 2.0;
292 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100293 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200294 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100295 return;
296 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200297 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100298
299 T.start;
300 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200301 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100302 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200303 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100304 }
305 }
306}
307
Harald Welte70767382018-02-21 12:16:40 +0100308/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100309function f_init(charstring id := "BTS-Test") runs on test_CT {
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100310 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100311 g_AllChannels := {
312 /* TS 1..4: TCH/F */
313 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
314 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
315 /* TS 5: TCH/H */
316 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
317 /* TS 0: SDCCH/4 */
318 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
319 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
320 /* TS 6: SDCCH/8 */
321 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
322 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
323 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
324 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
325 };
326
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200327 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700328 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200329 g_AllChanTypes := {
330 /* TS 1..4: TCH/F */
331 valueof(ts_RslChanNr_Bm(1)),
332 /* TS 5: TCH/H */
333 valueof(ts_RslChanNr_Lm(5,1)),
334 /* TS 0: SDCCH/4 */
335 valueof(ts_RslChanNr_SDCCH4(0,2)),
336 /* TS 6: SDCCH/8 */
337 valueof(ts_RslChanNr_SDCCH8(6,4))
338 };
339 } else {
340 g_AllChanTypes := {
341 /* TS 1..4: TCH/F */
342 valueof(ts_RslChanNr_Bm(1)),
343 /* TS 0: SDCCH/4 */
344 valueof(ts_RslChanNr_SDCCH4(0,2)),
345 /* TS 6: SDCCH/8 */
346 valueof(ts_RslChanNr_SDCCH8(6,4))
347 };
348 }
Harald Welte70767382018-02-21 12:16:40 +0100349 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200350 T.start;
351 alt {
352 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
353 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200354 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200355 }
356 }
Harald Welte2d142592018-02-25 13:19:44 +0100357 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100358 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200359 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100360
361 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100362 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
363 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
364 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
365 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100366
Harald Weltef26de0b2018-04-04 20:28:05 +0200367 map(self:PCU, system:PCU);
368 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100369
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700370 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100371 var TrxcMessage ret;
372 /* start with a default moderate timing offset equalling TA=2 */
373 f_main_trxc_connect();
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700374 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Harald Welte84271622018-03-10 17:21:03 +0100375 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200376
377 /* Wait some extra time to make sure the BTS emits a stable carrier.
378 * (this is only relevant when running the tests with a physical BTS.) */
379 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100380}
381
Harald Welte68e495b2018-02-25 00:05:57 +0100382/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
383function f_init_l1ctl() runs on test_CT {
384 map(self:L1CTL, system:L1CTL);
385 f_connect_reset(L1CTL);
386}
387
Harald Welte70767382018-02-21 12:16:40 +0100388type function void_fn(charstring id) runs on ConnHdlr;
389
390/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200391function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100392runs on test_CT return ConnHdlr {
393 var charstring id := testcasename();
394 var ConnHdlr vc_conn;
395
396 vc_conn := ConnHdlr.create(id);
397 /* connect to RSL Emulation main component */
398 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
399 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200400 if (pcu_comp) {
401 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
402 * it from the test_CT and connect it to the component. This obviously only
403 * works for one component, i.e. no concurrency */
404 unmap(self:PCU, system:PCU);
405 map(vc_conn:PCU, system:PCU);
406 }
Harald Welte70767382018-02-21 12:16:40 +0100407
408 vc_conn.start(f_handler_init(fn, id, pars));
409 return vc_conn;
410}
411
Harald Welte7484fc42018-02-24 14:09:45 +0100412template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
413 streamId := sid,
414 rsl := rsl
415}
416
417template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
418 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
419 streamId := sid,
420 rsl := rsl
421}
422
Harald Welte70767382018-02-21 12:16:40 +0100423private altstep as_Tguard() runs on ConnHdlr {
424 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100426 }
427}
428
Harald Welte505cf9b2018-09-15 17:47:23 +0300429friend function f_l1_tune(L1CTL_PT L1CTL) {
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200430 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100431}
432
433private function f_trxc_connect() runs on ConnHdlr {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700434 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte70767382018-02-21 12:16:40 +0100435 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700436 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Weltea4d8f352018-03-01 15:47:20 +0100437 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200438 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Could not connect to trx-control interface of trxcon, check your configuration");
Harald Welte9220f632018-05-23 20:27:02 +0200440 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700441 g_bts_trxc_conn_id := res.connId;
Harald Welte70767382018-02-21 12:16:40 +0100442}
443
444private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100445 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700446 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100447}
448
449private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100450 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700451 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100452}
453
454/* first function started in ConnHdlr component */
455private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
456runs on ConnHdlr {
457 g_pars := pars;
458 g_chan_nr := pars.chan_nr;
459
460 map(self:L1CTL, system:L1CTL);
461 f_connect_reset(L1CTL);
462
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700463 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100464 f_trxc_connect();
465 }
Harald Welte70767382018-02-21 12:16:40 +0100466
467 g_Tguard.start(pars.t_guard);
468 activate(as_Tguard());
469
470 f_rslem_register(0, pars.chan_nr);
471
472 /* call the user-supplied test case function */
473 fn.apply(id);
474}
475
Harald Welteb1726c92018-03-30 11:56:38 +0200476function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
477 boolean ignore_other := false)
478runs on ConnHdlr return RSL_Message {
479 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100480 timer T := 3.0;
481 RSL.send(tx);
482 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100483 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200484 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100485 T.stop;
486 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100487 }
Harald Welte1eba3742018-02-25 12:48:14 +0100488 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200489 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100490 }
Harald Welte21240e62018-03-11 21:43:35 +0100491 [not ignore_other] as_l1_sacch();
492 [not ignore_other] as_meas_res();
493 [not ignore_other] as_l1_dcch();
494 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100496 }
Harald Welte21240e62018-03-11 21:43:35 +0100497 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100498 }
Harald Welteb1726c92018-03-30 11:56:38 +0200499 return rx;
500}
501
502function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
503 boolean ignore_other := false)
504runs on ConnHdlr {
505 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100506}
507
Harald Welte8b01c792019-05-19 22:51:25 +0200508function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
509 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
510 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200511 if (encr_enable) {
512 /* append encryption related IEs, if requested */
513 var RSL_IE_EncryptionInfo encr_info;
514 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
515 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
516encr_info})) };
517 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200518 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200519 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100520}
521
Harald Welte70767382018-02-21 12:16:40 +0100522function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100523 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 +0100524 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100525}
526
Harald Welte70767382018-02-21 12:16:40 +0100527private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
528 template RSL_IE_ChannelMode chan_mode,
529 float t_guard := 20.0) := {
530 chan_nr := valueof(chan_nr),
531 chan_mode := valueof(chan_mode),
532 t_guard := t_guard,
533 l1_pars := {
534 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100535 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100536 meas_ul := {
537 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200538 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100539 rxqual := 0
540 },
541 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200542 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100543 rxqual := 0
544 }
545 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200546 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100547 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200548 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200549 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100550 },
Harald Weltee613f962018-04-18 22:38:16 +0200551 spec := omit,
552 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100553}
554
Harald Welte93640c62018-02-25 16:59:33 +0100555/***********************************************************************
556 * Channel Activation / Deactivation
557 ***********************************************************************/
558
Harald Welte70767382018-02-21 12:16:40 +0100559/* Stress test: Do 500 channel activations/deactivations in rapid succession */
560function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
561 for (var integer i := 0; i < 500; i := i+1) {
562 f_rsl_chan_act(g_pars.chan_mode);
563 f_rsl_chan_deact();
564 }
565 setverdict(pass);
566}
567testcase TC_chan_act_stress() runs on test_CT {
568 var ConnHdlr vc_conn;
569 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
570 f_init(testcasename());
571 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
572 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200573 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100574}
575
576/* Test if re-activation of an already active channel fails as expected */
577function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
578 f_rsl_chan_act(g_pars.chan_mode);
579 /* attempt to activate the same lchan again -> expect reject */
580 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
581 alt {
582 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100584 }
585 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
586 setverdict(pass);
587 }
588 }
589 f_rsl_chan_deact();
590}
591testcase TC_chan_act_react() runs on test_CT {
592 var ConnHdlr vc_conn;
593 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100594 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100595 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
596 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200597 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100598}
599
600/* Attempt to de-activate a channel that's not active */
601function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
602 timer T := 3.0;
603 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
604 T.start;
605 alt {
606 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
607 setverdict(pass);
608 }
609 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200610 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100611 }
612 }
613}
614testcase TC_chan_deact_not_active() runs on test_CT {
615 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100616 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100617 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
618 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200619 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100620}
621
622/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
623function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
624 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
625 alt {
626 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100628 }
629 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
630 setverdict(pass);
631 }
632 }
633}
634private type record WrongChanNrCase {
635 RslChannelNr chan_nr,
636 charstring description
637}
638private type record of WrongChanNrCase WrongChanNrCases;
639private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
640 chan_nr := chan_nr,
641 description := desc
642}
643
644testcase TC_chan_act_wrong_nr() runs on test_CT {
645 var ConnHdlr vc_conn;
646 var ConnHdlrPars pars;
647
Harald Welte294b0a22018-03-10 23:26:48 +0100648 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100649
650 var WrongChanNrCases wrong := {
651 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
652 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
653 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
654 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
655 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
656 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
657 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
658 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
659 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
660 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
661 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
662 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
663 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
664 };
665
666 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
667 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
668 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
669 vc_conn.done;
670 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100672}
673
Harald Weltee613f962018-04-18 22:38:16 +0200674/* execute the same callback function on a variety of logical channels */
675private function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
676 var ConnHdlr vc_conn;
677 f_init(testcasename());
678
679 /* test on each of the channels we have */
680 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
681 pars.chan_nr := valueof(g_AllChanTypes[i]);
682
683 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
684 vc_conn := f_start_handler(fn, pars);
685 vc_conn.done;
686 }
687
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200689}
690
Harald Welte93640c62018-02-25 16:59:33 +0100691/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100692 * SACCH handling
693 ***********************************************************************/
694
695private function f_exp_sacch(boolean exp) runs on ConnHdlr {
696 timer T_sacch := 3.0;
697 T_sacch.start;
698 alt {
699 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100701 }
702 [not exp] T_sacch.timeout {
703 setverdict(pass);
704 }
705 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
706 setverdict(pass);
707 }
708 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100710 }
711 [] L1CTL.receive { repeat; }
712 [] RSL.receive { repeat; }
713 }
714}
715
716/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
717private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
718 f_l1_tune(L1CTL);
719 RSL.clear;
720
721 /* activate the logical channel */
722 f_est_dchan();
723 L1CTL.clear;
724
725 /* check that SACCH actually are received as expected */
726 f_exp_sacch(true);
727
728 /* deactivate SACCH on the logical channel */
729 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
730 f_sleep(1.0);
731 L1CTL.clear;
732
733 /* check that no SACCH are received anymore */
734 f_exp_sacch(false);
735
736 /* release the channel */
737 f_rsl_chan_deact();
738 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
739}
740testcase TC_deact_sacch() runs on test_CT {
741 var ConnHdlr vc_conn;
742 var ConnHdlrPars pars;
743 f_init();
744 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
745 //for (var integer i := 0; i < 1; i := i+1) {
746 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
747 log(testcasename(), ": Starting for ", g_AllChannels[i]);
748 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
749 vc_conn.done;
750 }
751 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200752 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100753}
754
Harald Welte55700662018-03-12 13:15:43 +0100755/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100756private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
757 var L1ctlDlMessage dl;
758 /* check that the specified SI5 value is actually sent */
759 timer T_sacch := 3.0;
760 L1CTL.clear;
761 T_sacch.start;
762 alt {
763 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
764 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
765 if (match(l3, l3_exp)) {
766 setverdict(pass);
767 } else {
768 repeat;
769 }
770 }
771 [] L1CTL.receive { repeat; }
772 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100774 }
775 }
776}
777
Harald Welte55700662018-03-12 13:15:43 +0100778/* verify that given SACCH payload is not present */
779private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
780 var L1ctlDlMessage dl;
781 /* check that the specified SI5 value is actually sent */
782 timer T_sacch := 3.0;
783 L1CTL.clear;
784 T_sacch.start;
785 alt {
786 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
787 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
788 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200789 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100790 } else {
791 repeat;
792 }
793 }
794 [] L1CTL.receive { repeat; }
795 [] T_sacch.timeout {
796 setverdict(pass);
797 }
798 }
799}
800
Harald Welte629cc6b2018-03-11 17:19:05 +0100801/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100802private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
803 /* Set a known default SACCH filling for SI5 */
804 var octetstring si5 := f_rnd_octstring(19);
805 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
806
807 f_l1_tune(L1CTL);
808 RSL.clear;
809
810 /* activate the logical channel */
811 f_est_dchan();
812
813 /* check that the specified SI5 value is actually sent */
814 f_sacch_present(si5);
815
816 /* release the channel */
817 RSL.clear;
818 f_rsl_chan_deact();
819 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
820}
821testcase TC_sacch_filling() runs on test_CT {
822 var ConnHdlr vc_conn;
823 var ConnHdlrPars pars;
824 f_init();
825 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
826 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
827 log(testcasename(), ": Starting for ", g_AllChannels[i]);
828 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
829 vc_conn.done;
830 }
831 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200832 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100833}
834
Harald Welte629cc6b2018-03-11 17:19:05 +0100835/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100836private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
837 /* Set a known default SACCH filling for SI5 */
838 var octetstring si5 := f_rnd_octstring(19);
839 var octetstring si5_diff := f_rnd_octstring(19);
840 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
841
842 f_l1_tune(L1CTL);
843 RSL.clear;
844
845 log("Activating channel, expecting standard SI5");
846 /* activate the logical channel */
847 f_est_dchan();
848 /* check that the specified SI5 value is actually sent */
849 f_sacch_present(si5);
850
851 /* set channel-specific different SI5 */
852 log("Setting channel specific SACCH INFO, expecting it");
853 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
854 /* check that the specified lchan-specific value is now used */
855 f_sacch_present(si5_diff);
856
857 /* deactivate the channel and re-activate it, this should result in default SI5 */
858 log("De-activating and re-activating channel, expecting standard SI5");
859 f_rsl_chan_deact();
860 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
861 /* Verify that the TRX-wide default SACCH filling is present again */
862 f_sacch_present(si5);
863
864 /* release the channel */
865 RSL.clear;
866 f_rsl_chan_deact();
867 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
868}
869testcase TC_sacch_info_mod() runs on test_CT {
870 var ConnHdlr vc_conn;
871 var ConnHdlrPars pars;
872 f_init();
873 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
874 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
875 log(testcasename(), ": Starting for ", g_AllChannels[i]);
876 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
877 vc_conn.done;
878 }
879 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200880 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100881}
882
Harald Welte075d84c2018-03-12 13:07:24 +0100883/* Test SACCH scheduling of multiple different SI message types */
884private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
885 var octetstring si5 := f_rnd_octstring(19);
886 var octetstring si5bis := f_rnd_octstring(19);
887 var octetstring si5ter := f_rnd_octstring(19);
888 var octetstring si6 := f_rnd_octstring(19);
889
890 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
891 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
892 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
893 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
894
895 f_l1_tune(L1CTL);
896 RSL.clear;
897
898 /* activate the logical channel */
899 f_est_dchan();
900 L1CTL.clear;
901
902 /* check that SACCH actually are received as expected */
903 f_sacch_present(si5);
904 f_sacch_present(si5bis);
905 f_sacch_present(si5ter);
906 f_sacch_present(si6);
907
908 /* release the channel */
909 f_rsl_chan_deact();
910 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
911}
912testcase TC_sacch_multi() 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 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
918 log(testcasename(), ": Starting for ", g_AllChannels[i]);
919 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
920 vc_conn.done;
921 }
922 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200923 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100924}
925
Harald Welte55700662018-03-12 13:15:43 +0100926/* Test if SACH information is modified as expected */
927private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
928 var octetstring si5 := f_rnd_octstring(19);
929 var octetstring si6 := f_rnd_octstring(19);
930
931 /* First, configure both SI5 and SI6 to be transmitted */
932 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
933 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
934
935 f_l1_tune(L1CTL);
936 RSL.clear;
937
938 /* activate the logical channel */
939 f_est_dchan();
940 L1CTL.clear;
941
942 /* check that SACCH actually are received as expected */
943 f_sacch_present(si5);
944 f_sacch_present(si6);
945
946 /* disable SI6 */
947 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
948
949 /* check that SI5 is still transmitted */
950 f_sacch_present(si5);
951 /* check if SI6 is now gone */
952 f_sacch_missing(si6);
953
954 /* release the channel */
955 f_rsl_chan_deact();
956 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
957}
958testcase TC_sacch_multi_chg() runs on test_CT {
959 var ConnHdlr vc_conn;
960 var ConnHdlrPars pars;
961 f_init();
962 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
963 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
964 log(testcasename(), ": Starting for ", g_AllChannels[i]);
965 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
966 vc_conn.done;
967 }
968 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200969 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +0100970}
971
Harald Weltec8d363c2019-05-19 20:36:48 +0200972/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
973private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
974 var octetstring si5 := f_rnd_octstring(19);
975 var octetstring si6 := f_rnd_octstring(19);
976 var octetstring si5_specific := f_rnd_octstring(19);
977 var octetstring si6_specific := f_rnd_octstring(19);
978
979 /* First, configure both SI5 and SI6 to be transmitted */
980 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
981 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
982
983 f_l1_tune(L1CTL);
984 RSL.clear;
985
986 /* activate channel with different SACCH filling */
987 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
988 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
989 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
990 }));
991 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
992 RSL_IE_Body:{sacch_info := sacch_info})) };
993 f_est_dchan(more_ies := addl_ies);
994
995 /* check that SACCH actually are received as expected */
996 f_sacch_present(si5_specific);
997 f_sacch_present(si6_specific);
998
999 /* release the channel */
1000 f_rsl_chan_deact();
1001 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1002}
1003testcase TC_sacch_chan_act() runs on test_CT {
1004 var ConnHdlr vc_conn;
1005 var ConnHdlrPars pars;
1006 f_init();
1007
1008 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1009 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1010 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1011 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1012 vc_conn.done;
1013 }
1014 /* TODO: do the above in parallel, rather than sequentially? */
1015 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1016}
1017
Harald Welte8b01c792019-05-19 22:51:25 +02001018/* verify that SACCH DL transmission is started only if MS power IE present
1019 * see section 4.1.3 of 3GPP TS 48.058 */
1020private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1021 var octetstring si5 := f_rnd_octstring(19);
1022
1023 f_l1_tune(L1CTL);
1024 RSL.clear;
1025
1026 /* Step 1: Activate ASYNC HO channel without MS power IE */
1027
1028 /* Activate channel on BTS side */
1029 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1030 /* don't perform immediate assignment here, as we're testing non-IA case */
1031 /* enable dedicated mode */
1032 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1033
1034 /* Verify that no DL SACCH is being received */
1035 f_sacch_missing(?);
1036
1037 f_rsl_chan_deact();
1038 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1039
1040
1041 /* Step 2: Activate ASYNC HO channel with MS power IE */
1042
1043 /* Activate channel on BTS side */
1044 var RSL_IE_List addl_ies := {
1045 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1046 };
1047 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1048 /* don't perform immediate assignment here, as we're testing non-IA case */
1049 /* enable dedicated mode */
1050 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1051
1052 /* Verify that DL SACCH is being received */
1053 f_sacch_present(si5);
1054
1055 f_rsl_chan_deact();
1056 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1057}
1058testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1059 var ConnHdlr vc_conn;
1060 var ConnHdlrPars pars;
1061 f_init();
1062
1063 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1064 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1065 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1066 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1067 vc_conn.done;
1068 }
1069 /* TODO: do the above in parallel, rather than sequentially? */
1070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1071}
1072
1073/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1074 * see section 4.1.4 of 3GPP TS 48.058 */
1075private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1076 var octetstring si5 := f_rnd_octstring(19);
1077 var RSL_IE_List addl_ies;
1078
1079 f_l1_tune(L1CTL);
1080 RSL.clear;
1081
1082 /* Step 1: Activate SYNC HO channel without MS power IE */
1083
1084 /* Activate channel on BTS side */
1085 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1086 /* don't perform immediate assignment here, as we're testing non-IA case */
1087 /* enable dedicated mode */
1088 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1089
1090 /* Verify that no DL SACCH is being received */
1091 f_sacch_missing(?);
1092
1093 f_rsl_chan_deact();
1094 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1095
1096
1097 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1098
1099 /* Activate channel on BTS side */
1100 addl_ies := {
1101 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1102 };
1103 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1104 /* don't perform immediate assignment here, as we're testing non-IA case */
1105 /* enable dedicated mode */
1106 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1107
1108 /* Verify that no DL SACCH is being received */
1109 f_sacch_missing(?);
1110
1111 f_rsl_chan_deact();
1112 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1113
1114
1115 /* Step 2b: Activate SYNC HO channel with TA IE */
1116
1117 /* Activate channel on BTS side */
1118 addl_ies := {
1119 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1120 };
1121 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1122 /* don't perform immediate assignment here, as we're testing non-IA case */
1123 /* enable dedicated mode */
1124 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1125
1126 /* Verify that no DL SACCH is being received */
1127 f_sacch_missing(?);
1128
1129 f_rsl_chan_deact();
1130 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1131
1132
1133 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1134
1135 /* Activate channel on BTS side */
1136 addl_ies := {
1137 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1138 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1139 };
1140 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1141 /* don't perform immediate assignment here, as we're testing non-IA case */
1142 /* enable dedicated mode */
1143 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1144
1145 /* Verify that DL SACCH is being received */
1146 f_sacch_present(si5);
1147
1148 f_rsl_chan_deact();
1149 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1150}
1151testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1152 var ConnHdlr vc_conn;
1153 var ConnHdlrPars pars;
1154 f_init();
1155
1156 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1157 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1158 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1159 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1160 vc_conn.done;
1161 }
1162 /* TODO: do the above in parallel, rather than sequentially? */
1163 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1164}
Harald Welte629cc6b2018-03-11 17:19:05 +01001165
1166
1167/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001168 * RACH Handling
1169 ***********************************************************************/
1170
Harald Welte8c24c2b2018-02-26 08:31:31 +01001171/* like L1SAP_IS_PACKET_RACH */
1172private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001173 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001174 return true;
1175 }
1176 return false;
1177}
1178
1179/* generate a random RACH for circuit-switched */
1180private function f_rnd_ra_cs() return OCT1 {
1181 var OCT1 ra;
1182 do {
1183 ra := f_rnd_octstring(1);
1184 } while (ra_is_ps(ra));
1185 return ra;
1186}
1187
Harald Welte883340c2018-02-28 18:59:29 +01001188/* generate a random RACH for packet-switched */
1189private function f_rnd_ra_ps() return OCT1 {
1190 var OCT1 ra;
1191 do {
1192 ra := f_rnd_octstring(1);
1193 } while (not ra_is_ps(ra));
1194 return ra;
1195}
1196
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001197/* generate a random 11-bit RA (packet-switched only) */
1198private function f_rnd_ra11_ps() return BIT11 {
1199 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1200 return int2bit(ra11, 11);
1201}
1202
Harald Welte8c24c2b2018-02-26 08:31:31 +01001203/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1204testcase TC_rach_content() runs on test_CT {
1205 f_init(testcasename());
1206 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001207 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001208
Harald Welte8c24c2b2018-02-26 08:31:31 +01001209 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001210 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001211 for (var integer i := 0; i < 1000; i := i+1) {
1212 var OCT1 ra := f_rnd_ra_cs();
1213 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1214 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001215 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001216 }
1217 fn_last := fn;
1218
1219 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001220 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001221 alt {
1222 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
1223 T.stop;
1224 }
1225 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001227 }
1228 [] RSL_CCHAN.receive { repeat; }
1229 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001230 test_failed := true;
1231 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001232 }
1233 }
1234 }
Maxba06feb2019-03-05 10:52:46 +01001235 if (test_failed) {
1236 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001237 }
Maxba06feb2019-03-05 10:52:46 +01001238 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001240}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001241
1242/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1243testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001244 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001245 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001246 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001247 f_l1_tune(L1CTL);
1248
1249 var GsmFrameNumber fn_last := 0;
1250 for (var integer i := 0; i < 1000; i := i+1) {
1251 var OCT1 ra := f_rnd_ra_cs();
1252 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1253 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001254 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001255 }
1256 fn_last := fn;
1257 }
1258 var integer rsl_chrqd := 0;
1259 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001260 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001261 alt {
1262 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1263 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001264 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001265 repeat;
1266 }
1267 [] RSL_CCHAN.receive { repeat; }
1268 [] T.timeout { }
1269 }
1270 if (rsl_chrqd == 1000) {
1271 setverdict(pass);
1272 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001273 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001274 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001275 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001276}
1277
Harald Welte3453ab42019-05-24 21:19:58 +02001278private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1279 var charstring bts_str := "bts " & int2str(bts_nr);
1280 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1281}
1282
1283/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1284private template integer tr_rach_slots_per_interval := (90 .. 130);
1285
1286/* Expect 0 RACH load on an idle BTS that has just started up */
1287testcase TC_rach_load_idle_thresh0() runs on test_CT {
1288 var ASP_RSL_Unitdata rx_ud;
1289
1290 f_init_vty_bsc();
1291 /* send load indications even at 0% load */
1292 f_vty_load_ind_thresh(0);
1293 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1294 f_sleep(2.0);
1295
1296 f_init();
1297
1298 timer T := 5.0;
1299 T.start;
1300 alt {
1301 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1302 setverdict(pass);
1303 repeat;
1304 }
1305 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1306 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1307 repeat;
1308 }
1309 [] RSL_CCHAN.receive {
1310 repeat;
1311 }
1312 [] T.timeout { }
1313 }
1314
1315 f_vty_load_ind_thresh(10);
1316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1317}
1318
1319/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1320testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1321 var ASP_RSL_Unitdata rx_ud;
1322
1323 f_init_vty_bsc();
1324 f_init();
1325
1326 timer T := 5.0;
1327 T.start;
1328 alt {
1329 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1330 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1331 repeat;
1332 }
1333 [] RSL_CCHAN.receive {
1334 repeat;
1335 }
1336 [] T.timeout {
1337 setverdict(pass);
1338 }
1339 }
1340
1341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1342}
1343
1344/* Expect 0 RACH load on an idle BTS that has just started up */
1345testcase TC_rach_load_count() runs on test_CT {
1346 var ASP_RSL_Unitdata rx_ud;
1347 var integer load_access_count := 0;
1348
1349 f_init_vty_bsc();
1350 /* send load indications even at 0% load */
1351 f_vty_load_ind_thresh(0);
1352 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1353 f_sleep(2.0);
1354 f_init();
1355
1356 f_init_l1ctl();
1357 f_sleep(1.0);
1358 f_l1_tune(L1CTL);
1359
1360 var GsmFrameNumber fn_last := 0;
1361 for (var integer i := 0; i < 1000; i := i+1) {
1362 var OCT1 ra := f_rnd_ra_cs();
1363 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1364 if (fn == fn_last) {
1365 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1366 }
1367 fn_last := fn;
1368 }
1369
1370 timer T := 5.0;
1371 T.start;
1372 alt {
1373 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1374 -> value rx_ud {
1375 var RSL_IE_Body ie;
1376 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1377 load_access_count := load_access_count + ie.rach_load.access_count;
1378 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1379 setverdict(fail, "Access count cannot be < Busy count");
1380 }
1381 repeat;
1382 }
1383 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1384 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1385 repeat;
1386 }
1387 [] RSL_CCHAN.receive {
1388 repeat;
1389 }
1390 [] T.timeout { }
1391 }
1392 if (load_access_count == 1000) {
1393 setverdict(pass);
1394 } else {
1395 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1396 }
1397
1398 f_vty_load_ind_thresh(10);
1399 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1400}
1401
1402
1403
Harald Welte54a2a2d2018-02-26 09:14:05 +01001404private function f_main_trxc_connect() runs on test_CT {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001405 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001406 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001407 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Welted3a88a62018-03-01 16:04:52 +01001408 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001409 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Could not connect to trx-control interface of trxcon, check your configuration");
Harald Welte9220f632018-05-23 20:27:02 +02001411 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001412 g_bts_trxc_conn_id := res.connId;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001413}
1414
1415private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001416 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001417 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001418 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001419 f_sleep(0.5);
1420
1421 /* Transmit RACH request + wait for confirmation */
1422 var OCT1 ra := f_rnd_ra_cs();
1423 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1424
1425 /* Check for expected result */
1426 timer T := 1.5;
1427 T.start;
1428 alt {
1429 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1430 setverdict(pass);
1431 }
1432 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001434 }
1435 [] RSL_CCHAN.receive { repeat; }
1436 [not expect_pass] T.timeout {
1437 setverdict(pass);
1438 }
1439 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001440 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001441 }
1442 }
1443}
1444
1445/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1446testcase TC_rach_max_ta() runs on test_CT {
1447 f_init(testcasename());
1448 f_init_l1ctl();
1449 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001450 f_sleep(1.0);
1451
1452 /* default max-ta is 63 (full range of GSM timing advance */
1453
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001454 /* We allow early arrival up to 2 symbols */
1455 f_rach_toffs(-1*256, true);
1456 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001457 f_rach_toffs(-10*256, false);
1458
1459 /* 0 / 32 / 63 bits is legal / permitted */
1460 f_rach_toffs(0, true);
1461 f_rach_toffs(32*256, true);
1462 f_rach_toffs(63*256, true);
1463
1464 /* more than 63 bits is not legal / permitted */
1465 f_rach_toffs(64*256, false);
1466 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001467 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001468}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001469
Harald Welte93640c62018-02-25 16:59:33 +01001470/***********************************************************************
1471 * Measurement Processing / Reporting
1472 ***********************************************************************/
1473
Harald Welte70767382018-02-21 12:16:40 +01001474template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1475 spare := '0'B,
1476 lpd := 0,
1477 sapi := sapi,
1478 c_r := c_r,
1479 ea := true
1480}
1481
Harald Welted879bd92018-03-12 15:01:23 +01001482template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001483 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001484 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001485 len := 0, /* overwritten */
1486 m := false,
1487 el := 1,
1488 payload := pl
1489}
1490
1491/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1492altstep as_l1_sacch() runs on ConnHdlr {
1493 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001494 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001495 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001496 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 +01001497 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001498 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001499
1500 var L1ctlDataReq data_req := {
1501 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
1502 l2_payload := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O)
1503 }
1504 log("Sending Measurement Report: ", data_req);
1505 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), data_req));
Harald Welte70767382018-02-21 12:16:40 +01001506 repeat;
1507 }
1508}
1509
1510altstep as_l1_dcch() runs on ConnHdlr {
1511 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001512 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001513 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1514 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001515 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1516 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001517 repeat;
1518 }
1519}
1520
1521type record MeasElem {
1522 uint6_t rxlev,
1523 uint3_t rxqual
1524}
1525
1526type record MeasElemFS {
1527 MeasElem full,
1528 MeasElem sub
1529}
1530
1531type record ConnL1Pars {
1532 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001533 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001534 MeasElemFS meas_ul,
1535 int16_t timing_offset_256syms,
1536 uint5_t bs_power_level,
1537 uint5_t ms_power_level,
1538 uint8_t ms_actual_ta
1539}
1540
1541/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1542private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1543 return 63 + (toffs256s/256);
1544}
1545
Harald Welted5684392018-03-10 18:22:04 +01001546private function f_max(integer a, integer b) return integer {
1547 if (a > b) {
1548 return a;
1549 } else {
1550 return b;
1551 }
1552}
1553
1554private function f_min(integer a, integer b) return integer {
1555 if (a < b) {
1556 return a;
1557 } else {
1558 return b;
1559 }
1560}
1561
1562/* compute negative tolerance val-tolerance, ensure >= min */
1563private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1564 val := val - tolerance;
1565 return f_max(val, min);
1566}
1567
1568/* compute positive tolerance val+tolerance, ensure <= max */
1569private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1570 val := val + tolerance;
1571 return f_min(val, max);
1572}
1573
1574/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1575private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1576return template integer {
1577 var template integer ret;
1578 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1579 return ret;
1580}
1581
1582
Harald Welte70767382018-02-21 12:16:40 +01001583/* build a template for matching measurement results against */
1584private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1585 var ConnL1Pars l1p := g_pars.l1_pars;
1586 var template RSL_IE_UplinkMeas ul_meas := {
1587 len := 3,
1588 rfu := '0'B,
1589 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001590 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001591 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001592 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001593 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001594 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1595 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001596 supp_meas_info := omit
1597 };
Harald Welte685d5982018-02-27 20:42:05 +01001598 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001599 ul_meas.len := (3+8);
1600 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001601 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001602 toa256_min := ?,
1603 toa256_max := ?,
1604 toa256_std_dev := ?
1605 }
Harald Welte685d5982018-02-27 20:42:05 +01001606 }
Harald Welte70767382018-02-21 12:16:40 +01001607 var template RSL_IE_BS_Power bs_power := {
1608 reserved := 0,
1609 epc := false,
1610 fpc := false,
1611 power_level := l1p.bs_power_level
1612 };
1613 var template RSL_IE_L1Info l1_info := {
1614 ms_power_lvl := l1p.ms_power_level,
1615 fpc := false,
1616 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001617 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001618 };
1619 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001620 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001621 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1622 ?, t_toffs);
1623}
1624
1625/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001626altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001627 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001628 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001629 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1630 /* increment counter of next to-be-expected meas rep */
1631 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1632 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001633 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001634 repeat;
1635 }
1636 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001637 /* increment counter of next to-be-expected meas rep */
1638 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1639 if (g_first_meas_res) {
1640 g_first_meas_res := false;
1641 repeat;
1642 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001643 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001644 }
Harald Welte70767382018-02-21 12:16:40 +01001645 }
1646 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001647 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001648 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001649 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001650 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001651 }
1652}
1653
Harald Weltee613f962018-04-18 22:38:16 +02001654private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1655 select (rsl_alg_id) {
1656 case (RSL_ALG_ID_A5_0) { return 0; }
1657 case (RSL_ALG_ID_A5_1) { return 1; }
1658 case (RSL_ALG_ID_A5_2) { return 2; }
1659 case (RSL_ALG_ID_A5_3) { return 3; }
1660 case (RSL_ALG_ID_A5_4) { return 4; }
1661 case (RSL_ALG_ID_A5_5) { return 5; }
1662 case (RSL_ALG_ID_A5_6) { return 6; }
1663 case (RSL_ALG_ID_A5_7) { return 7; }
1664 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001665 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1666 /* Make compiler happy by calling mtc.stop here. It is already
1667 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001668 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001669 }
1670 }
1671}
1672
1673private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1674 select (rsl_alg_id) {
1675 case (RSL_ALG_ID_A5_1) { return '000'B; }
1676 case (RSL_ALG_ID_A5_2) { return '001'B; }
1677 case (RSL_ALG_ID_A5_3) { return '010'B; }
1678 case (RSL_ALG_ID_A5_4) { return '011'B; }
1679 case (RSL_ALG_ID_A5_5) { return '100'B; }
1680 case (RSL_ALG_ID_A5_6) { return '101'B; }
1681 case (RSL_ALG_ID_A5_7) { return '110'B; }
1682 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001683 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1684 /* Make compiler happy by calling mtc.stop here. It is already
1685 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001686 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001687 }
1688 }
1689}
1690
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001691/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1692private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1693 var GsmFrameNumber fn;
1694 timer T := 8.0;
1695
1696 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1697 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1698
1699 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1700 /* Send the actual RACH */
1701 fn := f_L1CTL_RACH(L1CTL, ra);
1702
1703 T.start;
1704 alt {
1705 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1706 [] T.timeout {
1707 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1708 }
1709 }
1710 T.stop
1711 return fn;
1712}
Harald Weltee613f962018-04-18 22:38:16 +02001713
Harald Welte70767382018-02-21 12:16:40 +01001714/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001715private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001716 var GsmFrameNumber fn;
1717 var ImmediateAssignment imm_ass;
1718 var integer ra := 23;
1719
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001720 /* Send RACH request and wait for ChanReq */
1721 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001722
1723 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001724 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001725
1726 /* Send IMM.ASS via CCHAN */
1727 var ChannelDescription ch_desc := {
1728 chan_nr := g_pars.chan_nr,
1729 tsc := 7,
1730 h := false,
1731 arfcn := mp_trx0_arfcn,
1732 maio_hsn := omit
1733 };
1734 var MobileAllocation ma := {
1735 len := 0,
1736 ma := ''B
1737 };
1738 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1739 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1740
1741 /* receive IMM.ASS on MS side */
1742 var ImmediateAssignment ia_um;
1743 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1744 /* enable dedicated mode */
1745 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001746 /* enable encryption, if requested */
1747 if (encr_enable) {
1748 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1749 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1750 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001751
1752 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001753}
1754
1755/* establish DChan, verify existance + contents of measurement reports */
1756function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001757 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001758 RSL.clear;
1759
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001760 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001761 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001762 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1763 }
Harald Welte70767382018-02-21 12:16:40 +01001764
1765 f_est_dchan();
1766
1767 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1768 * RSL measurement reports on Abis side */
1769 timer T := 8.0;
1770 T.start;
1771 alt {
1772 [] as_l1_sacch();
1773 [] as_meas_res();
1774 [] as_l1_dcch();
1775 [] L1CTL.receive { repeat; }
1776 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001777 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001778 * of any earlier errors, so if we reach this timeout, we're good */
1779 setverdict(pass);
1780 }
1781 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001782 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001783 }
1784 }
1785 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001786 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001787}
Harald Welte0472ab42018-03-12 15:02:26 +01001788
Harald Welte70767382018-02-21 12:16:40 +01001789testcase TC_meas_res_sign_tchf() runs on test_CT {
1790 var ConnHdlr vc_conn;
1791 var ConnHdlrPars pars;
1792 f_init(testcasename());
1793 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1794 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1795 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1796 vc_conn.done;
1797 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001798 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001799}
1800testcase TC_meas_res_sign_tchh() runs on test_CT {
1801 var ConnHdlr vc_conn;
1802 var ConnHdlrPars pars;
1803 f_init(testcasename());
1804 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1805 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1806 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1807 vc_conn.done;
1808 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001809 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001810}
1811testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1812 var ConnHdlr vc_conn;
1813 var ConnHdlrPars pars;
1814 f_init(testcasename());
1815 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1816 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1817 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1818 vc_conn.done;
1819 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001821}
1822testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1823 var ConnHdlr vc_conn;
1824 var ConnHdlrPars pars;
1825 f_init(testcasename());
1826 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1827 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1828 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1829 vc_conn.done;
1830 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001831 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001832}
Harald Welte685d5982018-02-27 20:42:05 +01001833testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1834 var ConnHdlr vc_conn;
1835 var ConnHdlrPars pars;
1836 f_init(testcasename());
1837 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1838 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1839 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1840 pars.l1_pars.toa256_enabled := true;
1841 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1842 vc_conn.done;
1843 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001844 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001845}
1846
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001847/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1848 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1849function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1850 var L1ctlDlMessage l1_dl;
1851 var RSL_IE_MS_Power ms_power;
1852 var RSL_Message rsl;
1853 var uint5_t power_level := 0;
1854
1855 f_l1_tune(L1CTL);
1856 RSL.clear;
1857
1858 f_est_dchan();
1859
1860 ms_power.reserved := 0;
1861 ms_power.fpc_epc := false;
1862
1863 /* Send the first power control command. This will disable any BTS/TRX
1864 * internal power control and switch the MS (which is not in scope of
1865 * this test) to a constant power level. We start with a power level
1866 * of 0 */
1867 ms_power.power_level := power_level;
1868 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1869 RSL.send(rsl);
1870
1871 alt {
1872
1873 /* Pick all SACCH blocks for checking */
1874 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1875
1876 /* The first byte of the L1 header contains the power level.
1877 * The reserved bits and the fpc bit is set to 0, so we may
1878 * compare directly. */
1879 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1880 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1881 }
1882
1883 /* Signal a new power level via RSL for the next turn. */
1884 if (power_level < 31) {
1885 power_level := power_level + 1;
1886 ms_power.power_level := power_level;
1887 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1888 RSL.send(rsl);
1889 repeat;
1890 }
1891
1892 }
1893
1894 /* Ignore all other blocks */
1895 [] L1CTL.receive { repeat; }
1896
1897 }
1898
1899 f_rsl_chan_deact();
1900 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1901
1902 setverdict(pass);
1903}
1904
1905testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
1906 var ConnHdlr vc_conn;
1907 var ConnHdlrPars pars;
1908 f_init(testcasename());
1909
1910 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1911 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1912 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
1913 vc_conn.done;
1914 }
1915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1916}
Harald Welte70767382018-02-21 12:16:40 +01001917
Eric Wild6833cc92019-05-23 19:34:44 +02001918/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
1919TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
1920function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
1921 var L1ctlDlMessage l1_dl;
1922 var uint5_t ta_to_test := 16;
1923
1924
1925 f_l1_tune(L1CTL);
1926 RSL.clear;
1927
1928 /* tell fake_trx to use a given timing offset for all bursts */
1929 f_trx_fake_toffs256(ta_to_test*256);
1930
1931 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
1932
1933
1934 alt {
1935
1936 /* Pick all SACCH blocks for checking */
1937 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1938
1939 /* The second byte of the L1 header contains the TA. */
1940 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
1941 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
1942 }
1943
1944 }
1945
1946 /* Ignore all other blocks */
1947 [] L1CTL.receive { repeat; }
1948
1949 }
1950
1951 f_rsl_chan_deact();
1952 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1953
1954 setverdict(pass);
1955}
1956
1957testcase TC_rsl_chan_initial_ta() runs on test_CT {
1958 var ConnHdlr vc_conn;
1959 var ConnHdlrPars pars;
1960 f_init(testcasename());
1961 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1962 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars);
1963 vc_conn.done;
1964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1965}
1966
Harald Welte0472ab42018-03-12 15:02:26 +01001967/* 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 +01001968private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001969 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001970 RSL.clear;
1971
1972 f_est_dchan();
1973 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001974 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001975
1976 timer T := 40.0;
1977 T.start;
1978 alt {
1979 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
1980 setverdict(pass)
1981 }
1982 [] RSL.receive { repeat };
1983 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01001985 }
1986 }
1987 f_rsl_chan_deact();
1988}
1989testcase TC_conn_fail_crit() runs on test_CT {
1990 var ConnHdlr vc_conn;
1991 var ConnHdlrPars pars;
1992 f_init(testcasename());
1993 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
1994 pars.t_guard := 60.0;
1995 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
1996 vc_conn.done;
1997}
1998
Harald Welte93640c62018-02-25 16:59:33 +01001999/***********************************************************************
2000 * Paging
2001 ***********************************************************************/
2002
Harald Welte68e495b2018-02-25 00:05:57 +01002003function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2004 if (tmsi == 'FFFFFFFF'O) {
2005 return true;
2006 } else {
2007 return false;
2008 }
2009}
Harald Welte70767382018-02-21 12:16:40 +01002010
Philipp Maier82cb0b12018-08-31 14:41:39 +02002011type record allowedFn { integer frame_nr }
2012template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2013template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2014template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2015template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2016template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2017template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2018template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2019template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2020function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2021{
2022 var integer frame_nr_51;
2023 frame_nr_51 := frame_nr mod 51
2024
2025 var allowedFn fn_check;
2026 fn_check.frame_nr := frame_nr_51;
2027
2028 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002030 return;
2031 }
2032
2033 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2034 return;
2035 }
2036 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2037 return;
2038 }
2039 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2040 return;
2041 }
2042 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2043 return;
2044 }
2045 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2046 return;
2047 }
2048 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2049 return;
2050 }
2051 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2052 return;
2053 }
2054 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2055 return;
2056 }
2057
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002058 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002059 return;
2060}
2061
2062altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids, PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01002063runs on test_CT {
2064 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002065 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002066 repeat;
2067 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002068 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002069 var octetstring without_plen :=
2070 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2071 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002072
2073 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2074
Harald Welte68e495b2018-02-25 00:05:57 +01002075 if (match(rr, tr_PAGING_REQ1)) {
2076 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2077 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2078 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2079 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2080 }
2081 } else if (match(rr, tr_PAGING_REQ2)) {
2082 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2083 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2084 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2085 }
2086 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2087 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2088 }
2089 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2090 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2091 }
2092 } else if (match(rr, tr_PAGING_REQ3)) {
2093 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2094 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2095 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2096 }
2097 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2098 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2099 }
2100 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2101 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2102 }
2103 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2104 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2105 }
2106 }
2107 repeat;
2108 }
2109}
2110
2111type record PagingTestCfg {
2112 boolean combined_ccch,
2113 integer bs_ag_blks_res,
2114 float load_factor,
2115 boolean exp_load_ind,
2116 boolean exp_overload,
2117 boolean use_tmsi
2118}
2119
2120type record PagingTestState {
2121 integer num_paging_sent,
2122 integer num_paging_rcv_msgs,
2123 integer num_paging_rcv_ids,
2124 integer num_overload
2125}
2126
2127/* receive + ignore RSL RF RES IND */
2128altstep as_rsl_res_ind() runs on test_CT {
2129 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2130 repeat;
2131 }
2132}
2133
2134/* Helper function for paging related testing */
2135private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
2136 f_init(testcasename());
2137 f_init_l1ctl();
2138 f_l1_tune(L1CTL);
2139
2140 var PagingTestState st := {
2141 num_paging_sent := 0,
2142 num_paging_rcv_msgs := 0,
2143 num_paging_rcv_ids := 0,
2144 num_overload := 0
2145 };
2146
2147 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2148 var float max_pch_imsi_per_sec;
2149 if (cfg.use_tmsi) {
2150 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2151 } else {
2152 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2153 }
2154 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2155 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002156 var float time_total := 20.0;
2157 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2158 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002159
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002160 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2161 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002162
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002163 timer T_itv := 0.0;
2164 T_itv.start;
2165 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002166 alt {
2167 /* check for presence of CCCH LOAD IND (paging load) */
2168 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2169 st.num_overload := st.num_overload + 1;
2170 repeat;
2171 }
2172 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002174 }
2175 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2176 log("Rx LOAD_IND");
2177 /* FIXME: analyze/verify interval + contents */
2178 repeat;
2179 }
2180 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002181 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002182 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002183 [] T_itv.timeout {
2184 /* Send paging cmds based on elapsed time */
2185 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2186 while (st.num_paging_sent < new_sent) {
2187 /* build mobile Identity */
2188 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2189 if (cfg.use_tmsi) {
2190 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2191 } else {
2192 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2193 }
2194 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2195 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2196
2197 /* Send RSL PAGING COMMAND */
2198 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2199
2200 st.num_paging_sent := st.num_paging_sent + 1;
2201 }
2202 if (st.num_paging_sent < pkt_total) {
2203 /* Wait for interval to next PAGING COMMAND */
2204 var float time_now := T_total.read;
2205 var float next_sched := int2float(st.num_paging_sent)*interval;
2206 if (next_sched > time_now) {
2207 T_itv.start(next_sched - time_now);
2208 } else {
2209 T_itv.start(0.0);
2210 }
2211 } else {
2212 /* We are done, no need to keep counting */
2213 T_total.stop;
2214 }
2215 }
2216 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002217 [] as_rsl_res_ind();
2218 }
2219 }
2220
2221 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2222 timer T_wait := 18.0;
2223 T_wait.start;
2224 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002225 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002226 [] L1CTL.receive { repeat; }
2227 /* 65535 == empty paging queue, we can terminate*/
2228 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2229 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2230 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002231 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002232 }
2233 [] as_rsl_res_ind();
2234 }
2235
2236 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2237 " rcvd_ids=", st.num_paging_rcv_ids);
2238 return st;
2239}
2240
2241/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2242 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2243 * - that CCCH LOAD IND (PCH) are being generated
2244 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2245testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002246 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002247 var PagingTestCfg cfg := {
2248 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002249 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002250 load_factor := 0.8,
2251 exp_load_ind := true,
2252 exp_overload := false,
2253 use_tmsi := false
2254 };
2255 var PagingTestState st := f_TC_paging(cfg);
2256 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002257 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2258 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002259 } else {
2260 setverdict(pass);
2261 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002262 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002263}
2264
2265/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2266 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2267 * - that CCCH LOAD IND (PCH) are being generated
2268 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2269testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002270 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002271 var PagingTestCfg cfg := {
2272 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002273 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002274 load_factor := 0.8,
2275 exp_load_ind := true,
2276 exp_overload := false,
2277 use_tmsi := true
2278 };
2279 var PagingTestState st := f_TC_paging(cfg);
2280 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2282 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002283 } else {
2284 setverdict(pass);
2285 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002287}
2288
2289/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2290 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2291 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2292 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2293testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002294 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002295 var PagingTestCfg cfg := {
2296 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002297 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002298 load_factor := 2.0,
2299 exp_load_ind := true,
2300 exp_overload := true,
2301 use_tmsi := false
2302 };
2303 var PagingTestState st := f_TC_paging(cfg);
2304 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2305 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002306 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002307 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002308 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 +01002309 } else {
2310 setverdict(pass);
2311 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002312 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002313}
2314
2315/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2316 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2317 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2318 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2319testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002320 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002321 var PagingTestCfg cfg := {
2322 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002323 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002324 load_factor := 2.0,
2325 exp_load_ind := true,
2326 exp_overload := true,
2327 use_tmsi := true
2328 };
2329 var PagingTestState st := f_TC_paging(cfg);
2330 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2331 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002332 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002333 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002334 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 +01002335 } else {
2336 setverdict(pass);
2337 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002338 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002339}
2340
2341
Harald Welte93640c62018-02-25 16:59:33 +01002342/***********************************************************************
2343 * Immediate Assignment / AGCH
2344 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002345const MobileAllocation c_MA_null := {
2346 len := 0,
2347 ma := ''B
2348}
Harald Welte93640c62018-02-25 16:59:33 +01002349
Harald Weltee8d750e2018-06-10 21:41:35 +02002350template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2351 uint12_t arfcn := 871) := {
2352 chan_nr := chan_nr,
2353 tsc := tsc,
2354 h := false,
2355 arfcn := arfcn,
2356 maio_hsn := omit
2357}
2358
2359private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2360 return int2str(num_tx) & " sent, "
2361 & int2str(num_rx) & " received, "
2362 & int2str(num_del) & " deleted";
2363}
2364
2365private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2366 var L1ctlDlMessage l1_dl;
2367 timer T := 10.0;
2368 var integer num_tx := 0;
2369 var integer num_rx := 0;
2370 var integer num_del := 0;
2371 var charstring res_str;
2372 var float rx_ratio;
2373
Harald Welte68e495b2018-02-25 00:05:57 +01002374 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02002375 f_init_l1ctl();
2376 f_l1_tune(L1CTL);
2377
2378 for (var integer i := 0; i < num_total; i := i+1) {
2379 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2380 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2381 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002382 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002383 num_tx := num_tx+1;
2384 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002385 }
2386 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002387 T.start;
2388 alt {
2389 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2390 num_del := num_del+1;
2391 repeat;
2392 }
2393 [] RSL_CCHAN.receive {
2394 repeat;
2395 }
2396 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2397 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2398 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2399 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2400 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002401 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002402 } else {
2403 num_rx := num_rx+1;
2404 }
2405 repeat;
2406 }
2407 [] L1CTL.receive { repeat; }
2408 [] T.timeout { }
2409 }
2410 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2411 log("AGCH test: " & res_str);
2412 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002414 }
2415 rx_ratio := int2float(num_rx) / int2float(num_tx);
2416 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002417 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 +02002418 } else {
2419 setverdict(pass);
2420 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002422}
2423
Harald Weltee8d750e2018-06-10 21:41:35 +02002424/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2425testcase TC_imm_ass_1000_20ms() runs on test_CT {
2426 f_TC_imm_ass(1000, 0.02, 0.25);
2427}
2428
2429/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2430testcase TC_imm_ass_200_0ms() runs on test_CT {
2431 f_TC_imm_ass(200, 0.0, 0.05);
2432}
2433
2434/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2435testcase TC_imm_ass_200_76ms() runs on test_CT {
2436 f_TC_imm_ass(150, 0.076, 1.00);
2437}
2438
2439
2440
Harald Welte48494ca2018-02-25 16:59:50 +01002441/***********************************************************************
2442 * BCCH
2443 ***********************************************************************/
2444
2445/* tuple of Frame Number + decoded SI */
2446type record SystemInformationFn {
2447 GsmFrameNumber frame_number,
2448 SystemInformation si
2449}
2450
2451/* an arbitrary-length vector of decoded SI + gsmtap header */
2452type record of SystemInformationFn SystemInformationVector;
2453
2454/* an array of SI-vectors indexed by TC value */
2455type SystemInformationVector SystemInformationVectorPerTc[8];
2456
2457/* determine if a given SI vector contains given SI type at least once */
2458function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2459 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2460 var integer fn_mod51 := arr[i].frame_number mod 51;
2461 if (not bcch_ext and fn_mod51 == 2 or
2462 bcch_ext and fn_mod51 == 6) {
2463 if (arr[i].si.header.message_type == key) {
2464 return true;
2465 }
2466 }
2467 }
2468 return false;
2469}
2470
2471/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2472function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2473 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002474 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002475 }
2476}
2477
2478/* check if a given SI vector contains given SI type at least once on any TC */
2479function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2480 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2481 if (f_si_vecslot_contains(arr[tc], key) or
2482 f_si_vecslot_contains(arr[tc], key, true)) {
2483 return true;
2484 }
2485 }
2486 return false;
2487}
2488
2489/* determine if a given SI vector contains given SI type at least N of M times */
2490function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2491 var integer count := 0;
2492 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002494 }
2495 for (var integer i:= 0; i < m; i := i + 1) {
2496 var integer fn_mod51 := arr[i].frame_number mod 51;
2497 if (not bcch_ext and fn_mod51 == 2 or
2498 bcch_ext and fn_mod51 == 6) {
2499 if (arr[i].si.header.message_type == key) {
2500 count := count + 1;
2501 }
2502 }
2503 }
2504 if (count >= n) {
2505 return true;
2506 } else {
2507 return false;
2508 }
2509}
2510
2511/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2512function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2513 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002514 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002515 }
2516}
2517
2518/* determine if a given SI vector contains given SI type at least once */
2519function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2520 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2521 var integer fn_mod51 := arr[i].frame_number mod 51;
2522 if (not bcch_ext and fn_mod51 == 2 or
2523 bcch_ext and fn_mod51 == 6) {
2524 if (arr[i].si.header.message_type != key) {
2525 return false;
2526 }
2527 }
2528 }
2529 return true;
2530}
2531
2532/* ensure a given TC slot of the SI vector contains only given SI type */
2533function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2534 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002535 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002536 }
2537}
2538
2539/* SI configuration of cell, against which we validate actual SI messages */
2540type set SystemInformationConfig {
2541 boolean bcch_extended,
2542 boolean si1_present,
2543 boolean si2bis_present,
2544 boolean si2ter_present,
2545 boolean si2quater_present,
2546 boolean si7_present,
2547 boolean si8_present,
2548 boolean si9_present,
2549 boolean si13_present,
2550 boolean si13alt_present,
2551 boolean si15_present,
2552 boolean si16_present,
2553 boolean si17_present,
2554 boolean si2n_present,
2555 boolean si21_present,
2556 boolean si22_present
2557}
2558
2559/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2560function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2561 var integer i;
2562 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2563 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002565 }
2566 }
2567 if (cfg.si1_present) {
2568 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2569 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2570 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2571 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2572 /* make sure *ALL* contain SI1 */
2573 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2574 }
2575 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2576 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2577 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2578 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2579 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2580 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2581
2582 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2583 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2584 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2585 * consecutive occurrences of TC = 4. */
2586 if (cfg.si2bis_present and not cfg.si2ter_present) {
2587 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2588 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2589 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2590 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2591 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2592 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2593 }
2594
2595 if (cfg.si7_present or cfg.si8_present) {
2596 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2597 * if System Information type 4 does not contain all information needed for cell
2598 * selection and reselection. */
2599 if (not cfg.bcch_extended) {
2600 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2601 }
2602 if (cfg.si7_present) {
2603 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2604 }
2605 if (cfg.si8_present) {
2606 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2607 }
2608 }
2609
2610 if (cfg.si2quater_present) {
2611 /* iii) System information type 2 quater is sent if needed, as determined by the system
2612 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2613 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2614 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2615 * within any of 4 consecutive occurrences of TC = 5. */
2616 if (not (cfg.bcch_extended)) {
2617 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2618 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2619 } else {
2620 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2621 }
2622 } else {
2623 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2624 }
2625 }
2626 if (cfg.si9_present) {
2627 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2628 * in system information type 3 as defined in 3GPP TS 44.018. */
2629 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2630 }
2631 if (cfg.si13_present) {
2632 /* vii) System Information type 13 is only related to the GPRS service. System Information
2633 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2634 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2635 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2636 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2637 * within any of 4 consecutive occurrences of TC=4. */
2638 if (not cfg.bcch_extended) {
2639 log("not-bccch-extended");
2640 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2641 } else {
2642 log("bccch-extended");
2643 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2644 }
2645 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002646 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002647 }
2648 }
2649 if (cfg.si16_present or cfg.si17_present) {
2650 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2651 * should not be sent in a cell where network sharing is used (see rule xv). */
2652 if (cfg.si22_present) {
2653 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2654 }
2655 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002656 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002657 }
2658 if (not cfg.bcch_extended) {
2659 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2660 }
2661 if (cfg.si16_present) {
2662 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2663 }
2664 if (cfg.si17_present) {
2665 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2666 }
2667 }
2668
2669 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2670 * broadcast information. The frequency with which they are sent is determined by the
2671 * system operator. System Information type 9 identifies the scheduling of System
2672 * Information type 18 and 20 messages. */
2673
2674 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2675 * Information Type 19 is present, then its scheduling shall be indicated in System
2676 * Information Type 9. */
2677
2678 if (cfg.si15_present) {
2679 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2680 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2681 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2682 * 4 consecutive occurrences of TC = 1. */
2683 if (not cfg.bcch_extended) {
2684 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2685 } else {
2686 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2687 }
2688 }
2689 if (cfg.si13alt_present) {
2690 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2691 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2692 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2693 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2694 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2695 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2696 * of TC = 4. */
2697 if (cfg.si13_present) {
2698 testcase.stop("Error: Cannot have SI13alt and SI13");
2699 }
2700 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002701 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002702 }
2703 if (not cfg.bcch_extended) {
2704 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2705 } else {
2706 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2707 }
2708 }
2709 if (cfg.si2n_present) {
2710 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2711 * as determined by the system operator. In the case that the message is sent on the
2712 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2713 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2714 * consecutive occurrences of TC = 4. */
2715 if (not cfg.bcch_extended) {
2716 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2717 } else {
2718 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2719 }
2720 }
2721 if (cfg.si21_present) {
2722 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2723 * determined by the system operator. If Extended Access Barring is in use in the cell
2724 * then this message is sent at least once within any of 4 consecutive occurrences of
2725 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2726 * cell then this message shall only be sent on BCCH Ext. */
2727 if (not cfg.bcch_extended) {
2728 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2729 } else {
2730 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2731 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002733 }
2734 }
2735 }
2736 if (cfg.si22_present) {
2737 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2738 * should not be sent in a cell where SoLSA is used (see rule viii). System
2739 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2740 * =2 and TC=6. */
2741 if (cfg.si16_present or cfg.si17_present) {
2742 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2743 }
2744 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2745 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002746 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002747 }
2748 if (not cfg.bcch_extended) {
2749 testcase.stop("Error: SI22 requires BCCH Extd!");
2750 } else {
2751 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2752 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2753 }
2754 }
2755}
2756
2757/* sample Systme Information for specified duration via L1CTL */
2758function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2759 timer T := duration;
2760 var SystemInformationVectorPerTc si_per_tc;
2761 var L1ctlDlMessage l1_dl;
2762
2763 /* initialize all per-TC vectors empty */
2764 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2765 si_per_tc[i] := {};
2766 }
2767
2768 /* flush all previous L1 queued msgs */
2769 pt.clear;
2770
2771 T.start;
2772 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002773 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002774 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2775 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2776 log("Ignoring non-RR SI ", l1_dl);
2777 repeat;
2778 }
2779 var SystemInformationFn sig := {
2780 frame_number := l1_dl.dl_info.frame_nr,
2781 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2782 }
2783 var integer tc := f_gsm_compute_tc(sig.frame_number);
2784 log("SI received at TC=", tc, ": ", sig.si);
2785 /* append to the per-TC bucket */
2786 si_per_tc[tc] := si_per_tc[tc] & { sig };
2787 repeat;
2788 }
2789 [] pt.receive { repeat; }
2790 [] T.timeout { }
2791 }
2792
2793 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2794 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2795 }
2796 log("si_per_tc=", si_per_tc);
2797 return si_per_tc;
2798}
2799
2800/* helper function: Set given SI via RSL + validate scheduling.
2801 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2802function f_TC_si_sched() runs on test_CT {
2803 var SystemInformationVectorPerTc si_per_tc;
2804 f_init_l1ctl();
2805 f_l1_tune(L1CTL);
2806
2807 /* Sample + Validate Scheduling */
2808 si_per_tc := f_l1_sample_si(L1CTL);
2809 f_validate_si_scheduling(si_cfg, si_per_tc);
2810
2811 setverdict(pass);
2812}
2813
2814testcase TC_si_sched_default() runs on test_CT {
2815 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002816 /* 2+3+4 are mandatory and set in f_init() */
2817 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002818 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002819}
2820
2821testcase TC_si_sched_1() runs on test_CT {
2822 f_init();
2823 si_cfg.si1_present := true;
2824 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002825 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002826 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002827}
2828
2829testcase TC_si_sched_2bis() runs on test_CT {
2830 f_init();
2831 si_cfg.si2bis_present := true;
2832 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2833 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002834 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002835}
2836
2837testcase TC_si_sched_2ter() runs on test_CT {
2838 f_init();
2839 si_cfg.si2ter_present := true;
2840 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2841 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002842 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002843}
2844
2845testcase TC_si_sched_2ter_2bis() runs on test_CT {
2846 f_init();
2847 si_cfg.si2bis_present := true;
2848 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2849 si_cfg.si2ter_present := true;
2850 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2851 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002852 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002853}
2854
2855testcase TC_si_sched_2quater() runs on test_CT {
2856 f_init();
2857 si_cfg.si2quater_present := true;
2858 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2859 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002860 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002861}
2862
2863testcase TC_si_sched_13() runs on test_CT {
2864 f_init();
2865 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002866 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002867 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002868 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002869}
2870
2871testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2872 f_init();
2873 si_cfg.si2bis_present := true;
2874 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2875 si_cfg.si2ter_present := true;
2876 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2877 si_cfg.si2quater_present := true;
2878 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2879 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002880 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002881 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002883}
2884
2885
Harald Welte68e495b2018-02-25 00:05:57 +01002886testcase TC_bcch_info() runs on test_CT {
2887 f_init(testcasename());
2888 /* FIXME: enable / disable individual BCCH info */
2889 //ts_RSL_BCCH_INFO(si_type, info);
2890 /* expect no ERROR REPORT after either of them *
2891 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002892 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002893}
2894
Harald Welte93640c62018-02-25 16:59:33 +01002895/***********************************************************************
2896 * Low-Level Protocol Errors / ERROR REPORT
2897 ***********************************************************************/
2898
Harald Welte01d982c2018-02-25 01:31:40 +01002899private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2900 timer T := 5.0;
2901 T.start;
2902 alt {
2903 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2904 setverdict(pass);
2905 }
2906 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002907 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002908 }
2909 [] RSL_CCHAN.receive {
2910 repeat;
2911 }
2912 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002914 }
2915 }
2916}
2917
2918/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2919testcase TC_rsl_protocol_error() runs on test_CT {
2920 f_init(testcasename());
2921 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2922 rsl.ies := omit;
2923 RSL_CCHAN.send(ts_RSL_UD(rsl));
2924
2925 f_exp_err_rep(RSL_ERR_PROTO);
2926}
2927
2928/* Provoke a mandatory IE error and match on ERROR REPORT */
2929testcase TC_rsl_mand_ie_error() runs on test_CT {
2930 f_init(testcasename());
2931
2932 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2933 rsl.ies := { rsl.ies[0] };
2934 RSL_CCHAN.send(ts_RSL_UD(rsl));
2935
2936 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2937}
2938
2939/* Provoke an IE content error and match on ERROR REPORT */
2940testcase TC_rsl_ie_content_error() runs on test_CT {
2941 f_init(testcasename());
2942 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2943 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2944 RSL_CCHAN.send(ts_RSL_UD(rsl));
2945
2946 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2947}
2948
Harald Welteee25aae2019-05-19 14:32:37 +02002949/* attempt to activate channel with wrong RSL Message Discriminator IE */
2950function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
2951 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2952 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
2953 RSL.send(rsl);
2954 f_rslem_unregister(0, g_chan_nr);
2955}
2956testcase TC_err_rep_wrong_mdisc() runs on test_CT {
2957 var ConnHdlr vc_conn;
2958 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
2959
2960 f_init(testcasename());
2961
2962 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
2963 vc_conn.done;
2964 f_exp_err_rep(RSL_ERR_MSG_DISCR);
2965
2966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2967}
2968
2969/* Send messages with wrong message type */
2970function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
2971 var template (value) RSL_Message rsl_tx;
2972 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2973 rsl_tx.msg_type := RSL_MT_NOT_CMD;
2974 RSL.send(rsl_tx);
2975 f_rslem_unregister(0, g_chan_nr);
2976}
2977function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
2978 var template (value) RSL_Message rsl_tx;
2979 /* we first have to activate the dedicated channel */
2980 f_rsl_chan_act(g_pars.chan_mode);
2981 /* ... to then send an invalid RLL message */
2982 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
2983 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
2984 RSL.send(rsl_tx);
2985 f_rslem_unregister(0, g_chan_nr);
2986}
2987testcase TC_err_rep_wrong_msg_type() runs on test_CT {
2988 var ConnHdlr vc_conn;
2989 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
2990 var template (value) RSL_Message rsl_tx;
2991
2992 f_init(testcasename());
2993
2994 /* Common Channel with wrong message type */
2995 RSL_CCHAN.clear;
2996 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2997 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
2998 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
2999 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3000
3001 /* TRX Management */
3002 RSL_CCHAN.clear;
3003 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3004 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3005 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3006 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3007
3008 /* Dedicated Channel */
3009 RSL_CCHAN.clear;
3010 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3011 vc_conn.done;
3012 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3013
3014 /* RLL */
3015 RSL_CCHAN.clear;
3016 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3017 vc_conn.done;
3018 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3019}
3020
3021/* Send messages in wrong sequence (RLL to an inactive lchan) */
3022function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3023 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3024 f_rslem_unregister(0, g_chan_nr);
3025}
3026testcase TC_err_rep_wrong_sequence() runs on test_CT {
3027 var ConnHdlr vc_conn;
3028 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3029
3030 f_init(testcasename());
3031
3032 RSL_CCHAN.clear;
3033 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3034 vc_conn.done;
3035 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3036}
3037
Harald Welte93640c62018-02-25 16:59:33 +01003038/***********************************************************************
3039 * IPA CRCX/MDCX/DLCS media stream handling
3040 ***********************************************************************/
3041
Harald Weltea871a382018-02-25 02:03:14 +01003042/* Send IPA DLCX to inactive lchan */
3043function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003044 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3045 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003046}
3047testcase TC_ipa_dlcx_not_active() runs on test_CT {
3048 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3049 f_init(testcasename());
3050 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3051 vc_conn.done;
3052}
Harald Welte68e495b2018-02-25 00:05:57 +01003053
Harald Weltea3f1df92018-02-25 12:49:55 +01003054/* Send IPA CRCX twice to inactive lchan */
3055function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3056 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3057 "IPA CRCX ACK");
3058 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3059 "IPA CRCX NACK");
3060}
3061testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3062 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3063 f_init(testcasename());
3064 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3065 vc_conn.done;
3066}
3067
3068/* Regular sequence of CRCX/MDCX/DLCX */
3069function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3070 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3071 "IPA CRCX ACK");
3072 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3073 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3074 var uint7_t rtp_pt2 := f_rnd_int(127);
3075 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3076 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3077 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3078 "IPA MDCX ACK");
3079 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3080 "IPA DLCX ACK");
3081}
3082testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3083 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3084 f_init(testcasename());
3085 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3086 vc_conn.done;
3087}
3088
Harald Welte3ae11da2018-02-25 13:36:06 +01003089/* Sequence of CRCX, 2x MDCX, DLCX */
3090function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3091 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3092 "IPA CRCX ACK");
3093 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3094 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3095 var uint7_t rtp_pt2 := f_rnd_int(127);
3096 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3097 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3098 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3099 "IPA MDCX ACK");
3100 /* Second MDCX */
3101 remote_ip := f_rnd_int(c_UINT32_MAX);
3102 remote_port := f_rnd_int(c_UINT16_MAX);
3103 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3104 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3105 "IPA MDCX ACK");
3106 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3107 "IPA DLCX ACK");
3108}
3109testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3110 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3111 f_init(testcasename());
3112 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3113 vc_conn.done;
3114}
3115
Harald Welte9912eb52018-02-25 13:30:15 +01003116/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3117function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3118 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3119 "IPA CRCX NACK");
3120}
3121testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3122 var ConnHdlrPars pars;
3123 var ConnHdlr vc_conn;
3124 f_init(testcasename());
3125
3126 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3127 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3128 vc_conn.done;
3129
3130 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3131 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3132 vc_conn.done;
3133}
3134
Harald Weltea3f1df92018-02-25 12:49:55 +01003135
Harald Welte883340c2018-02-28 18:59:29 +01003136/***********************************************************************
3137 * PCU Socket related tests
3138 ***********************************************************************/
3139
Harald Welte07bd2d22019-05-25 11:03:30 +02003140/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003141friend 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 +01003142runs on test_CT {
3143 timer T := 3.0;
3144
3145 /* we don't expect any RTS.req before PDCH are active */
3146 T.start;
3147 alt {
3148 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003149 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003150 }
3151 [] PCU.receive { repeat; }
3152 [] T.timeout { }
3153 }
3154
3155 /* Send PDCH activate request for known PDCH timeslot */
3156 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3157
3158 /* we now expect RTS.req for this timeslot (only) */
3159 T.start;
3160 alt {
3161 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3162 setverdict(pass);
3163 }
3164 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3165 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003166 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003167 }
3168 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003170 }
3171 [] PCU.receive { repeat; }
3172 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003173 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003174 }
3175 [not exp_success] T.timeout {
3176 setverdict(pass);
3177 }
3178 }
3179}
3180
Harald Welte07bd2d22019-05-25 11:03:30 +02003181/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003182friend 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 +01003183runs on test_CT {
3184 timer T := 3.0;
3185
3186 /* Send PDCH activate request for known PDCH timeslot */
3187 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3188
3189 PCU.clear;
3190 /* we now expect no RTS.req for this timeslot */
3191 T.start;
3192 alt {
3193 [] 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 +02003194 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003195 }
3196 [] PCU.receive { repeat; }
3197 [] T.timeout {
3198 setverdict(pass);
3199 }
3200 }
3201}
3202
Harald Weltead033dc2019-05-25 17:28:16 +02003203friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003204 f_init();
3205 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3206}
3207
Harald Welte883340c2018-02-28 18:59:29 +01003208/* PDCH activation via PCU socket; check for presence of RTS.req */
3209testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003210 f_init_pcu_test();
3211
Harald Welte883340c2018-02-28 18:59:29 +01003212 f_TC_pcu_act_req(0, 0, 7, true);
3213}
3214
3215/* PDCH activation via PCU socket on non-PDCU timeslot */
3216testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003217 f_init_pcu_test();
3218
Harald Welte883340c2018-02-28 18:59:29 +01003219 f_TC_pcu_act_req(0, 0, 1, false);
3220}
3221
3222/* PDCH activation via PCU socket on wrong BTS */
3223testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003224 f_init_pcu_test();
3225
Harald Welte883340c2018-02-28 18:59:29 +01003226 f_TC_pcu_act_req(23, 0, 7, false);
3227}
3228
3229/* PDCH activation via PCU socket on wrong TRX */
3230testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003231 f_init_pcu_test();
3232
Harald Welte883340c2018-02-28 18:59:29 +01003233 f_TC_pcu_act_req(0, 23, 7, false);
3234}
3235
3236/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3237testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003238 f_init_pcu_test();
3239
Harald Welte883340c2018-02-28 18:59:29 +01003240 /* Activate PDCH */
3241 f_TC_pcu_act_req(0, 0, 7, true);
3242 f_sleep(1.0);
3243 /* and De-Activate again */
3244 f_TC_pcu_deact_req(0, 0, 7);
3245}
3246
3247/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3248testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003249 f_init_pcu_test();
3250
Harald Welte883340c2018-02-28 18:59:29 +01003251 f_TC_pcu_deact_req(0, 0, 1);
3252}
3253
3254/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3255testcase TC_pcu_ver_si13() runs on test_CT {
3256 const octetstring si13 := '00010203040506070909'O;
3257 var PCUIF_send_data sd;
3258 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003259 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003260
3261 /* Set SI13 via RSL */
3262 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003263
Harald Welte883340c2018-02-28 18:59:29 +01003264 T.start;
3265 alt {
3266 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3267 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3268 setverdict(pass);
3269 } else {
3270 repeat;
3271 }
3272 }
3273 [] PCU.receive { repeat; }
3274 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003275 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003276 }
3277 }
3278}
3279
3280private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3281
3282/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003283friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003284 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3285runs on test_CT
3286{
3287 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3288 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3289}
3290
3291/* 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 +02003292friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3293 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003294runs on test_CT
3295{
3296 var PCUIF_send_data sd;
3297
3298 timer T := 3.0;
3299 T.start;
3300 alt {
3301 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3302 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3303 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3304 sd.data.u.rts_req.fn, sapi, data);
3305 }
3306 [] PCU.receive { repeat; }
3307 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003309 }
3310 }
3311}
3312
3313/* Send DATA.req on invalid BTS */
3314testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003315 f_init_pcu_test();
3316
Harald Welte883340c2018-02-28 18:59:29 +01003317 f_TC_pcu_act_req(0, 0, 7, true);
3318 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
3319 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
3320 f_sleep(10.0);
3321}
3322
3323/* Send DATA.req on invalid TRX */
3324testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003325 f_init_pcu_test();
3326
Harald Welte883340c2018-02-28 18:59:29 +01003327 f_TC_pcu_act_req(0, 0, 7, true);
3328 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
3329 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
3330 f_sleep(10.0);
3331}
3332
3333/* Send DATA.req on invalid timeslot */
3334testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003335 f_init_pcu_test();
3336
Harald Welte883340c2018-02-28 18:59:29 +01003337 f_TC_pcu_act_req(0, 0, 7, true);
3338 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
3339 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
3340 f_sleep(10.0);
3341}
3342
3343/* Send DATA.req on timeslot that hasn't been activated */
3344testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003345 f_init_pcu_test();
3346
Harald Welte883340c2018-02-28 18:59:29 +01003347 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
3348 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
3349 f_sleep(2.0);
3350}
3351
Harald Weltead033dc2019-05-25 17:28:16 +02003352private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3353 PCUIF_Sapi sapi, octetstring data) runs on test_CT
3354{
3355 timer T := 5.0;
3356
3357 PCU.clear;
3358 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3359
3360 T.start;
3361 alt {
3362 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
3363 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3364 setverdict(pass);
3365 }
3366 [] L1CTL.receive {
3367 repeat;
3368 }
3369 [] T.timeout {
3370 setverdict(fail, "Timeout waiting for ", data);
3371 }
3372 }
3373}
3374
3375private function f_disable_dynamic_ts() runs on test_CT
3376{
3377 f_init_vty_bsc();
3378 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3379 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3380 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3381 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003382 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003383}
3384
3385private function f_virtphy_common() runs on test_CT {
3386 f_disable_dynamic_ts();
3387 f_init_l1ctl();
3388 f_l1_tune(L1CTL);
3389}
3390
3391testcase TC_pcu_data_req_pdtch() runs on test_CT {
3392 var TfiUsfArr tua := f_TfiUsfArrInit();
3393 var octetstring data := '0000'O & f_rnd_octstring(21);
3394
3395 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003396
Harald Welte883340c2018-02-28 18:59:29 +01003397 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003398 f_TfiUsfArrSet(tua, 7, 0);
3399 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3400 f_sleep(1.0);
3401
3402 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003403}
3404
3405testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003406 var TfiUsfArr tua := f_TfiUsfArrInit();
3407 var octetstring data := '0000'O & f_rnd_octstring(21);
3408
3409 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003410
Harald Welte883340c2018-02-28 18:59:29 +01003411 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003412 f_TfiUsfArrSet(tua, 7, 0);
3413 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3414 f_sleep(1.0);
3415
3416 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01003417}
3418
3419/* Send AGCH from PCU; check it appears on Um side */
3420testcase TC_pcu_data_req_agch() runs on test_CT {
3421 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003422 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003423 f_init_l1ctl();
3424 f_l1_tune(L1CTL);
3425
3426 f_TC_pcu_act_req(0, 0, 7, true);
3427 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3428
3429 T.start;
3430 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003431 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003432 setverdict(pass);
3433 }
3434 [] L1CTL.receive { repeat; }
3435 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003436 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003437 }
3438 }
3439}
3440
3441/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3442testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3443 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003444 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003445 f_init_l1ctl();
3446 f_l1_tune(L1CTL);
3447
3448 /* append 3 last imsi digits so BTS can compute pagng group */
3449 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3450
3451 timer T := 0.5;
3452 T.start;
3453 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003454 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003455 /* TODO: verify paging group */
3456 setverdict(pass);
3457 }
3458 [] L1CTL.receive { repeat; }
3459 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003461 }
3462 }
3463}
3464
3465/* Send RACH from Um side, expect it to show up on PCU socket */
3466testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003467 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003468 f_init_l1ctl();
3469 f_l1_tune(L1CTL);
3470
3471 var GsmFrameNumber fn_last := 0;
3472 for (var integer i := 0; i < 1000; i := i+1) {
3473 var OCT1 ra := f_rnd_ra_ps();
3474 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3475 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003477 }
3478 fn_last := fn;
3479
3480 timer T := 2.0;
3481 T.start;
3482 alt {
3483 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3484 T.stop;
3485 }
3486 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003488 }
3489 [] PCU.receive { repeat; }
3490 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003492 }
3493 }
3494 }
3495 setverdict(pass);
3496}
3497
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003498/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3499 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3500testcase TC_pcu_ext_rach_content() runs on test_CT {
3501 var template PCUIF_Message pcu_rach_ind;
3502 var GsmFrameNumber fn_last := 0;
3503 var L1ctlRachSynchSeq synch_seq;
3504 var PCUIF_BurstType pcu_bt;
3505 var GsmFrameNumber fn;
3506 var BIT11 ra11;
3507
3508 f_init_pcu_test();
3509 f_init_l1ctl();
3510 f_l1_tune(L1CTL);
3511
3512 for (var integer i := 0; i < 1000; i := i+1) {
3513 /* We need to test both TS1 & TS2 */
3514 if (i rem 2 == 0) {
3515 synch_seq := RACH_SYNCH_SEQ_TS1;
3516 pcu_bt := BURST_TYPE_1;
3517 } else {
3518 synch_seq := RACH_SYNCH_SEQ_TS2;
3519 pcu_bt := BURST_TYPE_2;
3520 }
3521
3522 ra11 := f_rnd_ra11_ps();
3523 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3524 if (fn == fn_last) {
3525 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3526 "Two RACH in same FN?!?");
3527 }
3528 fn_last := fn;
3529
3530 /* Compose the expected message */
3531 pcu_rach_ind := tr_PCUIF_RACH_IND(
3532 bts_nr := 0,
3533 ra := bit2int(ra11),
3534 is_11bit := 1,
3535 burst_type := pcu_bt,
3536 fn := fn);
3537
3538 timer T := 2.0;
3539 T.start;
3540 alt {
3541 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3542 T.stop;
3543 }
3544 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3546 }
3547 [] PCU.receive { repeat; }
3548 [] T.timeout {
3549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3550 }
3551 }
3552 }
3553 setverdict(pass);
3554}
3555
Harald Welte883340c2018-02-28 18:59:29 +01003556private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
3557 var integer strlen := lengthof(str);
3558 for (var integer i := 0; i < len-strlen; i := i+1) {
3559 str := str & pad;
3560 }
3561 return str;
3562}
3563
3564/* Send PAGING via RSL, expect it to shw up on PCU socket */
3565testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003566 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003567
3568 for (var integer i := 0; i < 100; i := i+1) {
3569 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3570 timer T := 3.0;
3571 if (i < 50) {
3572 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3573 } else {
3574 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3575 }
3576 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3577 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3578 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3579
3580 /* Send RSL PAGING COMMAND */
3581 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3582 T.start;
3583 alt {
3584 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3585 }
3586 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003587 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003588 }
3589 [] PCU.receive { repeat; }
3590 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003591 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003592 }
3593 }
3594 }
3595 setverdict(pass);
3596}
3597
Harald Welted66c9b82019-05-25 09:03:15 +02003598/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
3599testcase TC_pcu_time_ind() runs on test_CT {
3600 var PCUIF_send_data pcu_sd;
3601 var integer num_time_ind := 0;
3602 var integer first_fn, last_fn;
3603 var float test_duration := 5.0;
3604 timer T;
3605
3606 f_init_pcu_test();
3607 f_TC_pcu_act_req(0, 0, 7, true);
3608
3609 PCU.clear;
3610 T.start(test_duration);
3611 alt {
3612 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
3613 num_time_ind := num_time_ind + 1;
3614 if (not isbound(first_fn)) {
3615 first_fn := pcu_sd.data.u.time_ind.fn;
3616 }
3617 last_fn := pcu_sd.data.u.time_ind.fn;
3618 repeat;
3619 }
3620 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
3621 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
3622 repeat;
3623 }
3624 [] PCU.receive {
3625 repeat;
3626 }
3627 [] T.timeout {}
3628 }
3629 var integer fn_expired := last_fn - first_fn;
3630 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
3631
3632 /* verify the number of frames expired matches our expectation */
3633 const float c_GSM_FN_DURATION_MS := 4.61538;
3634 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
3635 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
3636 if (not match(fn_expired, t_fn_expected)) {
3637 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3638 }
3639
3640 /* There are three TIME.ind in every fn MOD 13 */
3641 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
3642 /* Add some tolerance */
3643 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
3644 if (not match(num_time_ind, t_time_ind_exp)) {
3645 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
3646 }
3647
3648 setverdict(pass);
3649}
3650
Harald Welte4832c862019-05-25 14:57:18 +02003651/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
3652testcase TC_pcu_rts_req() runs on test_CT {
3653 var PCUIF_send_data pcu_sd;
3654 var integer first_fn, last_fn;
3655 var integer num_rts_pdtch := 0;
3656 var integer num_rts_ptcch := 0;
3657 var float test_duration := 5.0;
3658 timer T;
3659
3660 f_init_pcu_test();
3661 f_TC_pcu_act_req(0, 0, 7, true);
3662
3663 PCU.clear;
3664 T.start(test_duration);
3665 alt {
3666 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
3667 -> value pcu_sd {
3668 num_rts_pdtch := num_rts_pdtch + 1;
3669 if (not isbound(first_fn)) {
3670 first_fn := pcu_sd.data.u.rts_req.fn;
3671 }
3672 last_fn := pcu_sd.data.u.rts_req.fn;
3673 repeat;
3674 }
3675 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
3676 -> value pcu_sd {
3677 num_rts_ptcch := num_rts_ptcch + 1;
3678 if (not isbound(first_fn)) {
3679 first_fn := pcu_sd.data.u.rts_req.fn;
3680 }
3681 last_fn := pcu_sd.data.u.rts_req.fn;
3682 repeat;
3683 }
3684 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
3685 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
3686 repeat;
3687 }
3688 [] PCU.receive {
3689 repeat;
3690 }
3691 [] T.timeout {}
3692 }
3693 var integer fn_expired := last_fn - first_fn;
3694 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
3695 ", num_rts_ptcch=", num_rts_ptcch);
3696
3697 /* verify the number of frames expired matches our expectation */
3698 const float c_GSM_FN_DURATION_MS := 4.61538;
3699 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
3700 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
3701 if (not match(fn_expired, t_fn_expected)) {
3702 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3703 }
3704
3705 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
3706 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
3707 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
3708 if (not match(num_rts_ptcch, t_ptcch_exp)) {
3709 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
3710 t_ptcch_exp);
3711 }
3712
3713 /* We have 12 PDTCH blocks every 52-multiframe */
3714 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
3715 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
3716 if (not match(num_rts_pdtch, t_pdtch_exp)) {
3717 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
3718 t_pdtch_exp);
3719 }
3720
3721 setverdict(pass);
3722}
3723
Harald Welte07bd2d22019-05-25 11:03:30 +02003724/* test for generating Abis side OML ALERT from the PCU */
3725testcase TC_pcu_oml_alert() runs on test_CT {
3726 var PCUIF_send_data pcu_sd;
3727 var integer num_time_ind := 0;
3728 var integer first_fn, last_fn;
3729 var float test_duration := 5.0;
3730 timer T;
3731
3732 f_init_pcu_test();
3733 f_TC_pcu_act_req(0, 0, 7, true);
3734
3735 /* re-connect CTRL port from BTS to BSC */
3736 f_ipa_ctrl_stop();
3737 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
3738
3739 /* Send that OML Alert */
3740 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
3741
3742 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
3743 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
3744 setverdict(pass);
3745}
3746
3747
Harald Welted66c9b82019-05-25 09:03:15 +02003748
Harald Welte3d04ae62018-04-04 20:29:05 +02003749/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02003750 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02003751 ***********************************************************************/
3752
3753private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3754runs on ConnHdlr {
3755 var PCUIF_send_data sd;
3756 /* Expect BTS to immediately acknowledge activation as PDCH */
3757 PCU.clear;
3758 f_rsl_chan_act(g_pars.chan_mode);
3759 /* expect INFO_IND on PCU interface listing TS as PDCH */
3760 alt {
3761 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3762 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003763 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003764 }
3765 }
3766 [] PCU.receive { repeat; }
3767 }
3768 /* try to activate this PDCH from the PCU point of view */
3769 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3770 /* FIXME: is there a response? */
3771}
3772
3773private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3774runs on ConnHdlr {
3775 var PCUIF_send_data sd;
3776 /* Send RSL CHAN REL (deactivate) */
3777 PCU.clear;
3778 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3779 /* expect BTS to ask PCU to deactivate the channel */
3780 alt {
3781 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3782 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003783 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003784 }
3785 }
3786 [] PCU.receive { repeat; }
3787 }
3788 /* Emulate PCU asking BTS to deactivate PDCH */
3789 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3790 alt {
3791 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
3792 setverdict(pass);
3793 }
3794 [] RSL.receive { repeat; }
3795 }
3796}
3797
3798/* Activate Osmocom-style dynamic PDCH from BSC side */
3799function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
3800 var PCUIF_Message first_info;
3801 var integer ts_nr := g_chan_nr.tn;
3802 var integer trx_nr := 0;
3803 var integer bts_nr := 0;
3804 var integer pcu_conn_id := -1;
3805
3806 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3807
3808 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3809 f_sleep(3.0);
3810 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3811 setverdict(pass);
3812}
3813testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
3814 var ConnHdlrPars pars;
3815 var ConnHdlr vc_conn;
3816 f_init(testcasename());
3817
3818 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3819 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
3820 vc_conn.done;
3821}
3822
3823/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
3824function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
3825 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02003826 var integer pcu_conn_id := -1;
3827
3828 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3829
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02003830 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3831 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
3832 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02003833 setverdict(pass);
3834}
3835testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
3836 var ConnHdlrPars pars;
3837 var ConnHdlr vc_conn;
3838 f_init(testcasename());
3839
3840 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3841 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
3842 vc_conn.done;
3843}
3844
3845/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
3846function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
3847 var PCUIF_Message first_info;
3848 var integer ts_nr := g_chan_nr.tn;
3849 var integer trx_nr := 0;
3850 var integer bts_nr := 0;
3851 var integer pcu_conn_id := -1;
3852
3853 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3854
3855 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02003856 /* Send a second Chan Activ and expect it to be NACKed */
3857 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3858 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02003859 setverdict(pass);
3860}
3861testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
3862 var ConnHdlrPars pars;
3863 var ConnHdlr vc_conn;
3864 f_init(testcasename());
3865
3866 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3867 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
3868 vc_conn.done;
3869}
3870
3871/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
3872function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
3873 var PCUIF_Message first_info;
3874 var integer ts_nr := g_chan_nr.tn;
3875 var integer trx_nr := 0;
3876 var integer bts_nr := 0;
3877 var integer pcu_conn_id := -1;
3878 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
3879
3880 /* register for the TCH/F channel number */
3881 f_rslem_register(0, chan_nr);
3882
3883 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3884
3885 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
3886 "RSL CHAN ACT");
3887 setverdict(pass);
3888}
3889testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
3890 var ConnHdlrPars pars;
3891 var ConnHdlr vc_conn;
3892 f_init(testcasename());
3893
3894 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3895 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
3896 vc_conn.done;
3897}
3898
3899/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
3900function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
3901 var PCUIF_Message first_info;
3902 var integer ts_nr := g_chan_nr.tn;
3903 var integer trx_nr := 0;
3904 var integer bts_nr := 0;
3905 var integer pcu_conn_id := -1;
3906 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
3907 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
3908
3909 /* register for the TCH/H channel numbers */
3910 f_rslem_register(0, chan_nr[0]);
3911 f_rslem_register(0, chan_nr[1]);
3912
3913 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3914
3915 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
3916 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
3917 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
3918 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
3919 setverdict(pass);
3920}
3921testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
3922 var ConnHdlrPars pars;
3923 var ConnHdlr vc_conn;
3924 f_init(testcasename());
3925
3926 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3927 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
3928 vc_conn.done;
3929}
3930
Harald Welte9bbbfb52018-04-05 09:33:19 +02003931/***********************************************************************
3932 * IPA Style Dynamic Timeslot Support
3933 ***********************************************************************/
3934
3935private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3936runs on ConnHdlr {
3937 var PCUIF_send_data sd;
3938 /* Expect BTS to immediately acknowledge activation as PDCH */
3939 PCU.clear;
3940 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
3941 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003942 timer T_wait := 2.0;
3943 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003944 alt {
3945 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3946 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003947 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
3948 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
3949 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003950 }
3951 }
3952 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003953 [] T_wait.timeout {
3954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3955 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
3956 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02003957 }
3958 /* try to activate this PDCH from the PCU point of view */
3959 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3960 /* FIXME: is there a response? */
3961
3962 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
3963}
3964
3965private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3966runs on ConnHdlr {
3967 var PCUIF_send_data sd;
3968 /* Send RSL CHAN REL (deactivate) */
3969 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
3970 PCU.clear;
3971 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003972 timer T_wait := 2.0;
3973 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003974 alt {
3975 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3976 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003977 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
3978 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
3979 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02003980 }
3981 }
3982 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01003983 [] T_wait.timeout {
3984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3985 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
3986 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02003987 }
3988 /* Emulate PCU asking BTS to deactivate PDCH */
3989 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3990 alt {
3991 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
3992 setverdict(pass);
3993 }
3994 [] RSL.receive { repeat; }
3995 }
3996}
3997
3998/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
3999function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4000 var PCUIF_Message first_info;
4001 var integer ts_nr := g_chan_nr.tn;
4002 var integer trx_nr := 0;
4003 var integer bts_nr := 0;
4004 var integer pcu_conn_id := -1;
4005
4006 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4007
4008 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4009 f_sleep(3.0);
4010 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4011
4012 setverdict(pass);
4013
4014}
4015testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4016 var ConnHdlrPars pars;
4017 var ConnHdlr vc_conn;
4018 f_init();
4019
4020 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4021 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4022 vc_conn.done;
4023}
4024
4025/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4026function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4027 var PCUIF_Message first_info;
4028 var integer ts_nr := g_chan_nr.tn;
4029 var integer trx_nr := 0;
4030 var integer bts_nr := 0;
4031 var integer pcu_conn_id := -1;
4032
4033 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4034
4035 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4036 "RSL CHAN ACT");
4037 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4038 "RF CHAN REL", true);
4039 setverdict(pass);
4040}
4041testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4042 var ConnHdlrPars pars;
4043 var ConnHdlr vc_conn;
4044 f_init(testcasename());
4045
4046 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4047 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4048 vc_conn.done;
4049}
4050
4051/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4052function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4053 var PCUIF_Message first_info;
4054 var integer ts_nr := g_chan_nr.tn;
4055 var integer trx_nr := 0;
4056 var integer bts_nr := 0;
4057 var integer pcu_conn_id := -1;
4058
4059 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4060
4061 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4062 "RSL CHAN ACT");
4063
4064 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4065 alt {
4066 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4067 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004068 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004069 }
4070 [] RSL.receive { repeat; }
4071 }
4072
4073 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4074 "RF CHAN REL", true);
4075 setverdict(pass);
4076}
4077testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4078 var ConnHdlrPars pars;
4079 var ConnHdlr vc_conn;
4080 f_init(testcasename());
4081
4082 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4083 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4084 vc_conn.done;
4085}
4086
4087/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4088function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4089 var PCUIF_Message first_info;
4090 var integer ts_nr := g_chan_nr.tn;
4091 var integer trx_nr := 0;
4092 var integer bts_nr := 0;
4093 var integer pcu_conn_id := -1;
4094
4095 /* register for the TCH/F channel number */
4096 f_rslem_register(0, g_chan_nr);
4097
4098 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4099
4100 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4101
4102 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4103 "RSL CHAN ACT");
4104
4105 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4106
4107 setverdict(pass);
4108}
4109testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4110 var ConnHdlrPars pars;
4111 var ConnHdlr vc_conn;
4112 f_init(testcasename());
4113
4114 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4115 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
4116 vc_conn.done;
4117}
4118
4119
Harald Welte0472ab42018-03-12 15:02:26 +01004120/***********************************************************************
4121 * LAPDm / RLL related
4122 ***********************************************************************/
4123
4124private function f_tx_lapdm(template (value) LapdmFrame l,
4125 template (value) RslLinkId link_id) runs on ConnHdlr {
4126 var octetstring l2 := enc_LapdmFrame(valueof(l));
4127 if (valueof(link_id.c) == SACCH) {
4128 /* prepend dummy L1 header */
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02004129 var L1ctlDataReq l1hl2 := {
4130 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
4131 l2_payload := f_pad_oct(l2, 21, '2B'O)
4132 }
4133 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1hl2));
4134 } else {
4135 /* If required, pad L2 frame with constant 0x2b filling */
4136 l2 := f_pad_oct(l2, 23, '2B'O);
4137
4138 log("encoding ", l, " to ", l2);
4139 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
Harald Welte0472ab42018-03-12 15:02:26 +01004140 }
Harald Welte0472ab42018-03-12 15:02:26 +01004141}
4142
4143type record RllTestCase {
4144 uint3_t sapi,
4145 RslLinkId link_id,
4146 octetstring l3,
4147 boolean exp
4148}
4149type record of RllTestCase RllTestCases;
4150template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
4151 sapi := sapi,
4152 link_id := id,
4153 l3 := l3,
4154 exp := exp
4155}
4156
4157/* execute the same callback function with a set of different parameters (tcs) on a
4158 * variety of logical channels */
4159private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
4160 var ConnHdlrPars pars;
4161 var ConnHdlr vc_conn;
4162 f_init(testcasename());
4163
4164 /* test on each of the channels we have */
4165 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
4166 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
4167
4168 /* test each of the test cases on the current channel */
4169 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
4170 pars.spec.rll := tcs[j];
4171 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
4172 vc_conn := f_start_handler(fn, pars);
4173 vc_conn.done;
4174 }
4175 }
4176
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004177 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01004178}
4179
4180/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
4181private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
4182 var RllTestCase tc := g_pars.spec.rll;
4183 timer T := 3.0;
4184
4185 f_l1_tune(L1CTL);
4186 RSL.clear;
4187
4188 /* activate the logical channel */
4189 f_est_dchan();
4190 L1CTL.clear;
4191
4192 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
4193 T.start;
4194 alt {
4195 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
4196 if (tc.exp) {
4197 setverdict(pass);
4198 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004199 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004200 }
4201 }
4202 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
4203 if (tc.exp) {
4204 setverdict(pass);
4205 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004206 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004207 }
4208 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004209 /* We also expect to receive the measurements */
4210 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004211 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004212 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004213 }
4214 [not tc.exp] T.timeout {
4215 setverdict(pass);
4216 }
4217 }
4218
4219 f_rsl_chan_deact();
4220 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4221 f_rslem_unregister(0, g_chan_nr);
4222}
4223testcase TC_rll_est_ind() runs on test_CT {
4224 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02004225 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01004226 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02004227 /* normal SAPI0 establishment */
4228 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01004229 /* SAPI 3 doesn't support contention resolution */
4230 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
4231 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
4232 /* normal SAPI3 establishment on main DCCH */
4233 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4234 /* normal SAPI3 establishment on SACCH */
4235 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4236 };
4237 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
4238}
4239
4240/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
4241private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
4242 var RllTestCase tc := g_pars.spec.rll;
4243 var L1ctlDlMessage dl;
4244 timer T := 3.0;
4245
4246 f_l1_tune(L1CTL);
4247 RSL.clear;
4248
4249 /* activate the logical channel */
4250 f_est_dchan();
4251 L1CTL.clear;
4252
4253 /* Send a RSL EST REQ for SAPI3 on main DCCH */
4254 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
4255 T.start;
4256 alt {
4257 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4258 var LapdmFrame lapdm;
4259 var octetstring l2 := dl.payload.data_ind.payload;
4260 if (dl.dl_info.link_id.c == SACCH) {
4261 /* remove L1 header */
4262 l2 := substr(l2, 2, lengthof(l2)-2);
4263 }
4264 lapdm.ab := dec_LapdmFrameAB(l2);
4265 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
4266 setverdict(pass);
4267 } else {
4268 repeat;
4269 }
4270 }
4271 [] L1CTL.receive { repeat; }
4272 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004273 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01004274 }
4275 }
4276
4277 f_rsl_chan_deact();
4278 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4279 f_rslem_unregister(0, g_chan_nr);
4280}
4281testcase TC_rll_est_req_DCCH_3() runs on test_CT {
4282 var RllTestCases tcs := {
4283 /* normal SAPI3 establishment on main DCCH */
4284 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
4285 };
4286 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4287}
4288testcase TC_rll_est_req_ACCH_3() runs on test_CT {
4289 var RllTestCases tcs := {
4290 /* normal SAPI3 establishment on SACCH */
4291 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4292 }
4293 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4294}
4295
4296/* altstep to receive a LAPDm frame matching the given template */
4297private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
4298 var L1ctlDlMessage dl;
4299 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4300 var LapdmFrame lapdm;
4301 var octetstring l2 := dl.payload.data_ind.payload;
4302 if (dl.dl_info.link_id.c == SACCH) {
4303 /* remove L1 header */
4304 l2 := substr(l2, 2, lengthof(l2)-2);
4305 }
4306 if (ischosen(exp.ab)) {
4307 lapdm.ab := dec_LapdmFrameAB(l2);
4308 } else if (ischosen(exp.b4)) {
4309 lapdm.b4 := dec_LapdmFrameB4(l2);
4310 } else if (ischosen(exp.bbis)) {
4311 lapdm.bbis := dec_LapdmFrameBbis(l2);
4312 }
4313 log("Rx LAPDm ", lapdm);
4314 if (match(lapdm, exp)) {
4315 setverdict(pass);
4316 } else {
4317 repeat;
4318 }
4319 }
4320 [] L1CTL.receive { repeat; }
4321}
4322private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
4323 timer T := t;
4324 T.start;
4325 alt {
4326 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004327 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01004328 }
4329 [] as_l1_exp_lapdm(exp);
4330 }
4331}
4332
4333/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
4334private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4335 /* send SABM from MS -> BTS */
4336 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
4337 /* expect RLL EST IND on Abis */
4338 alt {
4339 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
4340 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
4341 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004342 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004343 }
4344 [] RSL.receive { repeat; }
4345 }
4346 /* expect UA from BTS -> MS */
4347 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
4348}
4349
4350/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
4351private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
4352 var RllTestCase tc := g_pars.spec.rll;
4353
4354 f_l1_tune(L1CTL);
4355 RSL.clear;
4356
4357 /* activate the logical channel */
4358 f_est_dchan();
4359 L1CTL.clear;
4360
4361 /* first establish the link-layer */
4362 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4363
4364 /* then send the DISC */
4365 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
4366 /* ... and expect the REL IND on the RSL side */
4367 alt {
4368 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
4369 setverdict(pass);
4370 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004371 /* We also expect to receive the measurements */
4372 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004373 }
4374
4375 /* release the channel */
4376 f_rsl_chan_deact();
4377 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4378 f_rslem_unregister(0, g_chan_nr);
4379}
4380testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
4381 var RllTestCases tcs := {
4382 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
4383 };
4384 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4385}
4386
4387testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
4388 var RllTestCases tcs := {
4389 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
4390 };
4391 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4392}
4393testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
4394 var RllTestCases tcs := {
4395 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
4396 };
4397 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4398}
4399testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
4400 var RllTestCases tcs := {
4401 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4402 };
4403 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4404}
4405
4406/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
4407private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
4408 var RllTestCase tc := g_pars.spec.rll;
4409 f_l1_tune(L1CTL);
4410 RSL.clear;
4411
4412 /* activate the logical channel */
4413 f_est_dchan();
4414 L1CTL.clear;
4415
4416 /* first establish the link-layer */
4417 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4418
4419 /* then send the REL REQ via RSL */
4420 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
4421 /* ... and expect the DISC on the Um side */
4422 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02004423 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01004424 /* FIXME: send a UA in resposne to the DISC */
4425 }
4426 }
4427
4428 /* release the channel */
4429 f_rsl_chan_deact();
4430 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4431 f_rslem_unregister(0, g_chan_nr);
4432}
4433testcase TC_rll_rel_req() runs on test_CT {
4434 var RllTestCases tcs := {
4435 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
4436 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
4437 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4438 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4439 };
4440 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
4441}
4442
4443/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
4444testcase TC_rll_data_req() runs on test_CT {
4445}
4446
4447/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
4448testcase TC_rll_data_ind() runs on test_CT {
4449}
4450
4451/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
4452private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
4453 var RllTestCase tc := g_pars.spec.rll;
4454
4455 f_l1_tune(L1CTL);
4456 RSL.clear;
4457
4458 f_est_dchan();
4459 L1CTL.clear;
4460
4461 /* Send UNITDATA REQ on RSL side */
4462 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
4463 /* Expect it to arrive on the other side */
4464 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02004465 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004466 } else {
Harald Weltee613f962018-04-18 22:38:16 +02004467 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004468 }
4469
4470 /* release the channel */
4471 f_rsl_chan_deact();
4472 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4473 f_rslem_unregister(0, g_chan_nr);
4474}
4475testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
4476 var octetstring l3 := f_rnd_octstring(15);
4477 var RllTestCases tcs := {
4478 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4479 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4480 };
4481 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4482}
4483testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
4484 var octetstring l3 := f_rnd_octstring(19);
4485 var RllTestCases tcs := {
4486 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4487 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4488 };
4489 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4490}
4491
4492/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
4493private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
4494 var RllTestCase tc := g_pars.spec.rll;
4495
4496 f_l1_tune(L1CTL);
4497 RSL.clear;
4498
4499 f_est_dchan();
4500 L1CTL.clear;
4501
4502 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02004503 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01004504 /* Expdct RLL UNITDATA IND on RSL side */
4505 alt {
4506 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
4507 setverdict(pass);
4508 }
4509 [] RSL.receive { repeat; }
4510 }
4511
4512 /* release the channel */
4513 f_rsl_chan_deact();
4514 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4515 f_rslem_unregister(0, g_chan_nr);
4516}
4517testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02004518 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01004519 var RllTestCases tcs := {
4520 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4521 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4522 };
4523 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4524}
4525testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
4526 var octetstring l3 := f_rnd_octstring(18);
4527 var RllTestCases tcs := {
4528 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4529 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4530 };
4531 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4532}
4533
Harald Weltee613f962018-04-18 22:38:16 +02004534/***********************************************************************
4535 * Encryption Related
4536 ***********************************************************************/
4537
4538/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4539function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4540 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
4541 if (link_id.c == SACCH) {
4542 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
4543 } else {
4544 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
4545 }
4546}
4547
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004548/* Expect (or not expect) other kinds of messages */
4549private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
4550 [exp_any] RSL.receive { repeat; }
4551 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004552 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004553 }
4554}
4555
Harald Weltee613f962018-04-18 22:38:16 +02004556/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07004557private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004558 RslLinkId link_id,
4559 octetstring l3,
4560 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004561 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004562) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02004563 timer T := 3.0;
4564 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
4565 T.start;
4566 /* Expect RLL UNITDATA IND on RSL side */
4567 alt {
4568 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
4569 setverdict(pass);
4570 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004571 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004572 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02004573 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004574 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02004575 }
Harald Weltee613f962018-04-18 22:38:16 +02004576 }
4577}
4578
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004579/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
4580private function f_data_mo(
4581 RslLinkId link_id,
4582 boolean p, uint3_t nr, uint3_t ns,
4583 octetstring l3,
4584 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004585 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004586) runs on ConnHdlr {
4587 timer T := 3.0;
4588 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
4589 T.start;
4590 /* Expect RLL DATA IND on RSL side */
4591 alt {
4592 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
4593 setverdict(pass);
4594 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004595 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004596 [] as_rsl_any_ind(exp_any);
4597 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004598 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004599 }
4600 }
4601}
4602
Harald Weltee613f962018-04-18 22:38:16 +02004603/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
4604function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
4605 f_l1_tune(L1CTL);
4606 f_est_dchan(true);
4607
4608 /* now we actually need to transmit some data both ways to check if the encryption works */
4609 var L1ctlDlMessage dl;
4610
Stefan Sperling603d98e2018-07-25 16:47:28 +02004611 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02004612 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4613
4614 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4615 f_unitdata_mt(link_id, l3);
4616
4617 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
4618 f_unitdata_mo(link_id, l3);
4619
4620 /* release the channel */
4621 f_rsl_chan_deact();
4622 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4623 f_rslem_unregister(0, g_chan_nr);
4624}
4625testcase TC_chan_act_a51() runs on test_CT {
4626 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4627 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4628 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4629}
4630testcase TC_chan_act_a52() runs on test_CT {
4631 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4632 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4633 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4634}
4635testcase TC_chan_act_a53() runs on test_CT {
4636 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4637 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4638 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4639}
4640
4641
4642/* Test unencrypted channel activation followed by explicit ENCR CMD later */
4643function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
4644 /* L3 payload doesn't matter, as it is passed transparently */
4645 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
4646 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
4647 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4648
4649 f_l1_tune(L1CTL);
4650
4651 /* first establish a dedicated channel in the clear */
4652 f_est_dchan(false);
4653
4654 /* Establish ABM */
4655 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4656
4657 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
4658 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
4659 /* expect the L3 to arrive still unencrypted on the MS side */
4660 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
4661
4662 /* configure L1 to apply ciphering */
4663 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
4664 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
4665
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004666 /* send first ciphered I-frame in response and expect it on RSL */
4667 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02004668
4669 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
4670 * and hence enable encryption also on the downlink */
4671
4672 /* expect bi-directional communication work in encrypted mode */
4673 f_unitdata_mo(link_id, f_rnd_octstring(15));
4674 f_unitdata_mt(link_id, f_rnd_octstring(15));
4675
4676 /* release the channel */
4677 f_rsl_chan_deact();
4678 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4679 f_rslem_unregister(0, g_chan_nr);
4680}
4681testcase TC_encr_cmd_a51() runs on test_CT {
4682 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4683 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4684 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4685}
4686testcase TC_encr_cmd_a52() runs on test_CT {
4687 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4688 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4689 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4690}
4691testcase TC_encr_cmd_a53() runs on test_CT {
4692 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4693 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4694 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4695}
4696
4697private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
4698 var LapdmFrame lf;
4699 var octetstring reenc;
4700
4701 /* decode the LAPDm frame */
4702 if (ischosen(exp_match.ab)) {
4703 lf.ab := dec_LapdmFrameAB(enc);
4704 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004705 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02004706 }
4707
4708 /* check if decoder result matches expectation */
4709 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004710 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004711 } else {
4712 log(name, ": matched");
4713 setverdict(pass);
4714 }
4715
4716 /* test if re-encoded frame equals original input */
4717 reenc := enc_LapdmFrame(lf);
4718 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004719 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004720 } else {
4721 setverdict(pass);
4722 }
4723}
4724
4725testcase TC_lapdm_selftest() runs on test_CT {
4726 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
4727 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
4728 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
4729 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
4730 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
4731 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
4732 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
4733}
4734
Stefan Sperling4880be42018-08-07 18:12:59 +02004735/***********************************************************************
4736 * DTX Related (see GSM 05.08, section 8.3)
4737 ***********************************************************************/
4738
4739/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
4740function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
4741 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
4742 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
4743 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
4744 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
4745}
4746function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
4747 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
4748 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
4749}
4750function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
4751 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
4752 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
4753 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
4754 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
4755}
4756function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
4757 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
4758 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
4759 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
4760 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
4761 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
4762 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
4763 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
4764 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
4765}
4766
4767function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
4768 var L1ctlDlMessage dl;
4769 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
4770 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
4771 var GsmFrameNumber first_fn;
4772 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004773 var integer nfill_frames_sacch := 0;
4774 var integer nfill_frames_nonsacch := 0;
4775 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02004776 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
4777 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004778 const integer frame_dtx_tchf_mod := 104;
4779 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
4780 * which operates in terms of blocks rather than frames. */
4781 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
4782 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02004783 timer T := 5.0;
4784
4785 f_l1_tune(L1CTL);
4786 RSL.clear;
4787 L1CTL.clear;
4788
4789 /* activate TCHF signalling channel */
4790 f_est_dchan(false);
4791
4792 T.start;
4793 alt {
4794 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4795 var GsmFrameNumber fn := dl.dl_info.frame_nr;
4796 var octetstring l2 := dl.payload.data_ind.payload;
4797
4798 if (is_first_frame) {
4799 is_first_frame := false;
4800 first_fn := dl.dl_info.frame_nr;
4801 }
4802
4803 if (dl.dl_info.link_id.c == SACCH) {
4804 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
4805 if (not match(l2_fill_frame_sacch, l2)) {
4806 repeat;
4807 }
4808 } else if (not match(l2_fill_frame, l2)) {
4809 repeat;
4810 }
4811
4812 if (dtxd) {
4813 if (not f_g_chan_is_tchf()) {
4814 T.stop;
4815 f_rsl_chan_deact();
4816 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004817 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 +02004818 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004819 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004820 T.stop;
4821 f_rsl_chan_deact();
4822 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004823
4824 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
4825 * 2 SACCH, 1 TCH/F */
4826 expected_fill_frames := 3;
4827
4828 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
4829 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4830 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004831 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004832 } else {
4833 setverdict(pass);
4834 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004835 } else {
4836 if (dl.dl_info.link_id.c == SACCH) {
4837 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02004838 repeat;
4839 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004840 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
4841 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
4842 * we should only see the subset of frames numbers which correspond to a block boundary.
4843 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
4844 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
4845 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
4846 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4847 repeat;
4848 }
4849 }
4850 log("Received DTX TCH fill frame with bad frame number: ", fn,
4851 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
4852 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
4853 f_rsl_chan_deact();
4854 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004855 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004856 }
Stefan Sperling4880be42018-08-07 18:12:59 +02004857 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004858 if (dl.dl_info.link_id.c == SACCH) {
4859 nfill_frames_sacch := nfill_frames_sacch + 1;
4860 } else {
4861 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4862 }
4863 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004864 T.stop;
4865 if (f_g_chan_is_tchf()) {
4866 /* Without DTX we can expect 25 fill frames for every 104 frames.
4867 * (24 FACCH + 1 SACCH filling) */
4868 expected_fill_frames := 25;
4869 } else if (f_g_chan_is_tchh()) {
4870 /* We can expect 2 fill frames for every 104 frames. */
4871 expected_fill_frames := 2;
4872 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
4873 /* We can expect 5 fill frames for every 104 frames. */
4874 expected_fill_frames := 5;
4875 } else {
4876 f_rsl_chan_deact();
4877 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02004879 }
4880
4881 f_rsl_chan_deact();
4882 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004883
4884 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004885 setverdict(pass);
4886 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004887 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4888 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004889 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004890 }
4891 } else {
4892 repeat;
4893 }
4894 }
4895 }
4896 [] L1CTL.receive { repeat; }
4897 [] T.timeout {
4898 f_rsl_chan_deact();
4899 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004900 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004901 }
4902 }
4903}
4904
4905function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
4906 f_test_l2_fill_frames(false);
4907}
4908
4909function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
4910 f_test_l2_fill_frames(true);
4911}
4912
4913function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
4914 var ConnHdlr vc_conn;
4915 var ConnHdlrPars pars;
4916 pars.t_guard := 60.0;
4917 f_init(testcasename());
4918 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
4919 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
4920 if (dtxd) {
4921 if (i >= 4) { /* DTX is only allowed on TCH/F */
4922 break;
4923 }
4924 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
4925 } else {
4926 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
4927 }
4928 vc_conn.done;
4929 }
4930}
4931
4932/* Verify that L2 fill frames are sent on TCH in signaling mode if
4933 * there is nothing to transmit while DTX is disabled on downlink. */
4934testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
4935 f_tch_sign_l2_fill_frame(false);
4936}
4937
4938/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
4939 * there is nothing to transmit while DTX is enabled on downlink. */
4940testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
4941 f_tch_sign_l2_fill_frame(true);
4942}
Harald Welte0472ab42018-03-12 15:02:26 +01004943
Stefan Sperling0ec1c262018-10-15 15:12:52 +02004944testcase TC_chopped_ipa_ping() runs on test_CT {
4945 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
4946}
4947
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004948testcase TC_chopped_ipa_payload() runs on test_CT {
4949 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
4950}
4951
Harald Welte0472ab42018-03-12 15:02:26 +01004952/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
4953/* protocol error as per 44.006 */
4954/* link layer failure (repetition of I-frame N200 times without ACK */
4955/* repetition of SABM or DISC N200 times without ACK */
4956/* receptiom of SABM in multi-frame established state */
4957
4958
Harald Welte68e495b2018-02-25 00:05:57 +01004959/* TODO Areas:
4960
4961* channel activation
4962** with BS_Power / MS_Power, bypassing power control loop
4963** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01004964** with timing advance from initial activation on
4965* mode modify
4966** encryption
4967** multirate
4968* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01004969** unsupported algorithm
4970* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01004971* BS Power Control
4972* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01004973* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01004974* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01004975** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01004976* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01004977** DATA_IND from BTS->PCU
4978** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01004979
4980*/
Harald Welte70767382018-02-21 12:16:40 +01004981
4982control {
4983 execute( TC_chan_act_stress() );
4984 execute( TC_chan_act_react() );
4985 execute( TC_chan_deact_not_active() );
4986 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01004987 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01004988 execute( TC_sacch_filling() );
4989 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01004990 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01004991 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02004992 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02004993 execute( TC_sacch_chan_act_ho_async() );
4994 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01004995 execute( TC_rach_content() );
4996 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01004997 execute( TC_rach_max_ta() );
Harald Welte3453ab42019-05-24 21:19:58 +02004998 execute( TC_rach_load_idle_thresh0() );
4999 execute( TC_rach_load_idle_below_thresh() );
5000 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01005001 execute( TC_meas_res_sign_tchf() );
5002 execute( TC_meas_res_sign_tchh() );
5003 execute( TC_meas_res_sign_sdcch4() );
5004 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01005005 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01005006 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild6833cc92019-05-23 19:34:44 +02005007 execute( TC_rsl_chan_initial_ta() );
Harald Welte70767382018-02-21 12:16:40 +01005008 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01005009 execute( TC_paging_imsi_80percent() );
5010 execute( TC_paging_tmsi_80percent() );
5011 execute( TC_paging_imsi_200percent() );
5012 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01005013 execute( TC_rsl_protocol_error() );
5014 execute( TC_rsl_mand_ie_error() );
5015 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01005016 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01005017 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01005018 execute( TC_si_sched_2bis() );
5019 execute( TC_si_sched_2ter() );
5020 execute( TC_si_sched_2ter_2bis() );
5021 execute( TC_si_sched_2quater() );
5022 execute( TC_si_sched_13() );
5023 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01005024 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01005025 execute( TC_ipa_crcx_twice_not_active() );
5026 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01005027 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01005028 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01005029
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005030 if (mp_pcu_socket != "") {
5031 execute( TC_pcu_act_req() );
5032 execute( TC_pcu_act_req_wrong_ts() );
5033 execute( TC_pcu_act_req_wrong_bts() );
5034 execute( TC_pcu_act_req_wrong_trx() );
5035 execute( TC_pcu_deact_req() );
5036 execute( TC_pcu_deact_req_wrong_ts() );
5037 execute( TC_pcu_ver_si13() );
5038 execute( TC_pcu_data_req_wrong_bts() );
5039 execute( TC_pcu_data_req_wrong_trx() );
5040 execute( TC_pcu_data_req_wrong_ts() );
5041 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02005042 if (mp_l1_supports_gprs) {
5043 execute( TC_pcu_data_req_pdtch() );
5044 execute( TC_pcu_data_req_ptcch() );
5045 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005046 execute( TC_pcu_data_req_agch() );
5047 execute( TC_pcu_data_req_imm_ass_pch() );
5048 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005049 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005050 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02005051 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02005052 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02005053 execute( TC_pcu_oml_alert() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005054 } else {
5055 log("PCU socket path not available, skipping PCU tests");
5056 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005057
5058 execute( TC_dyn_osmo_pdch_act_deact() );
5059 execute( TC_dyn_osmo_pdch_unsol_deact() );
5060 execute( TC_dyn_osmo_pdch_double_act() );
5061 execute( TC_dyn_osmo_pdch_tchf_act() );
5062 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02005063 execute( TC_dyn_ipa_pdch_act_deact() );
5064 execute( TC_dyn_ipa_pdch_tchf_act() );
5065 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
5066 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01005067
5068 execute( TC_rll_est_ind() );
5069 execute( TC_rll_est_req_DCCH_3() );
5070 execute( TC_rll_est_req_ACCH_3() );
5071 execute( TC_rll_rel_ind_DCCH_0() );
5072 execute( TC_rll_rel_ind_DCCH_3() );
5073 execute( TC_rll_rel_ind_ACCH_0() );
5074 execute( TC_rll_rel_ind_ACCH_3() );
5075 execute( TC_rll_rel_req() );
5076 execute( TC_rll_unit_data_req_DCCH() );
5077 execute( TC_rll_unit_data_req_ACCH() );
5078 execute( TC_rll_unit_data_ind_DCCH() );
5079 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02005080
5081 execute( TC_chan_act_a51() );
5082 execute( TC_chan_act_a52() );
5083 execute( TC_chan_act_a53() );
5084 execute( TC_encr_cmd_a51() );
5085 execute( TC_encr_cmd_a52() );
5086 execute( TC_encr_cmd_a53() );
5087
Harald Welteee25aae2019-05-19 14:32:37 +02005088 execute( TC_err_rep_wrong_mdisc() );
5089 execute( TC_err_rep_wrong_msg_type() );
5090 execute( TC_err_rep_wrong_sequence() );
5091
Harald Weltee613f962018-04-18 22:38:16 +02005092 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02005093
5094 execute( TC_tch_sign_l2_fill_frame() );
5095 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005096
5097 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005098 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01005099}
5100
5101
5102}