blob: 21e56346029e54055ce12810fda4ee01c3601a91 [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 Welteeaa9a862019-05-26 23:01:08 +020035import from L3_Common all;
36import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010037
Harald Welte8da48242018-02-27 20:41:32 +010038import from Osmocom_VTY_Functions all;
39import from TELNETasp_PortType all;
40
Harald Welte505cf9b2018-09-15 17:47:23 +030041friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020042friend module BTS_Tests_virtphy;
Harald Welte505cf9b2018-09-15 17:47:23 +030043
Harald Welte70767382018-02-21 12:16:40 +010044/* The tests assume a BTS with the following timeslot configuration:
45 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020046 * TS1 : TCH/F
47 * TS2 : TCH/F
48 * TS3 : TCH/F_PDCH (IPA Style)
49 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010050 * TS5 : TCH/H
51 * TS6 : SDCCH/8
52 * TS7 : PDCH
53 */
54
55modulepar {
56 charstring mp_rsl_ip := "127.0.0.2";
57 integer mp_rsl_port := 3003;
58 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070059 charstring mp_bts_trxc_ip := "127.0.0.1";
60 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010061 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020062 charstring mp_ctrl_ip := "127.0.0.1";
63 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020064 charstring mp_bsc_ctrl_ip := "127.0.0.1";
65 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020066 integer mp_tolerance_rxqual := 1;
67 integer mp_tolerance_rxlev := 3;
68 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020069 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020070 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020071 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020072 integer mp_ms_actual_ta_exp := 0;
73 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +010074 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +020075 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +020076 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +020077 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
78 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +010079}
80
Harald Welte629cc6b2018-03-11 17:19:05 +010081type record of RslChannelNr ChannelNrs;
82
Harald Welte70767382018-02-21 12:16:40 +010083type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +010084 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +010085 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +010086 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +010087 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +010088 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +010089 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +010090
91 /* L1CTL port (for classic tests) */
92 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +010093
Harald Welte54a2a2d2018-02-26 09:14:05 +010094 /* TRXC port (for classic tests) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070095 port TRXC_CODEC_PT BTS_TRXC;
96 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +010097
Harald Weltef50e3ae2018-09-10 10:27:56 +020098 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +010099 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200100 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100101
Harald Welte883340c2018-02-28 18:59:29 +0100102 /* PCU Interface of BTS */
103 port PCUIF_CODEC_PT PCU;
104 var integer g_pcu_conn_id;
105 /* Last PCU INFO IND we received */
106 var PCUIF_Message g_pcu_last_info;
107
Harald Welte48494ca2018-02-25 16:59:50 +0100108 /* SI configuration */
109 var SystemInformationConfig si_cfg := {
110 bcch_extended := false,
111 si1_present := false,
112 si2bis_present := false,
113 si2ter_present := false,
114 si2quater_present := false,
115 si7_present := false,
116 si8_present := false,
117 si9_present := false,
118 si13_present := false,
119 si13alt_present := false,
120 si15_present := false,
121 si16_present := false,
122 si17_present := false,
123 si2n_present := false,
124 si21_present := false,
125 si22_present := false
126 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100127
128 /* all logical channels available on the BTS */
129 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100130 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100131}
132
133/* an individual call / channel */
134type component ConnHdlr extends RSL_DchanHdlr {
135 port L1CTL_PT L1CTL;
136
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700137 port TRXC_CODEC_PT BTS_TRXC;
138 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100139
140 timer g_Tguard;
141 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
142
143 var ConnHdlrPars g_pars;
144 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100145 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200146
147 /* PCU Interface of BTS */
148 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100149}
150
151function f_init_rsl(charstring id) runs on test_CT {
152 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
153 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
154
155 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
156 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
157 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
158
159 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
160 vc_RSL.start(RSL_Emulation.main(false));
161}
162
163type record ConnHdlrPars {
164 RslChannelNr chan_nr,
165 RSL_IE_ChannelMode chan_mode,
166 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100167 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200168 TestSpecUnion spec optional,
169 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100170}
171
172/* Test-specific parameters */
173type union TestSpecUnion {
174 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100175}
176
Harald Welte82ccef72018-02-25 16:17:33 +0100177template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100178 max_retrans := RACH_MAX_RETRANS_7,
179 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100180 cell_barr_access := false,
181 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100182 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100183};
184
Harald Weltef10153f2018-02-25 16:34:05 +0100185template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100186 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200187 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100188 acs := '0'B,
189 neci := true,
190 rxlev_access_min := 0
191}
192
193template (value) LocationAreaIdentification ts_LAI_default := {
194 mcc_mnc := '262F42'H,
195 lac := 42
196}
197
Harald Welte7484fc42018-02-24 14:09:45 +0100198/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100199template (value) SystemInformation ts_SI3_default := {
200 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100201 payload := {
202 si3 := {
203 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100204 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100205 ctrl_chan_desc := {
206 msc_r99 := true,
207 att := true,
208 bs_ag_blks_res := 1,
209 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100210 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100211 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
212 spare := '00'B,
213 bs_pa_mfrms := 0, /* 2 multiframes */
214 t3212 := 1 /* 6 minutes */
215 },
Harald Welte82ccef72018-02-25 16:17:33 +0100216 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100217 dn_ind := false,
218 pwrc := false,
219 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100220 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100221 },
Harald Weltef10153f2018-02-25 16:34:05 +0100222 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100223 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100224 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100225 }
226 }
227}
Harald Welte70767382018-02-21 12:16:40 +0100228
Harald Weltef8df4cb2018-03-10 15:15:08 +0100229template (value) SystemInformation ts_SI2_default := {
230 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100231 payload := {
232 si2 := {
233 bcch_freq_list := '00000000000000000000000000000000'O,
234 ncc_permitted := '11111111'B,
235 rach_control := ts_RachCtrl_default
236 }
237 }
238}
239
Harald Weltef8df4cb2018-03-10 15:15:08 +0100240template (value) SystemInformation ts_SI4_default := {
241 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100242 payload := {
243 si4 := {
244 lai := ts_LAI_default,
245 cell_sel_par := ts_CellSelPar_default,
246 rach_control := ts_RachCtrl_default,
247 cbch_chan_desc := omit,
248 cbch_mobile_alloc := omit,
249 rest_octets := ''O
250 }
251 }
252}
253
254function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
255runs on test_CT {
256 log("Setting ", rsl_si_type, ": ", si_enc);
257 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
258}
259
260function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
261runs on test_CT {
262 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
263 log("Setting ", rsl_si_type, ": ", si_dec);
264 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
265}
266
Harald Welte505cf9b2018-09-15 17:47:23 +0300267friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100268 map(self:BTSVTY, system:BTSVTY);
269 f_vty_set_prompts(BTSVTY);
270 f_vty_transceive(BTSVTY, "enable");
271}
272
Harald Welte505cf9b2018-09-15 17:47:23 +0300273friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200274 map(self:BSCVTY, system:BSCVTY);
275 f_vty_set_prompts(BSCVTY, "OsmoBSC");
276 f_vty_transceive(BSCVTY, "enable");
277}
278
Harald Welte883340c2018-02-28 18:59:29 +0100279/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200280private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
281 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100282 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200283 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
284 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100285 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200286 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200287 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100288 }
289}
290
Harald Weltef26de0b2018-04-04 20:28:05 +0200291private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
292 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100293 timer T := 2.0;
294 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100295 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200296 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100297 return;
298 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200299 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100300
301 T.start;
302 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200303 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100304 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200305 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100306 }
307 }
308}
309
Harald Welte70767382018-02-21 12:16:40 +0100310/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100311function f_init(charstring id := "BTS-Test") runs on test_CT {
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100312 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100313 g_AllChannels := {
314 /* TS 1..4: TCH/F */
315 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
316 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
317 /* TS 5: TCH/H */
318 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
319 /* TS 0: SDCCH/4 */
320 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
321 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
322 /* TS 6: SDCCH/8 */
323 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
324 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
325 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
326 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
327 };
328
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200329 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700330 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200331 g_AllChanTypes := {
332 /* TS 1..4: TCH/F */
333 valueof(ts_RslChanNr_Bm(1)),
334 /* TS 5: TCH/H */
335 valueof(ts_RslChanNr_Lm(5,1)),
336 /* TS 0: SDCCH/4 */
337 valueof(ts_RslChanNr_SDCCH4(0,2)),
338 /* TS 6: SDCCH/8 */
339 valueof(ts_RslChanNr_SDCCH8(6,4))
340 };
341 } else {
342 g_AllChanTypes := {
343 /* TS 1..4: TCH/F */
344 valueof(ts_RslChanNr_Bm(1)),
345 /* TS 0: SDCCH/4 */
346 valueof(ts_RslChanNr_SDCCH4(0,2)),
347 /* TS 6: SDCCH/8 */
348 valueof(ts_RslChanNr_SDCCH8(6,4))
349 };
350 }
Harald Welte70767382018-02-21 12:16:40 +0100351 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200352 T.start;
353 alt {
354 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
355 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200357 }
358 }
Harald Welte2d142592018-02-25 13:19:44 +0100359 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100360 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200361 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100362
363 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100364 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
365 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
366 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
367 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100368
Harald Weltef26de0b2018-04-04 20:28:05 +0200369 map(self:PCU, system:PCU);
370 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100371
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700372 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100373 var TrxcMessage ret;
374 /* start with a default moderate timing offset equalling TA=2 */
375 f_main_trxc_connect();
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700376 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 +0100377 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200378
379 /* Wait some extra time to make sure the BTS emits a stable carrier.
380 * (this is only relevant when running the tests with a physical BTS.) */
381 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100382}
383
Harald Welte68e495b2018-02-25 00:05:57 +0100384/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
385function f_init_l1ctl() runs on test_CT {
386 map(self:L1CTL, system:L1CTL);
387 f_connect_reset(L1CTL);
388}
389
Harald Welte70767382018-02-21 12:16:40 +0100390type function void_fn(charstring id) runs on ConnHdlr;
391
392/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200393function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100394runs on test_CT return ConnHdlr {
395 var charstring id := testcasename();
396 var ConnHdlr vc_conn;
397
398 vc_conn := ConnHdlr.create(id);
399 /* connect to RSL Emulation main component */
400 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
401 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200402 if (pcu_comp) {
403 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
404 * it from the test_CT and connect it to the component. This obviously only
405 * works for one component, i.e. no concurrency */
406 unmap(self:PCU, system:PCU);
407 map(vc_conn:PCU, system:PCU);
408 }
Harald Welte70767382018-02-21 12:16:40 +0100409
410 vc_conn.start(f_handler_init(fn, id, pars));
411 return vc_conn;
412}
413
Harald Welte7484fc42018-02-24 14:09:45 +0100414template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
415 streamId := sid,
416 rsl := rsl
417}
418
419template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
420 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
421 streamId := sid,
422 rsl := rsl
423}
424
Harald Welte70767382018-02-21 12:16:40 +0100425private altstep as_Tguard() runs on ConnHdlr {
426 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100428 }
429}
430
Harald Welte505cf9b2018-09-15 17:47:23 +0300431friend function f_l1_tune(L1CTL_PT L1CTL) {
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +0200432 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100433}
434
435private function f_trxc_connect() runs on ConnHdlr {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700436 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte70767382018-02-21 12:16:40 +0100437 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700438 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Weltea4d8f352018-03-01 15:47:20 +0100439 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +0200440 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200441 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 +0200442 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700443 g_bts_trxc_conn_id := res.connId;
Harald Welte70767382018-02-21 12:16:40 +0100444}
445
446private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100447 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700448 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100449}
450
451private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100452 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700453 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100454}
455
456/* first function started in ConnHdlr component */
457private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
458runs on ConnHdlr {
459 g_pars := pars;
460 g_chan_nr := pars.chan_nr;
461
462 map(self:L1CTL, system:L1CTL);
463 f_connect_reset(L1CTL);
464
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700465 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100466 f_trxc_connect();
467 }
Harald Welte70767382018-02-21 12:16:40 +0100468
469 g_Tguard.start(pars.t_guard);
470 activate(as_Tguard());
471
472 f_rslem_register(0, pars.chan_nr);
473
474 /* call the user-supplied test case function */
475 fn.apply(id);
476}
477
Harald Welteb1726c92018-03-30 11:56:38 +0200478function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
479 boolean ignore_other := false)
480runs on ConnHdlr return RSL_Message {
481 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100482 timer T := 3.0;
483 RSL.send(tx);
484 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100485 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200486 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100487 T.stop;
488 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100489 }
Harald Welte1eba3742018-02-25 12:48:14 +0100490 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200491 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100492 }
Harald Welte21240e62018-03-11 21:43:35 +0100493 [not ignore_other] as_l1_sacch();
494 [not ignore_other] as_meas_res();
495 [not ignore_other] as_l1_dcch();
496 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200497 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100498 }
Harald Welte21240e62018-03-11 21:43:35 +0100499 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100500 }
Harald Welteb1726c92018-03-30 11:56:38 +0200501 return rx;
502}
503
504function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
505 boolean ignore_other := false)
506runs on ConnHdlr {
507 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100508}
509
Harald Welte8b01c792019-05-19 22:51:25 +0200510function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
511 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
512 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200513 if (encr_enable) {
514 /* append encryption related IEs, if requested */
515 var RSL_IE_EncryptionInfo encr_info;
516 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
517 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
518encr_info})) };
519 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200520 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200521 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100522}
523
Harald Welte70767382018-02-21 12:16:40 +0100524function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100525 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 +0100526 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100527}
528
Harald Welte70767382018-02-21 12:16:40 +0100529private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
530 template RSL_IE_ChannelMode chan_mode,
531 float t_guard := 20.0) := {
532 chan_nr := valueof(chan_nr),
533 chan_mode := valueof(chan_mode),
534 t_guard := t_guard,
535 l1_pars := {
536 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100537 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100538 meas_ul := {
539 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200540 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100541 rxqual := 0
542 },
543 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200544 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100545 rxqual := 0
546 }
547 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200548 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100549 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200550 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200551 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100552 },
Harald Weltee613f962018-04-18 22:38:16 +0200553 spec := omit,
554 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100555}
556
Harald Welte93640c62018-02-25 16:59:33 +0100557/***********************************************************************
558 * Channel Activation / Deactivation
559 ***********************************************************************/
560
Harald Welte70767382018-02-21 12:16:40 +0100561/* Stress test: Do 500 channel activations/deactivations in rapid succession */
562function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
563 for (var integer i := 0; i < 500; i := i+1) {
564 f_rsl_chan_act(g_pars.chan_mode);
565 f_rsl_chan_deact();
566 }
567 setverdict(pass);
568}
569testcase TC_chan_act_stress() runs on test_CT {
570 var ConnHdlr vc_conn;
571 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
572 f_init(testcasename());
573 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
574 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200575 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100576}
577
578/* Test if re-activation of an already active channel fails as expected */
579function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
580 f_rsl_chan_act(g_pars.chan_mode);
581 /* attempt to activate the same lchan again -> expect reject */
582 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
583 alt {
584 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200585 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100586 }
587 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
588 setverdict(pass);
589 }
590 }
591 f_rsl_chan_deact();
592}
593testcase TC_chan_act_react() runs on test_CT {
594 var ConnHdlr vc_conn;
595 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100596 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100597 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
598 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200599 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100600}
601
602/* Attempt to de-activate a channel that's not active */
603function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
604 timer T := 3.0;
605 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
606 T.start;
607 alt {
608 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
609 setverdict(pass);
610 }
611 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200612 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100613 }
614 }
615}
616testcase TC_chan_deact_not_active() runs on test_CT {
617 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100618 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100619 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
620 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200621 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100622}
623
624/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
625function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
626 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
627 alt {
628 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200629 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100630 }
631 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
632 setverdict(pass);
633 }
634 }
635}
636private type record WrongChanNrCase {
637 RslChannelNr chan_nr,
638 charstring description
639}
640private type record of WrongChanNrCase WrongChanNrCases;
641private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
642 chan_nr := chan_nr,
643 description := desc
644}
645
646testcase TC_chan_act_wrong_nr() runs on test_CT {
647 var ConnHdlr vc_conn;
648 var ConnHdlrPars pars;
649
Harald Welte294b0a22018-03-10 23:26:48 +0100650 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100651
652 var WrongChanNrCases wrong := {
653 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
654 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
655 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
656 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
657 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
658 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
659 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
660 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
661 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
662 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
663 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
664 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
665 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
666 };
667
668 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
669 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
670 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
671 vc_conn.done;
672 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100674}
675
Harald Weltee613f962018-04-18 22:38:16 +0200676/* execute the same callback function on a variety of logical channels */
677private function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
678 var ConnHdlr vc_conn;
679 f_init(testcasename());
680
681 /* test on each of the channels we have */
682 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
683 pars.chan_nr := valueof(g_AllChanTypes[i]);
684
685 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
686 vc_conn := f_start_handler(fn, pars);
687 vc_conn.done;
688 }
689
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200690 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200691}
692
Harald Welte93640c62018-02-25 16:59:33 +0100693/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100694 * SACCH handling
695 ***********************************************************************/
696
697private function f_exp_sacch(boolean exp) runs on ConnHdlr {
698 timer T_sacch := 3.0;
699 T_sacch.start;
700 alt {
701 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100703 }
704 [not exp] T_sacch.timeout {
705 setverdict(pass);
706 }
707 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
708 setverdict(pass);
709 }
710 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100712 }
713 [] L1CTL.receive { repeat; }
714 [] RSL.receive { repeat; }
715 }
716}
717
718/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
719private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
720 f_l1_tune(L1CTL);
721 RSL.clear;
722
723 /* activate the logical channel */
724 f_est_dchan();
725 L1CTL.clear;
726
727 /* check that SACCH actually are received as expected */
728 f_exp_sacch(true);
729
730 /* deactivate SACCH on the logical channel */
731 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
732 f_sleep(1.0);
733 L1CTL.clear;
734
735 /* check that no SACCH are received anymore */
736 f_exp_sacch(false);
737
738 /* release the channel */
739 f_rsl_chan_deact();
740 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
741}
742testcase TC_deact_sacch() runs on test_CT {
743 var ConnHdlr vc_conn;
744 var ConnHdlrPars pars;
745 f_init();
746 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
747 //for (var integer i := 0; i < 1; i := i+1) {
748 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
749 log(testcasename(), ": Starting for ", g_AllChannels[i]);
750 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
751 vc_conn.done;
752 }
753 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200754 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100755}
756
Harald Welte55700662018-03-12 13:15:43 +0100757/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100758private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
759 var L1ctlDlMessage dl;
760 /* check that the specified SI5 value is actually sent */
761 timer T_sacch := 3.0;
762 L1CTL.clear;
763 T_sacch.start;
764 alt {
765 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
766 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
767 if (match(l3, l3_exp)) {
768 setverdict(pass);
769 } else {
770 repeat;
771 }
772 }
773 [] L1CTL.receive { repeat; }
774 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200775 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100776 }
777 }
778}
779
Harald Welte55700662018-03-12 13:15:43 +0100780/* verify that given SACCH payload is not present */
781private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
782 var L1ctlDlMessage dl;
783 /* check that the specified SI5 value is actually sent */
784 timer T_sacch := 3.0;
785 L1CTL.clear;
786 T_sacch.start;
787 alt {
788 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
789 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
790 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200791 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100792 } else {
793 repeat;
794 }
795 }
796 [] L1CTL.receive { repeat; }
797 [] T_sacch.timeout {
798 setverdict(pass);
799 }
800 }
801}
802
Harald Welte629cc6b2018-03-11 17:19:05 +0100803/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100804private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
805 /* Set a known default SACCH filling for SI5 */
806 var octetstring si5 := f_rnd_octstring(19);
807 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
808
809 f_l1_tune(L1CTL);
810 RSL.clear;
811
812 /* activate the logical channel */
813 f_est_dchan();
814
815 /* check that the specified SI5 value is actually sent */
816 f_sacch_present(si5);
817
818 /* release the channel */
819 RSL.clear;
820 f_rsl_chan_deact();
821 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
822}
823testcase TC_sacch_filling() runs on test_CT {
824 var ConnHdlr vc_conn;
825 var ConnHdlrPars pars;
826 f_init();
827 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
828 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
829 log(testcasename(), ": Starting for ", g_AllChannels[i]);
830 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
831 vc_conn.done;
832 }
833 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200834 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100835}
836
Harald Welte629cc6b2018-03-11 17:19:05 +0100837/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100838private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
839 /* Set a known default SACCH filling for SI5 */
840 var octetstring si5 := f_rnd_octstring(19);
841 var octetstring si5_diff := f_rnd_octstring(19);
842 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
843
844 f_l1_tune(L1CTL);
845 RSL.clear;
846
847 log("Activating channel, expecting standard SI5");
848 /* activate the logical channel */
849 f_est_dchan();
850 /* check that the specified SI5 value is actually sent */
851 f_sacch_present(si5);
852
853 /* set channel-specific different SI5 */
854 log("Setting channel specific SACCH INFO, expecting it");
855 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
856 /* check that the specified lchan-specific value is now used */
857 f_sacch_present(si5_diff);
858
859 /* deactivate the channel and re-activate it, this should result in default SI5 */
860 log("De-activating and re-activating channel, expecting standard SI5");
861 f_rsl_chan_deact();
862 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
863 /* Verify that the TRX-wide default SACCH filling is present again */
864 f_sacch_present(si5);
865
866 /* release the channel */
867 RSL.clear;
868 f_rsl_chan_deact();
869 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
870}
871testcase TC_sacch_info_mod() runs on test_CT {
872 var ConnHdlr vc_conn;
873 var ConnHdlrPars pars;
874 f_init();
875 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
876 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
877 log(testcasename(), ": Starting for ", g_AllChannels[i]);
878 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
879 vc_conn.done;
880 }
881 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200882 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100883}
884
Harald Welte075d84c2018-03-12 13:07:24 +0100885/* Test SACCH scheduling of multiple different SI message types */
886private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
887 var octetstring si5 := f_rnd_octstring(19);
888 var octetstring si5bis := f_rnd_octstring(19);
889 var octetstring si5ter := f_rnd_octstring(19);
890 var octetstring si6 := f_rnd_octstring(19);
891
892 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
893 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
894 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
895 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
896
897 f_l1_tune(L1CTL);
898 RSL.clear;
899
900 /* activate the logical channel */
901 f_est_dchan();
902 L1CTL.clear;
903
904 /* check that SACCH actually are received as expected */
905 f_sacch_present(si5);
906 f_sacch_present(si5bis);
907 f_sacch_present(si5ter);
908 f_sacch_present(si6);
909
910 /* release the channel */
911 f_rsl_chan_deact();
912 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
913}
914testcase TC_sacch_multi() runs on test_CT {
915 var ConnHdlr vc_conn;
916 var ConnHdlrPars pars;
917 f_init();
918 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
919 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
920 log(testcasename(), ": Starting for ", g_AllChannels[i]);
921 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
922 vc_conn.done;
923 }
924 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200925 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100926}
927
Harald Welte55700662018-03-12 13:15:43 +0100928/* Test if SACH information is modified as expected */
929private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
930 var octetstring si5 := f_rnd_octstring(19);
931 var octetstring si6 := f_rnd_octstring(19);
932
933 /* First, configure both SI5 and SI6 to be transmitted */
934 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
935 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
936
937 f_l1_tune(L1CTL);
938 RSL.clear;
939
940 /* activate the logical channel */
941 f_est_dchan();
942 L1CTL.clear;
943
944 /* check that SACCH actually are received as expected */
945 f_sacch_present(si5);
946 f_sacch_present(si6);
947
948 /* disable SI6 */
949 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
950
951 /* check that SI5 is still transmitted */
952 f_sacch_present(si5);
953 /* check if SI6 is now gone */
954 f_sacch_missing(si6);
955
956 /* release the channel */
957 f_rsl_chan_deact();
958 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
959}
960testcase TC_sacch_multi_chg() runs on test_CT {
961 var ConnHdlr vc_conn;
962 var ConnHdlrPars pars;
963 f_init();
964 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
965 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
966 log(testcasename(), ": Starting for ", g_AllChannels[i]);
967 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
968 vc_conn.done;
969 }
970 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200971 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +0100972}
973
Harald Weltec8d363c2019-05-19 20:36:48 +0200974/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
975private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
976 var octetstring si5 := f_rnd_octstring(19);
977 var octetstring si6 := f_rnd_octstring(19);
978 var octetstring si5_specific := f_rnd_octstring(19);
979 var octetstring si6_specific := f_rnd_octstring(19);
980
981 /* First, configure both SI5 and SI6 to be transmitted */
982 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
983 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
984
985 f_l1_tune(L1CTL);
986 RSL.clear;
987
988 /* activate channel with different SACCH filling */
989 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
990 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
991 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
992 }));
993 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
994 RSL_IE_Body:{sacch_info := sacch_info})) };
995 f_est_dchan(more_ies := addl_ies);
996
997 /* check that SACCH actually are received as expected */
998 f_sacch_present(si5_specific);
999 f_sacch_present(si6_specific);
1000
1001 /* release the channel */
1002 f_rsl_chan_deact();
1003 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1004}
1005testcase TC_sacch_chan_act() runs on test_CT {
1006 var ConnHdlr vc_conn;
1007 var ConnHdlrPars pars;
1008 f_init();
1009
1010 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1011 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1012 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1013 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1014 vc_conn.done;
1015 }
1016 /* TODO: do the above in parallel, rather than sequentially? */
1017 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1018}
1019
Harald Welte8b01c792019-05-19 22:51:25 +02001020/* verify that SACCH DL transmission is started only if MS power IE present
1021 * see section 4.1.3 of 3GPP TS 48.058 */
1022private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1023 var octetstring si5 := f_rnd_octstring(19);
1024
1025 f_l1_tune(L1CTL);
1026 RSL.clear;
1027
1028 /* Step 1: Activate ASYNC HO channel without MS power IE */
1029
1030 /* Activate channel on BTS side */
1031 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1032 /* don't perform immediate assignment here, as we're testing non-IA case */
1033 /* enable dedicated mode */
1034 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1035
1036 /* Verify that no DL SACCH is being received */
1037 f_sacch_missing(?);
1038
1039 f_rsl_chan_deact();
1040 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1041
1042
1043 /* Step 2: Activate ASYNC HO channel with MS power IE */
1044
1045 /* Activate channel on BTS side */
1046 var RSL_IE_List addl_ies := {
1047 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1048 };
1049 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1050 /* don't perform immediate assignment here, as we're testing non-IA case */
1051 /* enable dedicated mode */
1052 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1053
1054 /* Verify that DL SACCH is being received */
1055 f_sacch_present(si5);
1056
1057 f_rsl_chan_deact();
1058 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1059}
1060testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1061 var ConnHdlr vc_conn;
1062 var ConnHdlrPars pars;
1063 f_init();
1064
1065 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1066 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1067 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1068 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1069 vc_conn.done;
1070 }
1071 /* TODO: do the above in parallel, rather than sequentially? */
1072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1073}
1074
1075/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1076 * see section 4.1.4 of 3GPP TS 48.058 */
1077private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1078 var octetstring si5 := f_rnd_octstring(19);
1079 var RSL_IE_List addl_ies;
1080
1081 f_l1_tune(L1CTL);
1082 RSL.clear;
1083
1084 /* Step 1: Activate SYNC HO channel without MS power IE */
1085
1086 /* Activate channel on BTS side */
1087 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1088 /* don't perform immediate assignment here, as we're testing non-IA case */
1089 /* enable dedicated mode */
1090 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1091
1092 /* Verify that no DL SACCH is being received */
1093 f_sacch_missing(?);
1094
1095 f_rsl_chan_deact();
1096 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1097
1098
1099 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1100
1101 /* Activate channel on BTS side */
1102 addl_ies := {
1103 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1104 };
1105 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1106 /* don't perform immediate assignment here, as we're testing non-IA case */
1107 /* enable dedicated mode */
1108 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1109
1110 /* Verify that no DL SACCH is being received */
1111 f_sacch_missing(?);
1112
1113 f_rsl_chan_deact();
1114 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1115
1116
1117 /* Step 2b: Activate SYNC HO channel with TA IE */
1118
1119 /* Activate channel on BTS side */
1120 addl_ies := {
1121 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1122 };
1123 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1124 /* don't perform immediate assignment here, as we're testing non-IA case */
1125 /* enable dedicated mode */
1126 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1127
1128 /* Verify that no DL SACCH is being received */
1129 f_sacch_missing(?);
1130
1131 f_rsl_chan_deact();
1132 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1133
1134
1135 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1136
1137 /* Activate channel on BTS side */
1138 addl_ies := {
1139 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1140 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1141 };
1142 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1143 /* don't perform immediate assignment here, as we're testing non-IA case */
1144 /* enable dedicated mode */
1145 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1146
1147 /* Verify that DL SACCH is being received */
1148 f_sacch_present(si5);
1149
1150 f_rsl_chan_deact();
1151 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1152}
1153testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1154 var ConnHdlr vc_conn;
1155 var ConnHdlrPars pars;
1156 f_init();
1157
1158 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1159 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1160 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1161 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1162 vc_conn.done;
1163 }
1164 /* TODO: do the above in parallel, rather than sequentially? */
1165 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1166}
Harald Welte629cc6b2018-03-11 17:19:05 +01001167
1168
1169/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001170 * RACH Handling
1171 ***********************************************************************/
1172
Harald Welte8c24c2b2018-02-26 08:31:31 +01001173/* like L1SAP_IS_PACKET_RACH */
1174private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001175 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001176 return true;
1177 }
1178 return false;
1179}
1180
1181/* generate a random RACH for circuit-switched */
1182private function f_rnd_ra_cs() return OCT1 {
1183 var OCT1 ra;
1184 do {
1185 ra := f_rnd_octstring(1);
1186 } while (ra_is_ps(ra));
1187 return ra;
1188}
1189
Harald Welte883340c2018-02-28 18:59:29 +01001190/* generate a random RACH for packet-switched */
1191private function f_rnd_ra_ps() return OCT1 {
1192 var OCT1 ra;
1193 do {
1194 ra := f_rnd_octstring(1);
1195 } while (not ra_is_ps(ra));
1196 return ra;
1197}
1198
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001199/* generate a random 11-bit RA (packet-switched only) */
1200private function f_rnd_ra11_ps() return BIT11 {
1201 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1202 return int2bit(ra11, 11);
1203}
1204
Harald Welte8c24c2b2018-02-26 08:31:31 +01001205/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1206testcase TC_rach_content() runs on test_CT {
1207 f_init(testcasename());
1208 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001209 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001210
Harald Welte8c24c2b2018-02-26 08:31:31 +01001211 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001212 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001213 for (var integer i := 0; i < 1000; i := i+1) {
1214 var OCT1 ra := f_rnd_ra_cs();
1215 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1216 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001217 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001218 }
1219 fn_last := fn;
1220
1221 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001222 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001223 alt {
1224 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
1225 T.stop;
1226 }
1227 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001229 }
1230 [] RSL_CCHAN.receive { repeat; }
1231 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001232 test_failed := true;
1233 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001234 }
1235 }
1236 }
Maxba06feb2019-03-05 10:52:46 +01001237 if (test_failed) {
1238 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001239 }
Maxba06feb2019-03-05 10:52:46 +01001240 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001241 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001242}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001243
1244/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1245testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001246 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001247 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001248 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001249 f_l1_tune(L1CTL);
1250
1251 var GsmFrameNumber fn_last := 0;
1252 for (var integer i := 0; i < 1000; i := i+1) {
1253 var OCT1 ra := f_rnd_ra_cs();
1254 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1255 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001256 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001257 }
1258 fn_last := fn;
1259 }
1260 var integer rsl_chrqd := 0;
1261 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001262 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001263 alt {
1264 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1265 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001266 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001267 repeat;
1268 }
1269 [] RSL_CCHAN.receive { repeat; }
1270 [] T.timeout { }
1271 }
1272 if (rsl_chrqd == 1000) {
1273 setverdict(pass);
1274 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001275 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001276 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001277 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001278}
1279
Harald Welte3453ab42019-05-24 21:19:58 +02001280private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1281 var charstring bts_str := "bts " & int2str(bts_nr);
1282 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1283}
1284
1285/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1286private template integer tr_rach_slots_per_interval := (90 .. 130);
1287
1288/* Expect 0 RACH load on an idle BTS that has just started up */
1289testcase TC_rach_load_idle_thresh0() runs on test_CT {
1290 var ASP_RSL_Unitdata rx_ud;
1291
1292 f_init_vty_bsc();
1293 /* send load indications even at 0% load */
1294 f_vty_load_ind_thresh(0);
1295 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1296 f_sleep(2.0);
1297
1298 f_init();
1299
1300 timer T := 5.0;
1301 T.start;
1302 alt {
1303 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1304 setverdict(pass);
1305 repeat;
1306 }
1307 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1308 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1309 repeat;
1310 }
1311 [] RSL_CCHAN.receive {
1312 repeat;
1313 }
1314 [] T.timeout { }
1315 }
1316
1317 f_vty_load_ind_thresh(10);
1318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1319}
1320
1321/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1322testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1323 var ASP_RSL_Unitdata rx_ud;
1324
1325 f_init_vty_bsc();
1326 f_init();
1327
1328 timer T := 5.0;
1329 T.start;
1330 alt {
1331 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1332 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1333 repeat;
1334 }
1335 [] RSL_CCHAN.receive {
1336 repeat;
1337 }
1338 [] T.timeout {
1339 setverdict(pass);
1340 }
1341 }
1342
1343 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1344}
1345
1346/* Expect 0 RACH load on an idle BTS that has just started up */
1347testcase TC_rach_load_count() runs on test_CT {
1348 var ASP_RSL_Unitdata rx_ud;
1349 var integer load_access_count := 0;
1350
1351 f_init_vty_bsc();
1352 /* send load indications even at 0% load */
1353 f_vty_load_ind_thresh(0);
1354 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1355 f_sleep(2.0);
1356 f_init();
1357
1358 f_init_l1ctl();
1359 f_sleep(1.0);
1360 f_l1_tune(L1CTL);
1361
1362 var GsmFrameNumber fn_last := 0;
1363 for (var integer i := 0; i < 1000; i := i+1) {
1364 var OCT1 ra := f_rnd_ra_cs();
1365 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1366 if (fn == fn_last) {
1367 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1368 }
1369 fn_last := fn;
1370 }
1371
1372 timer T := 5.0;
1373 T.start;
1374 alt {
1375 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1376 -> value rx_ud {
1377 var RSL_IE_Body ie;
1378 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1379 load_access_count := load_access_count + ie.rach_load.access_count;
1380 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1381 setverdict(fail, "Access count cannot be < Busy count");
1382 }
1383 repeat;
1384 }
1385 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1386 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1387 repeat;
1388 }
1389 [] RSL_CCHAN.receive {
1390 repeat;
1391 }
1392 [] T.timeout { }
1393 }
1394 if (load_access_count == 1000) {
1395 setverdict(pass);
1396 } else {
1397 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1398 }
1399
1400 f_vty_load_ind_thresh(10);
1401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1402}
1403
1404
1405
Harald Welte54a2a2d2018-02-26 09:14:05 +01001406private function f_main_trxc_connect() runs on test_CT {
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001407 map(self:BTS_TRXC, system:BTS_TRXC);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001408 var Result res;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001409 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BTS_TRXC, mp_bts_trxc_ip, mp_bts_trxc_port,
Harald Welted3a88a62018-03-01 16:04:52 +01001410 "", -1, -1, {udp:={}}, {});
Harald Welte9220f632018-05-23 20:27:02 +02001411 if (not ispresent(res.connId)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001412 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 +02001413 }
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001414 g_bts_trxc_conn_id := res.connId;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001415}
1416
1417private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001418 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001419 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001420 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001421 f_sleep(0.5);
1422
1423 /* Transmit RACH request + wait for confirmation */
1424 var OCT1 ra := f_rnd_ra_cs();
1425 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1426
1427 /* Check for expected result */
1428 timer T := 1.5;
1429 T.start;
1430 alt {
1431 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1432 setverdict(pass);
1433 }
1434 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001436 }
1437 [] RSL_CCHAN.receive { repeat; }
1438 [not expect_pass] T.timeout {
1439 setverdict(pass);
1440 }
1441 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001442 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001443 }
1444 }
1445}
1446
1447/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1448testcase TC_rach_max_ta() runs on test_CT {
1449 f_init(testcasename());
1450 f_init_l1ctl();
1451 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001452 f_sleep(1.0);
1453
1454 /* default max-ta is 63 (full range of GSM timing advance */
1455
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001456 /* We allow early arrival up to 2 symbols */
1457 f_rach_toffs(-1*256, true);
1458 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001459 f_rach_toffs(-10*256, false);
1460
1461 /* 0 / 32 / 63 bits is legal / permitted */
1462 f_rach_toffs(0, true);
1463 f_rach_toffs(32*256, true);
1464 f_rach_toffs(63*256, true);
1465
1466 /* more than 63 bits is not legal / permitted */
1467 f_rach_toffs(64*256, false);
1468 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001469 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001470}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001471
Harald Welte93640c62018-02-25 16:59:33 +01001472/***********************************************************************
1473 * Measurement Processing / Reporting
1474 ***********************************************************************/
1475
Harald Welte70767382018-02-21 12:16:40 +01001476template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1477 spare := '0'B,
1478 lpd := 0,
1479 sapi := sapi,
1480 c_r := c_r,
1481 ea := true
1482}
1483
Harald Welted879bd92018-03-12 15:01:23 +01001484template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001485 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001486 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001487 len := 0, /* overwritten */
1488 m := false,
1489 el := 1,
1490 payload := pl
1491}
1492
1493/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1494altstep as_l1_sacch() runs on ConnHdlr {
1495 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001496 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001497 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001498 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 +01001499 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001500 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001501
1502 var L1ctlDataReq data_req := {
1503 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
1504 l2_payload := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O)
1505 }
1506 log("Sending Measurement Report: ", data_req);
1507 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), data_req));
Harald Welte70767382018-02-21 12:16:40 +01001508 repeat;
1509 }
1510}
1511
1512altstep as_l1_dcch() runs on ConnHdlr {
1513 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001514 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001515 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1516 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001517 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1518 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001519 repeat;
1520 }
1521}
1522
1523type record MeasElem {
1524 uint6_t rxlev,
1525 uint3_t rxqual
1526}
1527
1528type record MeasElemFS {
1529 MeasElem full,
1530 MeasElem sub
1531}
1532
1533type record ConnL1Pars {
1534 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001535 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001536 MeasElemFS meas_ul,
1537 int16_t timing_offset_256syms,
1538 uint5_t bs_power_level,
1539 uint5_t ms_power_level,
1540 uint8_t ms_actual_ta
1541}
1542
1543/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1544private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1545 return 63 + (toffs256s/256);
1546}
1547
Harald Welted5684392018-03-10 18:22:04 +01001548private function f_max(integer a, integer b) return integer {
1549 if (a > b) {
1550 return a;
1551 } else {
1552 return b;
1553 }
1554}
1555
1556private function f_min(integer a, integer b) return integer {
1557 if (a < b) {
1558 return a;
1559 } else {
1560 return b;
1561 }
1562}
1563
1564/* compute negative tolerance val-tolerance, ensure >= min */
1565private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1566 val := val - tolerance;
1567 return f_max(val, min);
1568}
1569
1570/* compute positive tolerance val+tolerance, ensure <= max */
1571private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1572 val := val + tolerance;
1573 return f_min(val, max);
1574}
1575
1576/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1577private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1578return template integer {
1579 var template integer ret;
1580 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1581 return ret;
1582}
1583
1584
Harald Welte70767382018-02-21 12:16:40 +01001585/* build a template for matching measurement results against */
1586private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1587 var ConnL1Pars l1p := g_pars.l1_pars;
1588 var template RSL_IE_UplinkMeas ul_meas := {
1589 len := 3,
1590 rfu := '0'B,
1591 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001592 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001593 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001594 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001595 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001596 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1597 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001598 supp_meas_info := omit
1599 };
Harald Welte685d5982018-02-27 20:42:05 +01001600 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001601 ul_meas.len := (3+8);
1602 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001603 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001604 toa256_min := ?,
1605 toa256_max := ?,
1606 toa256_std_dev := ?
1607 }
Harald Welte685d5982018-02-27 20:42:05 +01001608 }
Harald Welte70767382018-02-21 12:16:40 +01001609 var template RSL_IE_BS_Power bs_power := {
1610 reserved := 0,
1611 epc := false,
1612 fpc := false,
1613 power_level := l1p.bs_power_level
1614 };
1615 var template RSL_IE_L1Info l1_info := {
1616 ms_power_lvl := l1p.ms_power_level,
1617 fpc := false,
1618 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001619 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001620 };
1621 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001622 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001623 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1624 ?, t_toffs);
1625}
1626
1627/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001628altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001629 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001630 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001631 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1632 /* increment counter of next to-be-expected meas rep */
1633 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1634 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001635 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001636 repeat;
1637 }
1638 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001639 /* increment counter of next to-be-expected meas rep */
1640 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1641 if (g_first_meas_res) {
1642 g_first_meas_res := false;
1643 repeat;
1644 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001645 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001646 }
Harald Welte70767382018-02-21 12:16:40 +01001647 }
1648 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001649 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001650 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001651 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001652 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001653 }
1654}
1655
Harald Weltee613f962018-04-18 22:38:16 +02001656private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1657 select (rsl_alg_id) {
1658 case (RSL_ALG_ID_A5_0) { return 0; }
1659 case (RSL_ALG_ID_A5_1) { return 1; }
1660 case (RSL_ALG_ID_A5_2) { return 2; }
1661 case (RSL_ALG_ID_A5_3) { return 3; }
1662 case (RSL_ALG_ID_A5_4) { return 4; }
1663 case (RSL_ALG_ID_A5_5) { return 5; }
1664 case (RSL_ALG_ID_A5_6) { return 6; }
1665 case (RSL_ALG_ID_A5_7) { return 7; }
1666 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1668 /* Make compiler happy by calling mtc.stop here. It is already
1669 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001670 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001671 }
1672 }
1673}
1674
1675private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1676 select (rsl_alg_id) {
1677 case (RSL_ALG_ID_A5_1) { return '000'B; }
1678 case (RSL_ALG_ID_A5_2) { return '001'B; }
1679 case (RSL_ALG_ID_A5_3) { return '010'B; }
1680 case (RSL_ALG_ID_A5_4) { return '011'B; }
1681 case (RSL_ALG_ID_A5_5) { return '100'B; }
1682 case (RSL_ALG_ID_A5_6) { return '101'B; }
1683 case (RSL_ALG_ID_A5_7) { return '110'B; }
1684 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001685 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1686 /* Make compiler happy by calling mtc.stop here. It is already
1687 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001688 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001689 }
1690 }
1691}
1692
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001693/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1694private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1695 var GsmFrameNumber fn;
1696 timer T := 8.0;
1697
1698 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1699 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1700
1701 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1702 /* Send the actual RACH */
1703 fn := f_L1CTL_RACH(L1CTL, ra);
1704
1705 T.start;
1706 alt {
1707 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1708 [] T.timeout {
1709 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1710 }
1711 }
1712 T.stop
1713 return fn;
1714}
Harald Weltee613f962018-04-18 22:38:16 +02001715
Harald Welte70767382018-02-21 12:16:40 +01001716/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001717private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001718 var GsmFrameNumber fn;
1719 var ImmediateAssignment imm_ass;
1720 var integer ra := 23;
1721
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001722 /* Send RACH request and wait for ChanReq */
1723 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001724
1725 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001726 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001727
1728 /* Send IMM.ASS via CCHAN */
1729 var ChannelDescription ch_desc := {
1730 chan_nr := g_pars.chan_nr,
1731 tsc := 7,
1732 h := false,
1733 arfcn := mp_trx0_arfcn,
1734 maio_hsn := omit
1735 };
1736 var MobileAllocation ma := {
1737 len := 0,
1738 ma := ''B
1739 };
1740 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1741 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1742
1743 /* receive IMM.ASS on MS side */
1744 var ImmediateAssignment ia_um;
1745 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1746 /* enable dedicated mode */
1747 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001748 /* enable encryption, if requested */
1749 if (encr_enable) {
1750 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1751 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1752 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001753
1754 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001755}
1756
1757/* establish DChan, verify existance + contents of measurement reports */
1758function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001759 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001760 RSL.clear;
1761
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001762 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001763 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001764 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1765 }
Harald Welte70767382018-02-21 12:16:40 +01001766
1767 f_est_dchan();
1768
1769 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1770 * RSL measurement reports on Abis side */
1771 timer T := 8.0;
1772 T.start;
1773 alt {
1774 [] as_l1_sacch();
1775 [] as_meas_res();
1776 [] as_l1_dcch();
1777 [] L1CTL.receive { repeat; }
1778 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001779 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001780 * of any earlier errors, so if we reach this timeout, we're good */
1781 setverdict(pass);
1782 }
1783 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001785 }
1786 }
1787 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001788 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001789}
Harald Welte0472ab42018-03-12 15:02:26 +01001790
Harald Welte70767382018-02-21 12:16:40 +01001791testcase TC_meas_res_sign_tchf() runs on test_CT {
1792 var ConnHdlr vc_conn;
1793 var ConnHdlrPars pars;
1794 f_init(testcasename());
1795 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1796 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1797 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1798 vc_conn.done;
1799 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001800 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001801}
1802testcase TC_meas_res_sign_tchh() runs on test_CT {
1803 var ConnHdlr vc_conn;
1804 var ConnHdlrPars pars;
1805 f_init(testcasename());
1806 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1807 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1808 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1809 vc_conn.done;
1810 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001811 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001812}
1813testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1814 var ConnHdlr vc_conn;
1815 var ConnHdlrPars pars;
1816 f_init(testcasename());
1817 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1818 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1819 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1820 vc_conn.done;
1821 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001822 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001823}
1824testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1825 var ConnHdlr vc_conn;
1826 var ConnHdlrPars pars;
1827 f_init(testcasename());
1828 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1829 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1830 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1831 vc_conn.done;
1832 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001834}
Harald Welte685d5982018-02-27 20:42:05 +01001835testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1836 var ConnHdlr vc_conn;
1837 var ConnHdlrPars pars;
1838 f_init(testcasename());
1839 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1840 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1841 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1842 pars.l1_pars.toa256_enabled := true;
1843 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1844 vc_conn.done;
1845 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001846 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001847}
1848
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001849/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1850 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1851function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1852 var L1ctlDlMessage l1_dl;
1853 var RSL_IE_MS_Power ms_power;
1854 var RSL_Message rsl;
1855 var uint5_t power_level := 0;
1856
1857 f_l1_tune(L1CTL);
1858 RSL.clear;
1859
1860 f_est_dchan();
1861
1862 ms_power.reserved := 0;
1863 ms_power.fpc_epc := false;
1864
1865 /* Send the first power control command. This will disable any BTS/TRX
1866 * internal power control and switch the MS (which is not in scope of
1867 * this test) to a constant power level. We start with a power level
1868 * of 0 */
1869 ms_power.power_level := power_level;
1870 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1871 RSL.send(rsl);
1872
1873 alt {
1874
1875 /* Pick all SACCH blocks for checking */
1876 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1877
1878 /* The first byte of the L1 header contains the power level.
1879 * The reserved bits and the fpc bit is set to 0, so we may
1880 * compare directly. */
1881 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1882 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1883 }
1884
1885 /* Signal a new power level via RSL for the next turn. */
1886 if (power_level < 31) {
1887 power_level := power_level + 1;
1888 ms_power.power_level := power_level;
1889 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1890 RSL.send(rsl);
1891 repeat;
1892 }
1893
1894 }
1895
1896 /* Ignore all other blocks */
1897 [] L1CTL.receive { repeat; }
1898
1899 }
1900
1901 f_rsl_chan_deact();
1902 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1903
1904 setverdict(pass);
1905}
1906
1907testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
1908 var ConnHdlr vc_conn;
1909 var ConnHdlrPars pars;
1910 f_init(testcasename());
1911
1912 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1913 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1914 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
1915 vc_conn.done;
1916 }
1917 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1918}
Harald Welte70767382018-02-21 12:16:40 +01001919
Eric Wild6833cc92019-05-23 19:34:44 +02001920/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
1921TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
1922function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
1923 var L1ctlDlMessage l1_dl;
1924 var uint5_t ta_to_test := 16;
1925
1926
1927 f_l1_tune(L1CTL);
1928 RSL.clear;
1929
1930 /* tell fake_trx to use a given timing offset for all bursts */
1931 f_trx_fake_toffs256(ta_to_test*256);
1932
1933 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
1934
1935
1936 alt {
1937
1938 /* Pick all SACCH blocks for checking */
1939 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1940
1941 /* The second byte of the L1 header contains the TA. */
1942 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
1943 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
1944 }
1945
1946 }
1947
1948 /* Ignore all other blocks */
1949 [] L1CTL.receive { repeat; }
1950
1951 }
1952
1953 f_rsl_chan_deact();
1954 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1955
1956 setverdict(pass);
1957}
1958
1959testcase TC_rsl_chan_initial_ta() runs on test_CT {
1960 var ConnHdlr vc_conn;
1961 var ConnHdlrPars pars;
1962 f_init(testcasename());
1963 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1964 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars);
1965 vc_conn.done;
1966 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1967}
1968
Harald Welte0472ab42018-03-12 15:02:26 +01001969/* 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 +01001970private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001971 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001972 RSL.clear;
1973
1974 f_est_dchan();
1975 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001976 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001977
1978 timer T := 40.0;
1979 T.start;
1980 alt {
1981 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
1982 setverdict(pass)
1983 }
1984 [] RSL.receive { repeat };
1985 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01001987 }
1988 }
1989 f_rsl_chan_deact();
1990}
1991testcase TC_conn_fail_crit() runs on test_CT {
1992 var ConnHdlr vc_conn;
1993 var ConnHdlrPars pars;
1994 f_init(testcasename());
1995 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
1996 pars.t_guard := 60.0;
1997 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
1998 vc_conn.done;
1999}
2000
Harald Welte93640c62018-02-25 16:59:33 +01002001/***********************************************************************
2002 * Paging
2003 ***********************************************************************/
2004
Harald Welte68e495b2018-02-25 00:05:57 +01002005function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2006 if (tmsi == 'FFFFFFFF'O) {
2007 return true;
2008 } else {
2009 return false;
2010 }
2011}
Harald Welte70767382018-02-21 12:16:40 +01002012
Philipp Maier82cb0b12018-08-31 14:41:39 +02002013type record allowedFn { integer frame_nr }
2014template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2015template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2016template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2017template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2018template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2019template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2020template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2021template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2022function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2023{
2024 var integer frame_nr_51;
2025 frame_nr_51 := frame_nr mod 51
2026
2027 var allowedFn fn_check;
2028 fn_check.frame_nr := frame_nr_51;
2029
2030 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002031 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002032 return;
2033 }
2034
2035 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2036 return;
2037 }
2038 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2039 return;
2040 }
2041 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2042 return;
2043 }
2044 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2045 return;
2046 }
2047 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2048 return;
2049 }
2050 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2051 return;
2052 }
2053 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2054 return;
2055 }
2056 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2057 return;
2058 }
2059
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002061 return;
2062}
2063
2064altstep 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 +01002065runs on test_CT {
2066 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002067 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002068 repeat;
2069 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002070 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002071 var octetstring without_plen :=
2072 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2073 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002074
2075 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2076
Harald Welte68e495b2018-02-25 00:05:57 +01002077 if (match(rr, tr_PAGING_REQ1)) {
2078 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2079 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2080 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2081 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2082 }
2083 } else if (match(rr, tr_PAGING_REQ2)) {
2084 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2085 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2086 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2087 }
2088 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2089 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2090 }
2091 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2092 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2093 }
2094 } else if (match(rr, tr_PAGING_REQ3)) {
2095 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2096 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2097 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2098 }
2099 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2100 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2101 }
2102 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2103 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2104 }
2105 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2106 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2107 }
2108 }
2109 repeat;
2110 }
2111}
2112
2113type record PagingTestCfg {
2114 boolean combined_ccch,
2115 integer bs_ag_blks_res,
2116 float load_factor,
2117 boolean exp_load_ind,
2118 boolean exp_overload,
2119 boolean use_tmsi
2120}
2121
2122type record PagingTestState {
2123 integer num_paging_sent,
2124 integer num_paging_rcv_msgs,
2125 integer num_paging_rcv_ids,
2126 integer num_overload
2127}
2128
2129/* receive + ignore RSL RF RES IND */
2130altstep as_rsl_res_ind() runs on test_CT {
2131 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2132 repeat;
2133 }
2134}
2135
2136/* Helper function for paging related testing */
2137private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
2138 f_init(testcasename());
2139 f_init_l1ctl();
2140 f_l1_tune(L1CTL);
2141
2142 var PagingTestState st := {
2143 num_paging_sent := 0,
2144 num_paging_rcv_msgs := 0,
2145 num_paging_rcv_ids := 0,
2146 num_overload := 0
2147 };
2148
2149 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2150 var float max_pch_imsi_per_sec;
2151 if (cfg.use_tmsi) {
2152 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2153 } else {
2154 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2155 }
2156 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2157 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002158 var float time_total := 20.0;
2159 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2160 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002161
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002162 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2163 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002164
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002165 timer T_itv := 0.0;
2166 T_itv.start;
2167 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002168 alt {
2169 /* check for presence of CCCH LOAD IND (paging load) */
2170 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2171 st.num_overload := st.num_overload + 1;
2172 repeat;
2173 }
2174 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002175 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002176 }
2177 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2178 log("Rx LOAD_IND");
2179 /* FIXME: analyze/verify interval + contents */
2180 repeat;
2181 }
2182 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002183 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002184 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002185 [] T_itv.timeout {
2186 /* Send paging cmds based on elapsed time */
2187 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2188 while (st.num_paging_sent < new_sent) {
2189 /* build mobile Identity */
2190 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2191 if (cfg.use_tmsi) {
2192 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2193 } else {
2194 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2195 }
2196 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2197 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2198
2199 /* Send RSL PAGING COMMAND */
2200 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2201
2202 st.num_paging_sent := st.num_paging_sent + 1;
2203 }
2204 if (st.num_paging_sent < pkt_total) {
2205 /* Wait for interval to next PAGING COMMAND */
2206 var float time_now := T_total.read;
2207 var float next_sched := int2float(st.num_paging_sent)*interval;
2208 if (next_sched > time_now) {
2209 T_itv.start(next_sched - time_now);
2210 } else {
2211 T_itv.start(0.0);
2212 }
2213 } else {
2214 /* We are done, no need to keep counting */
2215 T_total.stop;
2216 }
2217 }
2218 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002219 [] as_rsl_res_ind();
2220 }
2221 }
2222
2223 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2224 timer T_wait := 18.0;
2225 T_wait.start;
2226 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002227 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002228 [] L1CTL.receive { repeat; }
2229 /* 65535 == empty paging queue, we can terminate*/
2230 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2231 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2232 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002233 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002234 }
2235 [] as_rsl_res_ind();
2236 }
2237
2238 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2239 " rcvd_ids=", st.num_paging_rcv_ids);
2240 return st;
2241}
2242
2243/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2244 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2245 * - that CCCH LOAD IND (PCH) are being generated
2246 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2247testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002248 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002249 var PagingTestCfg cfg := {
2250 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002251 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002252 load_factor := 0.8,
2253 exp_load_ind := true,
2254 exp_overload := false,
2255 use_tmsi := false
2256 };
2257 var PagingTestState st := f_TC_paging(cfg);
2258 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002259 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2260 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002261 } else {
2262 setverdict(pass);
2263 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002264 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002265}
2266
2267/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2268 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2269 * - that CCCH LOAD IND (PCH) are being generated
2270 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2271testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002272 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002273 var PagingTestCfg cfg := {
2274 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002275 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002276 load_factor := 0.8,
2277 exp_load_ind := true,
2278 exp_overload := false,
2279 use_tmsi := true
2280 };
2281 var PagingTestState st := f_TC_paging(cfg);
2282 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2284 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002285 } else {
2286 setverdict(pass);
2287 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002288 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002289}
2290
2291/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2292 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2293 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2294 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2295testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002296 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002297 var PagingTestCfg cfg := {
2298 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002299 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002300 load_factor := 2.0,
2301 exp_load_ind := true,
2302 exp_overload := true,
2303 use_tmsi := false
2304 };
2305 var PagingTestState st := f_TC_paging(cfg);
2306 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2307 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002308 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002309 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002310 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 +01002311 } else {
2312 setverdict(pass);
2313 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002314 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002315}
2316
2317/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2318 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2319 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2320 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2321testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002322 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002323 var PagingTestCfg cfg := {
2324 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002325 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002326 load_factor := 2.0,
2327 exp_load_ind := true,
2328 exp_overload := true,
2329 use_tmsi := true
2330 };
2331 var PagingTestState st := f_TC_paging(cfg);
2332 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2333 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002334 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002335 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002336 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 +01002337 } else {
2338 setverdict(pass);
2339 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002340 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002341}
2342
2343
Harald Welte93640c62018-02-25 16:59:33 +01002344/***********************************************************************
2345 * Immediate Assignment / AGCH
2346 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002347const MobileAllocation c_MA_null := {
2348 len := 0,
2349 ma := ''B
2350}
Harald Welte93640c62018-02-25 16:59:33 +01002351
Harald Weltee8d750e2018-06-10 21:41:35 +02002352template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2353 uint12_t arfcn := 871) := {
2354 chan_nr := chan_nr,
2355 tsc := tsc,
2356 h := false,
2357 arfcn := arfcn,
2358 maio_hsn := omit
2359}
2360
2361private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2362 return int2str(num_tx) & " sent, "
2363 & int2str(num_rx) & " received, "
2364 & int2str(num_del) & " deleted";
2365}
2366
2367private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2368 var L1ctlDlMessage l1_dl;
2369 timer T := 10.0;
2370 var integer num_tx := 0;
2371 var integer num_rx := 0;
2372 var integer num_del := 0;
2373 var charstring res_str;
2374 var float rx_ratio;
2375
Harald Welte68e495b2018-02-25 00:05:57 +01002376 f_init(testcasename());
Harald Weltee8d750e2018-06-10 21:41:35 +02002377 f_init_l1ctl();
2378 f_l1_tune(L1CTL);
2379
2380 for (var integer i := 0; i < num_total; i := i+1) {
2381 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2382 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2383 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002384 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002385 num_tx := num_tx+1;
2386 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002387 }
2388 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002389 T.start;
2390 alt {
2391 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2392 num_del := num_del+1;
2393 repeat;
2394 }
2395 [] RSL_CCHAN.receive {
2396 repeat;
2397 }
2398 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2399 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2400 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2401 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2402 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002403 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002404 } else {
2405 num_rx := num_rx+1;
2406 }
2407 repeat;
2408 }
2409 [] L1CTL.receive { repeat; }
2410 [] T.timeout { }
2411 }
2412 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2413 log("AGCH test: " & res_str);
2414 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002415 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002416 }
2417 rx_ratio := int2float(num_rx) / int2float(num_tx);
2418 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002419 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 +02002420 } else {
2421 setverdict(pass);
2422 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002424}
2425
Harald Weltee8d750e2018-06-10 21:41:35 +02002426/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2427testcase TC_imm_ass_1000_20ms() runs on test_CT {
2428 f_TC_imm_ass(1000, 0.02, 0.25);
2429}
2430
2431/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2432testcase TC_imm_ass_200_0ms() runs on test_CT {
2433 f_TC_imm_ass(200, 0.0, 0.05);
2434}
2435
2436/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2437testcase TC_imm_ass_200_76ms() runs on test_CT {
2438 f_TC_imm_ass(150, 0.076, 1.00);
2439}
2440
2441
2442
Harald Welte48494ca2018-02-25 16:59:50 +01002443/***********************************************************************
2444 * BCCH
2445 ***********************************************************************/
2446
2447/* tuple of Frame Number + decoded SI */
2448type record SystemInformationFn {
2449 GsmFrameNumber frame_number,
2450 SystemInformation si
2451}
2452
2453/* an arbitrary-length vector of decoded SI + gsmtap header */
2454type record of SystemInformationFn SystemInformationVector;
2455
2456/* an array of SI-vectors indexed by TC value */
2457type SystemInformationVector SystemInformationVectorPerTc[8];
2458
2459/* determine if a given SI vector contains given SI type at least once */
2460function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2461 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2462 var integer fn_mod51 := arr[i].frame_number mod 51;
2463 if (not bcch_ext and fn_mod51 == 2 or
2464 bcch_ext and fn_mod51 == 6) {
2465 if (arr[i].si.header.message_type == key) {
2466 return true;
2467 }
2468 }
2469 }
2470 return false;
2471}
2472
2473/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2474function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2475 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002477 }
2478}
2479
2480/* check if a given SI vector contains given SI type at least once on any TC */
2481function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2482 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2483 if (f_si_vecslot_contains(arr[tc], key) or
2484 f_si_vecslot_contains(arr[tc], key, true)) {
2485 return true;
2486 }
2487 }
2488 return false;
2489}
2490
2491/* determine if a given SI vector contains given SI type at least N of M times */
2492function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2493 var integer count := 0;
2494 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002496 }
2497 for (var integer i:= 0; i < m; i := i + 1) {
2498 var integer fn_mod51 := arr[i].frame_number mod 51;
2499 if (not bcch_ext and fn_mod51 == 2 or
2500 bcch_ext and fn_mod51 == 6) {
2501 if (arr[i].si.header.message_type == key) {
2502 count := count + 1;
2503 }
2504 }
2505 }
2506 if (count >= n) {
2507 return true;
2508 } else {
2509 return false;
2510 }
2511}
2512
2513/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2514function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2515 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002516 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002517 }
2518}
2519
2520/* determine if a given SI vector contains given SI type at least once */
2521function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2522 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2523 var integer fn_mod51 := arr[i].frame_number mod 51;
2524 if (not bcch_ext and fn_mod51 == 2 or
2525 bcch_ext and fn_mod51 == 6) {
2526 if (arr[i].si.header.message_type != key) {
2527 return false;
2528 }
2529 }
2530 }
2531 return true;
2532}
2533
2534/* ensure a given TC slot of the SI vector contains only given SI type */
2535function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2536 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002538 }
2539}
2540
2541/* SI configuration of cell, against which we validate actual SI messages */
2542type set SystemInformationConfig {
2543 boolean bcch_extended,
2544 boolean si1_present,
2545 boolean si2bis_present,
2546 boolean si2ter_present,
2547 boolean si2quater_present,
2548 boolean si7_present,
2549 boolean si8_present,
2550 boolean si9_present,
2551 boolean si13_present,
2552 boolean si13alt_present,
2553 boolean si15_present,
2554 boolean si16_present,
2555 boolean si17_present,
2556 boolean si2n_present,
2557 boolean si21_present,
2558 boolean si22_present
2559}
2560
2561/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2562function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2563 var integer i;
2564 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2565 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002567 }
2568 }
2569 if (cfg.si1_present) {
2570 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2571 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2572 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2573 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2574 /* make sure *ALL* contain SI1 */
2575 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2576 }
2577 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2578 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2579 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2580 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2581 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2582 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2583
2584 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2585 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2586 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2587 * consecutive occurrences of TC = 4. */
2588 if (cfg.si2bis_present and not cfg.si2ter_present) {
2589 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2590 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2591 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2592 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2593 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2594 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2595 }
2596
2597 if (cfg.si7_present or cfg.si8_present) {
2598 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2599 * if System Information type 4 does not contain all information needed for cell
2600 * selection and reselection. */
2601 if (not cfg.bcch_extended) {
2602 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2603 }
2604 if (cfg.si7_present) {
2605 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2606 }
2607 if (cfg.si8_present) {
2608 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2609 }
2610 }
2611
2612 if (cfg.si2quater_present) {
2613 /* iii) System information type 2 quater is sent if needed, as determined by the system
2614 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2615 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2616 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2617 * within any of 4 consecutive occurrences of TC = 5. */
2618 if (not (cfg.bcch_extended)) {
2619 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2620 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2621 } else {
2622 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2623 }
2624 } else {
2625 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2626 }
2627 }
2628 if (cfg.si9_present) {
2629 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2630 * in system information type 3 as defined in 3GPP TS 44.018. */
2631 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2632 }
2633 if (cfg.si13_present) {
2634 /* vii) System Information type 13 is only related to the GPRS service. System Information
2635 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2636 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2637 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2638 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2639 * within any of 4 consecutive occurrences of TC=4. */
2640 if (not cfg.bcch_extended) {
2641 log("not-bccch-extended");
2642 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2643 } else {
2644 log("bccch-extended");
2645 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2646 }
2647 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002649 }
2650 }
2651 if (cfg.si16_present or cfg.si17_present) {
2652 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2653 * should not be sent in a cell where network sharing is used (see rule xv). */
2654 if (cfg.si22_present) {
2655 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2656 }
2657 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002658 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002659 }
2660 if (not cfg.bcch_extended) {
2661 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2662 }
2663 if (cfg.si16_present) {
2664 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2665 }
2666 if (cfg.si17_present) {
2667 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2668 }
2669 }
2670
2671 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2672 * broadcast information. The frequency with which they are sent is determined by the
2673 * system operator. System Information type 9 identifies the scheduling of System
2674 * Information type 18 and 20 messages. */
2675
2676 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2677 * Information Type 19 is present, then its scheduling shall be indicated in System
2678 * Information Type 9. */
2679
2680 if (cfg.si15_present) {
2681 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2682 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2683 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2684 * 4 consecutive occurrences of TC = 1. */
2685 if (not cfg.bcch_extended) {
2686 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2687 } else {
2688 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2689 }
2690 }
2691 if (cfg.si13alt_present) {
2692 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2693 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2694 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2695 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2696 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2697 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2698 * of TC = 4. */
2699 if (cfg.si13_present) {
2700 testcase.stop("Error: Cannot have SI13alt and SI13");
2701 }
2702 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002703 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002704 }
2705 if (not cfg.bcch_extended) {
2706 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2707 } else {
2708 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2709 }
2710 }
2711 if (cfg.si2n_present) {
2712 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2713 * as determined by the system operator. In the case that the message is sent on the
2714 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2715 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2716 * consecutive occurrences of TC = 4. */
2717 if (not cfg.bcch_extended) {
2718 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2719 } else {
2720 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2721 }
2722 }
2723 if (cfg.si21_present) {
2724 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2725 * determined by the system operator. If Extended Access Barring is in use in the cell
2726 * then this message is sent at least once within any of 4 consecutive occurrences of
2727 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2728 * cell then this message shall only be sent on BCCH Ext. */
2729 if (not cfg.bcch_extended) {
2730 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2731 } else {
2732 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2733 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002734 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002735 }
2736 }
2737 }
2738 if (cfg.si22_present) {
2739 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2740 * should not be sent in a cell where SoLSA is used (see rule viii). System
2741 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2742 * =2 and TC=6. */
2743 if (cfg.si16_present or cfg.si17_present) {
2744 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2745 }
2746 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2747 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002748 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002749 }
2750 if (not cfg.bcch_extended) {
2751 testcase.stop("Error: SI22 requires BCCH Extd!");
2752 } else {
2753 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2754 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2755 }
2756 }
2757}
2758
2759/* sample Systme Information for specified duration via L1CTL */
2760function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2761 timer T := duration;
2762 var SystemInformationVectorPerTc si_per_tc;
2763 var L1ctlDlMessage l1_dl;
2764
2765 /* initialize all per-TC vectors empty */
2766 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2767 si_per_tc[i] := {};
2768 }
2769
2770 /* flush all previous L1 queued msgs */
2771 pt.clear;
2772
2773 T.start;
2774 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002775 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002776 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2777 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2778 log("Ignoring non-RR SI ", l1_dl);
2779 repeat;
2780 }
2781 var SystemInformationFn sig := {
2782 frame_number := l1_dl.dl_info.frame_nr,
2783 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2784 }
2785 var integer tc := f_gsm_compute_tc(sig.frame_number);
2786 log("SI received at TC=", tc, ": ", sig.si);
2787 /* append to the per-TC bucket */
2788 si_per_tc[tc] := si_per_tc[tc] & { sig };
2789 repeat;
2790 }
2791 [] pt.receive { repeat; }
2792 [] T.timeout { }
2793 }
2794
2795 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2796 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2797 }
2798 log("si_per_tc=", si_per_tc);
2799 return si_per_tc;
2800}
2801
2802/* helper function: Set given SI via RSL + validate scheduling.
2803 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2804function f_TC_si_sched() runs on test_CT {
2805 var SystemInformationVectorPerTc si_per_tc;
2806 f_init_l1ctl();
2807 f_l1_tune(L1CTL);
2808
2809 /* Sample + Validate Scheduling */
2810 si_per_tc := f_l1_sample_si(L1CTL);
2811 f_validate_si_scheduling(si_cfg, si_per_tc);
2812
2813 setverdict(pass);
2814}
2815
2816testcase TC_si_sched_default() runs on test_CT {
2817 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002818 /* 2+3+4 are mandatory and set in f_init() */
2819 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002820 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002821}
2822
2823testcase TC_si_sched_1() runs on test_CT {
2824 f_init();
2825 si_cfg.si1_present := true;
2826 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002827 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002828 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002829}
2830
2831testcase TC_si_sched_2bis() runs on test_CT {
2832 f_init();
2833 si_cfg.si2bis_present := true;
2834 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2835 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002836 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002837}
2838
2839testcase TC_si_sched_2ter() runs on test_CT {
2840 f_init();
2841 si_cfg.si2ter_present := true;
2842 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2843 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002844 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002845}
2846
2847testcase TC_si_sched_2ter_2bis() runs on test_CT {
2848 f_init();
2849 si_cfg.si2bis_present := true;
2850 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2851 si_cfg.si2ter_present := true;
2852 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2853 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002854 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002855}
2856
2857testcase TC_si_sched_2quater() runs on test_CT {
2858 f_init();
2859 si_cfg.si2quater_present := true;
2860 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2861 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002862 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002863}
2864
2865testcase TC_si_sched_13() runs on test_CT {
2866 f_init();
2867 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002868 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002869 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002870 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002871}
2872
2873testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2874 f_init();
2875 si_cfg.si2bis_present := true;
2876 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2877 si_cfg.si2ter_present := true;
2878 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2879 si_cfg.si2quater_present := true;
2880 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2881 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002882 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002883 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002884 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002885}
2886
2887
Harald Welte68e495b2018-02-25 00:05:57 +01002888testcase TC_bcch_info() runs on test_CT {
2889 f_init(testcasename());
2890 /* FIXME: enable / disable individual BCCH info */
2891 //ts_RSL_BCCH_INFO(si_type, info);
2892 /* expect no ERROR REPORT after either of them *
2893 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002894 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002895}
2896
Harald Welte93640c62018-02-25 16:59:33 +01002897/***********************************************************************
2898 * Low-Level Protocol Errors / ERROR REPORT
2899 ***********************************************************************/
2900
Harald Welte01d982c2018-02-25 01:31:40 +01002901private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2902 timer T := 5.0;
2903 T.start;
2904 alt {
2905 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2906 setverdict(pass);
2907 }
2908 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002909 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002910 }
2911 [] RSL_CCHAN.receive {
2912 repeat;
2913 }
2914 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01002916 }
2917 }
2918}
2919
2920/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2921testcase TC_rsl_protocol_error() runs on test_CT {
2922 f_init(testcasename());
2923 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2924 rsl.ies := omit;
2925 RSL_CCHAN.send(ts_RSL_UD(rsl));
2926
2927 f_exp_err_rep(RSL_ERR_PROTO);
2928}
2929
2930/* Provoke a mandatory IE error and match on ERROR REPORT */
2931testcase TC_rsl_mand_ie_error() runs on test_CT {
2932 f_init(testcasename());
2933
2934 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2935 rsl.ies := { rsl.ies[0] };
2936 RSL_CCHAN.send(ts_RSL_UD(rsl));
2937
2938 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2939}
2940
2941/* Provoke an IE content error and match on ERROR REPORT */
2942testcase TC_rsl_ie_content_error() runs on test_CT {
2943 f_init(testcasename());
2944 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2945 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2946 RSL_CCHAN.send(ts_RSL_UD(rsl));
2947
2948 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2949}
2950
Harald Welteee25aae2019-05-19 14:32:37 +02002951/* attempt to activate channel with wrong RSL Message Discriminator IE */
2952function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
2953 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2954 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
2955 RSL.send(rsl);
2956 f_rslem_unregister(0, g_chan_nr);
2957}
2958testcase TC_err_rep_wrong_mdisc() runs on test_CT {
2959 var ConnHdlr vc_conn;
2960 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
2961
2962 f_init(testcasename());
2963
2964 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
2965 vc_conn.done;
2966 f_exp_err_rep(RSL_ERR_MSG_DISCR);
2967
2968 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2969}
2970
2971/* Send messages with wrong message type */
2972function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
2973 var template (value) RSL_Message rsl_tx;
2974 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
2975 rsl_tx.msg_type := RSL_MT_NOT_CMD;
2976 RSL.send(rsl_tx);
2977 f_rslem_unregister(0, g_chan_nr);
2978}
2979function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
2980 var template (value) RSL_Message rsl_tx;
2981 /* we first have to activate the dedicated channel */
2982 f_rsl_chan_act(g_pars.chan_mode);
2983 /* ... to then send an invalid RLL message */
2984 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
2985 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
2986 RSL.send(rsl_tx);
2987 f_rslem_unregister(0, g_chan_nr);
2988}
2989testcase TC_err_rep_wrong_msg_type() runs on test_CT {
2990 var ConnHdlr vc_conn;
2991 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
2992 var template (value) RSL_Message rsl_tx;
2993
2994 f_init(testcasename());
2995
2996 /* Common Channel with wrong message type */
2997 RSL_CCHAN.clear;
2998 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2999 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3000 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3001 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3002
3003 /* TRX Management */
3004 RSL_CCHAN.clear;
3005 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3006 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3007 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3008 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3009
3010 /* Dedicated Channel */
3011 RSL_CCHAN.clear;
3012 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3013 vc_conn.done;
3014 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3015
3016 /* RLL */
3017 RSL_CCHAN.clear;
3018 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3019 vc_conn.done;
3020 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3021}
3022
3023/* Send messages in wrong sequence (RLL to an inactive lchan) */
3024function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3025 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3026 f_rslem_unregister(0, g_chan_nr);
3027}
3028testcase TC_err_rep_wrong_sequence() runs on test_CT {
3029 var ConnHdlr vc_conn;
3030 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3031
3032 f_init(testcasename());
3033
3034 RSL_CCHAN.clear;
3035 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3036 vc_conn.done;
3037 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3038}
3039
Harald Welte93640c62018-02-25 16:59:33 +01003040/***********************************************************************
3041 * IPA CRCX/MDCX/DLCS media stream handling
3042 ***********************************************************************/
3043
Harald Weltea871a382018-02-25 02:03:14 +01003044/* Send IPA DLCX to inactive lchan */
3045function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003046 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3047 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003048}
3049testcase TC_ipa_dlcx_not_active() runs on test_CT {
3050 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3051 f_init(testcasename());
3052 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3053 vc_conn.done;
3054}
Harald Welte68e495b2018-02-25 00:05:57 +01003055
Harald Weltea3f1df92018-02-25 12:49:55 +01003056/* Send IPA CRCX twice to inactive lchan */
3057function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3058 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3059 "IPA CRCX ACK");
3060 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3061 "IPA CRCX NACK");
3062}
3063testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3064 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3065 f_init(testcasename());
3066 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3067 vc_conn.done;
3068}
3069
3070/* Regular sequence of CRCX/MDCX/DLCX */
3071function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3072 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3073 "IPA CRCX ACK");
3074 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3075 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3076 var uint7_t rtp_pt2 := f_rnd_int(127);
3077 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3078 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3079 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3080 "IPA MDCX ACK");
3081 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3082 "IPA DLCX ACK");
3083}
3084testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3085 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3086 f_init(testcasename());
3087 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3088 vc_conn.done;
3089}
3090
Harald Welte3ae11da2018-02-25 13:36:06 +01003091/* Sequence of CRCX, 2x MDCX, DLCX */
3092function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3093 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3094 "IPA CRCX ACK");
3095 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3096 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3097 var uint7_t rtp_pt2 := f_rnd_int(127);
3098 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3099 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3100 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3101 "IPA MDCX ACK");
3102 /* Second MDCX */
3103 remote_ip := f_rnd_int(c_UINT32_MAX);
3104 remote_port := f_rnd_int(c_UINT16_MAX);
3105 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3106 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3107 "IPA MDCX ACK");
3108 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3109 "IPA DLCX ACK");
3110}
3111testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3112 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
3113 f_init(testcasename());
3114 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3115 vc_conn.done;
3116}
3117
Harald Welte9912eb52018-02-25 13:30:15 +01003118/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3119function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3120 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3121 "IPA CRCX NACK");
3122}
3123testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3124 var ConnHdlrPars pars;
3125 var ConnHdlr vc_conn;
3126 f_init(testcasename());
3127
3128 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3129 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3130 vc_conn.done;
3131
3132 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3133 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3134 vc_conn.done;
3135}
3136
Harald Weltea3f1df92018-02-25 12:49:55 +01003137
Harald Welte883340c2018-02-28 18:59:29 +01003138/***********************************************************************
3139 * PCU Socket related tests
3140 ***********************************************************************/
3141
Harald Welte07bd2d22019-05-25 11:03:30 +02003142/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003143friend 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 +01003144runs on test_CT {
3145 timer T := 3.0;
3146
3147 /* we don't expect any RTS.req before PDCH are active */
3148 T.start;
3149 alt {
3150 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003152 }
3153 [] PCU.receive { repeat; }
3154 [] T.timeout { }
3155 }
3156
3157 /* Send PDCH activate request for known PDCH timeslot */
3158 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3159
3160 /* we now expect RTS.req for this timeslot (only) */
3161 T.start;
3162 alt {
3163 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3164 setverdict(pass);
3165 }
3166 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3167 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003168 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003169 }
3170 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003171 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003172 }
3173 [] PCU.receive { repeat; }
3174 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003175 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003176 }
3177 [not exp_success] T.timeout {
3178 setverdict(pass);
3179 }
3180 }
3181}
3182
Harald Welte07bd2d22019-05-25 11:03:30 +02003183/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003184friend 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 +01003185runs on test_CT {
3186 timer T := 3.0;
3187
3188 /* Send PDCH activate request for known PDCH timeslot */
3189 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3190
3191 PCU.clear;
3192 /* we now expect no RTS.req for this timeslot */
3193 T.start;
3194 alt {
3195 [] 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 +02003196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003197 }
3198 [] PCU.receive { repeat; }
3199 [] T.timeout {
3200 setverdict(pass);
3201 }
3202 }
3203}
3204
Harald Weltead033dc2019-05-25 17:28:16 +02003205friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003206 f_init();
3207 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3208}
3209
Harald Welte883340c2018-02-28 18:59:29 +01003210/* PDCH activation via PCU socket; check for presence of RTS.req */
3211testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003212 f_init_pcu_test();
3213
Harald Welte883340c2018-02-28 18:59:29 +01003214 f_TC_pcu_act_req(0, 0, 7, true);
3215}
3216
3217/* PDCH activation via PCU socket on non-PDCU timeslot */
3218testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003219 f_init_pcu_test();
3220
Harald Welte883340c2018-02-28 18:59:29 +01003221 f_TC_pcu_act_req(0, 0, 1, false);
3222}
3223
3224/* PDCH activation via PCU socket on wrong BTS */
3225testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003226 f_init_pcu_test();
3227
Harald Welte883340c2018-02-28 18:59:29 +01003228 f_TC_pcu_act_req(23, 0, 7, false);
3229}
3230
3231/* PDCH activation via PCU socket on wrong TRX */
3232testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003233 f_init_pcu_test();
3234
Harald Welte883340c2018-02-28 18:59:29 +01003235 f_TC_pcu_act_req(0, 23, 7, false);
3236}
3237
3238/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3239testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003240 f_init_pcu_test();
3241
Harald Welte883340c2018-02-28 18:59:29 +01003242 /* Activate PDCH */
3243 f_TC_pcu_act_req(0, 0, 7, true);
3244 f_sleep(1.0);
3245 /* and De-Activate again */
3246 f_TC_pcu_deact_req(0, 0, 7);
3247}
3248
3249/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3250testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003251 f_init_pcu_test();
3252
Harald Welte883340c2018-02-28 18:59:29 +01003253 f_TC_pcu_deact_req(0, 0, 1);
3254}
3255
3256/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3257testcase TC_pcu_ver_si13() runs on test_CT {
3258 const octetstring si13 := '00010203040506070909'O;
3259 var PCUIF_send_data sd;
3260 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003261 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003262
3263 /* Set SI13 via RSL */
3264 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003265
Harald Welte883340c2018-02-28 18:59:29 +01003266 T.start;
3267 alt {
3268 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3269 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3270 setverdict(pass);
3271 } else {
3272 repeat;
3273 }
3274 }
3275 [] PCU.receive { repeat; }
3276 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003277 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003278 }
3279 }
3280}
3281
3282private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3283
3284/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003285friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003286 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3287runs on test_CT
3288{
3289 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3290 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3291}
3292
3293/* 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 +02003294friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3295 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003296runs on test_CT
3297{
3298 var PCUIF_send_data sd;
3299
3300 timer T := 3.0;
3301 T.start;
3302 alt {
3303 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3304 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3305 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3306 sd.data.u.rts_req.fn, sapi, data);
3307 }
3308 [] PCU.receive { repeat; }
3309 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003310 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003311 }
3312 }
3313}
3314
3315/* Send DATA.req on invalid BTS */
3316testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003317 var TfiUsfArr tua := f_TfiUsfArrInit();
3318 var octetstring data := '0000'O & f_rnd_octstring(21);
3319
3320 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003321
Harald Welte883340c2018-02-28 18:59:29 +01003322 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003323 f_TfiUsfArrSet(tua, 7, 0);
3324 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3325 f_sleep(1.0);
3326
3327 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003328}
3329
3330/* Send DATA.req on invalid TRX */
3331testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003332 var TfiUsfArr tua := f_TfiUsfArrInit();
3333 var octetstring data := '0000'O & f_rnd_octstring(21);
3334
3335 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003336
Harald Welte883340c2018-02-28 18:59:29 +01003337 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003338 f_TfiUsfArrSet(tua, 7, 0);
3339 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3340 f_sleep(1.0);
3341
3342 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003343}
3344
3345/* Send DATA.req on invalid timeslot */
3346testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003347 var TfiUsfArr tua := f_TfiUsfArrInit();
3348 var octetstring data := '0000'O & f_rnd_octstring(21);
3349
3350 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003351
Harald Welte883340c2018-02-28 18:59:29 +01003352 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003353 f_TfiUsfArrSet(tua, 7, 0);
3354 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3355 f_sleep(1.0);
3356
3357 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003358}
3359
3360/* Send DATA.req on timeslot that hasn't been activated */
3361testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003362 var TfiUsfArr tua := f_TfiUsfArrInit();
3363 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01003364
Harald Welte7162a612019-05-26 12:56:09 +02003365 f_virtphy_common();
3366
3367 f_TfiUsfArrSet(tua, 7, 0);
3368 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3369 f_sleep(1.0);
3370
3371 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003372}
3373
Harald Weltead033dc2019-05-25 17:28:16 +02003374private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02003375 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
3376 boolean wait_rts := true)
3377runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003378 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02003379 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02003380
3381 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02003382 if (wait_rts) {
3383 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3384 } else {
3385 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
3386 }
Harald Weltead033dc2019-05-25 17:28:16 +02003387
3388 T.start;
3389 alt {
Harald Welte7162a612019-05-26 12:56:09 +02003390 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02003391 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3392 setverdict(pass);
3393 }
Harald Welte7162a612019-05-26 12:56:09 +02003394 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
3395 setverdict(fail, "Received unexpected ", rx_dl);
3396 }
Harald Weltead033dc2019-05-25 17:28:16 +02003397 [] L1CTL.receive {
3398 repeat;
3399 }
Harald Welte7162a612019-05-26 12:56:09 +02003400 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02003401 setverdict(fail, "Timeout waiting for ", data);
3402 }
Harald Welte7162a612019-05-26 12:56:09 +02003403 [not expect_data] T.timeout {
3404 setverdict(pass);
3405 }
Harald Weltead033dc2019-05-25 17:28:16 +02003406 }
3407}
3408
3409private function f_disable_dynamic_ts() runs on test_CT
3410{
3411 f_init_vty_bsc();
3412 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3413 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3414 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3415 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003416 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003417}
3418
3419private function f_virtphy_common() runs on test_CT {
3420 f_disable_dynamic_ts();
3421 f_init_l1ctl();
3422 f_l1_tune(L1CTL);
3423}
3424
3425testcase TC_pcu_data_req_pdtch() runs on test_CT {
3426 var TfiUsfArr tua := f_TfiUsfArrInit();
3427 var octetstring data := '0000'O & f_rnd_octstring(21);
3428
3429 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003430
Harald Welte883340c2018-02-28 18:59:29 +01003431 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003432 f_TfiUsfArrSet(tua, 7, 0);
3433 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3434 f_sleep(1.0);
3435
3436 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003437}
3438
3439testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003440 var TfiUsfArr tua := f_TfiUsfArrInit();
3441 var octetstring data := '0000'O & f_rnd_octstring(21);
3442
3443 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003444
Harald Welte883340c2018-02-28 18:59:29 +01003445 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003446 f_TfiUsfArrSet(tua, 7, 0);
3447 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3448 f_sleep(1.0);
3449
3450 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01003451}
3452
3453/* Send AGCH from PCU; check it appears on Um side */
3454testcase TC_pcu_data_req_agch() runs on test_CT {
3455 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003456 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003457 f_init_l1ctl();
3458 f_l1_tune(L1CTL);
3459
3460 f_TC_pcu_act_req(0, 0, 7, true);
3461 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3462
3463 T.start;
3464 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003465 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003466 setverdict(pass);
3467 }
3468 [] L1CTL.receive { repeat; }
3469 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003470 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003471 }
3472 }
3473}
3474
Harald Welte928622b2019-05-26 13:22:59 +02003475/* Send AGCH from PCU; check it appears on Um side */
3476testcase TC_pcu_data_req_pch() runs on test_CT {
3477 timer T := 3.0;
3478 f_init_pcu_test();
3479 f_init_l1ctl();
3480 f_l1_tune(L1CTL);
3481
3482 f_TC_pcu_act_req(0, 0, 7, true);
3483 /* three characters prefix: last 3 digits of IMSI as ASCII */
3484 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
3485
3486 T.start;
3487 alt {
3488 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
3489 setverdict(pass);
3490 }
3491 [] L1CTL.receive { repeat; }
3492 [] T.timeout {
3493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
3494 }
3495 }
3496}
3497
Harald Welte883340c2018-02-28 18:59:29 +01003498/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3499testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3500 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003501 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003502 f_init_l1ctl();
3503 f_l1_tune(L1CTL);
3504
3505 /* append 3 last imsi digits so BTS can compute pagng group */
3506 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3507
3508 timer T := 0.5;
3509 T.start;
3510 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003511 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003512 /* TODO: verify paging group */
3513 setverdict(pass);
3514 }
3515 [] L1CTL.receive { repeat; }
3516 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003518 }
3519 }
3520}
3521
3522/* Send RACH from Um side, expect it to show up on PCU socket */
3523testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003524 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003525 f_init_l1ctl();
3526 f_l1_tune(L1CTL);
3527
3528 var GsmFrameNumber fn_last := 0;
3529 for (var integer i := 0; i < 1000; i := i+1) {
3530 var OCT1 ra := f_rnd_ra_ps();
3531 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3532 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003533 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003534 }
3535 fn_last := fn;
3536
3537 timer T := 2.0;
3538 T.start;
3539 alt {
3540 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3541 T.stop;
3542 }
3543 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003544 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003545 }
3546 [] PCU.receive { repeat; }
3547 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003548 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003549 }
3550 }
3551 }
3552 setverdict(pass);
3553}
3554
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003555/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3556 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3557testcase TC_pcu_ext_rach_content() runs on test_CT {
3558 var template PCUIF_Message pcu_rach_ind;
3559 var GsmFrameNumber fn_last := 0;
3560 var L1ctlRachSynchSeq synch_seq;
3561 var PCUIF_BurstType pcu_bt;
3562 var GsmFrameNumber fn;
3563 var BIT11 ra11;
3564
3565 f_init_pcu_test();
3566 f_init_l1ctl();
3567 f_l1_tune(L1CTL);
3568
3569 for (var integer i := 0; i < 1000; i := i+1) {
3570 /* We need to test both TS1 & TS2 */
3571 if (i rem 2 == 0) {
3572 synch_seq := RACH_SYNCH_SEQ_TS1;
3573 pcu_bt := BURST_TYPE_1;
3574 } else {
3575 synch_seq := RACH_SYNCH_SEQ_TS2;
3576 pcu_bt := BURST_TYPE_2;
3577 }
3578
3579 ra11 := f_rnd_ra11_ps();
3580 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3581 if (fn == fn_last) {
3582 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3583 "Two RACH in same FN?!?");
3584 }
3585 fn_last := fn;
3586
3587 /* Compose the expected message */
3588 pcu_rach_ind := tr_PCUIF_RACH_IND(
3589 bts_nr := 0,
3590 ra := bit2int(ra11),
3591 is_11bit := 1,
3592 burst_type := pcu_bt,
3593 fn := fn);
3594
3595 timer T := 2.0;
3596 T.start;
3597 alt {
3598 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3599 T.stop;
3600 }
3601 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3603 }
3604 [] PCU.receive { repeat; }
3605 [] T.timeout {
3606 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3607 }
3608 }
3609 }
3610 setverdict(pass);
3611}
3612
Harald Welte883340c2018-02-28 18:59:29 +01003613private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
3614 var integer strlen := lengthof(str);
3615 for (var integer i := 0; i < len-strlen; i := i+1) {
3616 str := str & pad;
3617 }
3618 return str;
3619}
3620
3621/* Send PAGING via RSL, expect it to shw up on PCU socket */
3622testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003623 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003624
3625 for (var integer i := 0; i < 100; i := i+1) {
3626 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3627 timer T := 3.0;
3628 if (i < 50) {
3629 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3630 } else {
3631 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3632 }
3633 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3634 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3635 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3636
3637 /* Send RSL PAGING COMMAND */
3638 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3639 T.start;
3640 alt {
3641 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3642 }
3643 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003644 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003645 }
3646 [] PCU.receive { repeat; }
3647 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003648 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003649 }
3650 }
3651 }
3652 setverdict(pass);
3653}
3654
Harald Welted66c9b82019-05-25 09:03:15 +02003655/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
3656testcase TC_pcu_time_ind() runs on test_CT {
3657 var PCUIF_send_data pcu_sd;
3658 var integer num_time_ind := 0;
3659 var integer first_fn, last_fn;
3660 var float test_duration := 5.0;
3661 timer T;
3662
3663 f_init_pcu_test();
3664 f_TC_pcu_act_req(0, 0, 7, true);
3665
3666 PCU.clear;
3667 T.start(test_duration);
3668 alt {
3669 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
3670 num_time_ind := num_time_ind + 1;
3671 if (not isbound(first_fn)) {
3672 first_fn := pcu_sd.data.u.time_ind.fn;
3673 }
3674 last_fn := pcu_sd.data.u.time_ind.fn;
3675 repeat;
3676 }
3677 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
3678 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
3679 repeat;
3680 }
3681 [] PCU.receive {
3682 repeat;
3683 }
3684 [] T.timeout {}
3685 }
3686 var integer fn_expired := last_fn - first_fn;
3687 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
3688
3689 /* verify the number of frames expired matches our expectation */
3690 const float c_GSM_FN_DURATION_MS := 4.61538;
3691 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
3692 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
3693 if (not match(fn_expired, t_fn_expected)) {
3694 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3695 }
3696
3697 /* There are three TIME.ind in every fn MOD 13 */
3698 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
3699 /* Add some tolerance */
3700 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
3701 if (not match(num_time_ind, t_time_ind_exp)) {
3702 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
3703 }
3704
3705 setverdict(pass);
3706}
3707
Harald Welte4832c862019-05-25 14:57:18 +02003708/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
3709testcase TC_pcu_rts_req() runs on test_CT {
3710 var PCUIF_send_data pcu_sd;
3711 var integer first_fn, last_fn;
3712 var integer num_rts_pdtch := 0;
3713 var integer num_rts_ptcch := 0;
3714 var float test_duration := 5.0;
3715 timer T;
3716
3717 f_init_pcu_test();
3718 f_TC_pcu_act_req(0, 0, 7, true);
3719
3720 PCU.clear;
3721 T.start(test_duration);
3722 alt {
3723 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
3724 -> value pcu_sd {
3725 num_rts_pdtch := num_rts_pdtch + 1;
3726 if (not isbound(first_fn)) {
3727 first_fn := pcu_sd.data.u.rts_req.fn;
3728 }
3729 last_fn := pcu_sd.data.u.rts_req.fn;
3730 repeat;
3731 }
3732 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
3733 -> value pcu_sd {
3734 num_rts_ptcch := num_rts_ptcch + 1;
3735 if (not isbound(first_fn)) {
3736 first_fn := pcu_sd.data.u.rts_req.fn;
3737 }
3738 last_fn := pcu_sd.data.u.rts_req.fn;
3739 repeat;
3740 }
3741 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
3742 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
3743 repeat;
3744 }
3745 [] PCU.receive {
3746 repeat;
3747 }
3748 [] T.timeout {}
3749 }
3750 var integer fn_expired := last_fn - first_fn;
3751 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
3752 ", num_rts_ptcch=", num_rts_ptcch);
3753
3754 /* verify the number of frames expired matches our expectation */
3755 const float c_GSM_FN_DURATION_MS := 4.61538;
3756 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
3757 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 10);
3758 if (not match(fn_expired, t_fn_expected)) {
3759 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3760 }
3761
3762 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
3763 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
3764 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
3765 if (not match(num_rts_ptcch, t_ptcch_exp)) {
3766 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
3767 t_ptcch_exp);
3768 }
3769
3770 /* We have 12 PDTCH blocks every 52-multiframe */
3771 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
3772 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
3773 if (not match(num_rts_pdtch, t_pdtch_exp)) {
3774 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
3775 t_pdtch_exp);
3776 }
3777
3778 setverdict(pass);
3779}
3780
Harald Welte07bd2d22019-05-25 11:03:30 +02003781/* test for generating Abis side OML ALERT from the PCU */
3782testcase TC_pcu_oml_alert() runs on test_CT {
3783 var PCUIF_send_data pcu_sd;
3784 var integer num_time_ind := 0;
3785 var integer first_fn, last_fn;
3786 var float test_duration := 5.0;
3787 timer T;
3788
3789 f_init_pcu_test();
3790 f_TC_pcu_act_req(0, 0, 7, true);
3791
3792 /* re-connect CTRL port from BTS to BSC */
3793 f_ipa_ctrl_stop();
3794 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
3795
3796 /* Send that OML Alert */
3797 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
3798
3799 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
3800 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
3801 setverdict(pass);
3802}
3803
Harald Welteeaa9a862019-05-26 23:01:08 +02003804template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
3805 template (value) RoutingAreaIdentificationV rai,
3806 template (value) OCT1 cause) := {
3807 discriminator := '0000'B, /* overwritten */
3808 tiOrSkip := {
3809 skipIndicator := '0000'B
3810 },
3811 msgs := {
3812 rrm := {
3813 gPRS_suspensionRequest := {
3814 messageType := '00110100'B,
3815 tLLI := tlli,
3816 routingAreaIdentification := rai,
3817 suspensionCause := cause,
3818 service_Support := omit
3819 }
3820 }
3821 }
3822}
3823
3824/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
3825private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
3826 var PCUIF_Message first_info;
3827 var integer pcu_conn_id := -1;
3828 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3829 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
3830 var OCT4 tlli := '01020304'O;
3831 var OCT1 cause := '23'O;
3832 timer T := 5.0;
3833
3834 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3835
3836 f_l1_tune(L1CTL);
3837 RSL.clear;
3838
3839 f_est_dchan();
3840 L1CTL.clear;
3841
3842 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3843
3844 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
3845 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
3846 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3847
3848 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
3849 T.start;
3850 alt {
3851 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
3852 setverdict(pass);
3853 }
3854 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
3855 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
3856 }
3857 [] PCU.receive {
3858 repeat;
3859 }
3860 [] T.timeout {
3861 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
3862 }
3863 }
3864}
3865testcase TC_pcu_rr_suspend() runs on test_CT {
3866 var ConnHdlrPars pars;
3867 var ConnHdlr vc_conn;
3868
3869 f_init();
3870
3871 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
3872 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
3873 vc_conn.done;
3874}
Harald Welte07bd2d22019-05-25 11:03:30 +02003875
Harald Welted66c9b82019-05-25 09:03:15 +02003876
Harald Welte3d04ae62018-04-04 20:29:05 +02003877/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02003878 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02003879 ***********************************************************************/
3880
3881private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3882runs on ConnHdlr {
3883 var PCUIF_send_data sd;
3884 /* Expect BTS to immediately acknowledge activation as PDCH */
3885 PCU.clear;
3886 f_rsl_chan_act(g_pars.chan_mode);
3887 /* expect INFO_IND on PCU interface listing TS as PDCH */
3888 alt {
3889 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3890 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 +02003891 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003892 }
3893 }
3894 [] PCU.receive { repeat; }
3895 }
3896 /* try to activate this PDCH from the PCU point of view */
3897 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3898 /* FIXME: is there a response? */
3899}
3900
3901private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
3902runs on ConnHdlr {
3903 var PCUIF_send_data sd;
3904 /* Send RSL CHAN REL (deactivate) */
3905 PCU.clear;
3906 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3907 /* expect BTS to ask PCU to deactivate the channel */
3908 alt {
3909 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
3910 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 +02003911 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02003912 }
3913 }
3914 [] PCU.receive { repeat; }
3915 }
3916 /* Emulate PCU asking BTS to deactivate PDCH */
3917 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
3918 alt {
3919 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
3920 setverdict(pass);
3921 }
3922 [] RSL.receive { repeat; }
3923 }
3924}
3925
3926/* Activate Osmocom-style dynamic PDCH from BSC side */
3927function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
3928 var PCUIF_Message first_info;
3929 var integer ts_nr := g_chan_nr.tn;
3930 var integer trx_nr := 0;
3931 var integer bts_nr := 0;
3932 var integer pcu_conn_id := -1;
3933
3934 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3935
3936 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
3937 f_sleep(3.0);
3938 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3939 setverdict(pass);
3940}
3941testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
3942 var ConnHdlrPars pars;
3943 var ConnHdlr vc_conn;
3944 f_init(testcasename());
3945
3946 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3947 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
3948 vc_conn.done;
3949}
3950
3951/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
3952function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
3953 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02003954 var integer pcu_conn_id := -1;
3955
3956 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3957
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02003958 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
3959 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
3960 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02003961 setverdict(pass);
3962}
3963testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
3964 var ConnHdlrPars pars;
3965 var ConnHdlr vc_conn;
3966 f_init(testcasename());
3967
3968 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3969 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
3970 vc_conn.done;
3971}
3972
3973/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
3974function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
3975 var PCUIF_Message first_info;
3976 var integer ts_nr := g_chan_nr.tn;
3977 var integer trx_nr := 0;
3978 var integer bts_nr := 0;
3979 var integer pcu_conn_id := -1;
3980
3981 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3982
3983 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02003984 /* Send a second Chan Activ and expect it to be NACKed */
3985 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
3986 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02003987 setverdict(pass);
3988}
3989testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
3990 var ConnHdlrPars pars;
3991 var ConnHdlr vc_conn;
3992 f_init(testcasename());
3993
3994 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
3995 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
3996 vc_conn.done;
3997}
3998
3999/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
4000function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
4001 var PCUIF_Message first_info;
4002 var integer ts_nr := g_chan_nr.tn;
4003 var integer trx_nr := 0;
4004 var integer bts_nr := 0;
4005 var integer pcu_conn_id := -1;
4006 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
4007
4008 /* register for the TCH/F channel number */
4009 f_rslem_register(0, chan_nr);
4010
4011 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4012
4013 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
4014 "RSL CHAN ACT");
4015 setverdict(pass);
4016}
4017testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
4018 var ConnHdlrPars pars;
4019 var ConnHdlr vc_conn;
4020 f_init(testcasename());
4021
4022 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4023 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
4024 vc_conn.done;
4025}
4026
4027/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
4028function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
4029 var PCUIF_Message first_info;
4030 var integer ts_nr := g_chan_nr.tn;
4031 var integer trx_nr := 0;
4032 var integer bts_nr := 0;
4033 var integer pcu_conn_id := -1;
4034 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
4035 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
4036
4037 /* register for the TCH/H channel numbers */
4038 f_rslem_register(0, chan_nr[0]);
4039 f_rslem_register(0, chan_nr[1]);
4040
4041 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4042
4043 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
4044 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
4045 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
4046 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
4047 setverdict(pass);
4048}
4049testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
4050 var ConnHdlrPars pars;
4051 var ConnHdlr vc_conn;
4052 f_init(testcasename());
4053
4054 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4055 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
4056 vc_conn.done;
4057}
4058
Harald Welte9bbbfb52018-04-05 09:33:19 +02004059/***********************************************************************
4060 * IPA Style Dynamic Timeslot Support
4061 ***********************************************************************/
4062
4063private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4064runs on ConnHdlr {
4065 var PCUIF_send_data sd;
4066 /* Expect BTS to immediately acknowledge activation as PDCH */
4067 PCU.clear;
4068 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4069 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004070 timer T_wait := 2.0;
4071 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004072 alt {
4073 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4074 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 +01004075 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
4076 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4077 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004078 }
4079 }
4080 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004081 [] T_wait.timeout {
4082 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4083 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
4084 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004085 }
4086 /* try to activate this PDCH from the PCU point of view */
4087 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4088 /* FIXME: is there a response? */
4089
4090 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
4091}
4092
4093private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4094runs on ConnHdlr {
4095 var PCUIF_send_data sd;
4096 /* Send RSL CHAN REL (deactivate) */
4097 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
4098 PCU.clear;
4099 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004100 timer T_wait := 2.0;
4101 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004102 alt {
4103 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4104 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 +01004105 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
4106 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4107 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004108 }
4109 }
4110 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004111 [] T_wait.timeout {
4112 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4113 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
4114 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004115 }
4116 /* Emulate PCU asking BTS to deactivate PDCH */
4117 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4118 alt {
4119 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
4120 setverdict(pass);
4121 }
4122 [] RSL.receive { repeat; }
4123 }
4124}
4125
4126/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
4127function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4128 var PCUIF_Message first_info;
4129 var integer ts_nr := g_chan_nr.tn;
4130 var integer trx_nr := 0;
4131 var integer bts_nr := 0;
4132 var integer pcu_conn_id := -1;
4133
4134 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4135
4136 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4137 f_sleep(3.0);
4138 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4139
4140 setverdict(pass);
4141
4142}
4143testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4144 var ConnHdlrPars pars;
4145 var ConnHdlr vc_conn;
4146 f_init();
4147
4148 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4149 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4150 vc_conn.done;
4151}
4152
4153/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4154function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4155 var PCUIF_Message first_info;
4156 var integer ts_nr := g_chan_nr.tn;
4157 var integer trx_nr := 0;
4158 var integer bts_nr := 0;
4159 var integer pcu_conn_id := -1;
4160
4161 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4162
4163 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4164 "RSL CHAN ACT");
4165 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4166 "RF CHAN REL", true);
4167 setverdict(pass);
4168}
4169testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4170 var ConnHdlrPars pars;
4171 var ConnHdlr vc_conn;
4172 f_init(testcasename());
4173
4174 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4175 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4176 vc_conn.done;
4177}
4178
4179/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4180function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4181 var PCUIF_Message first_info;
4182 var integer ts_nr := g_chan_nr.tn;
4183 var integer trx_nr := 0;
4184 var integer bts_nr := 0;
4185 var integer pcu_conn_id := -1;
4186
4187 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4188
4189 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4190 "RSL CHAN ACT");
4191
4192 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4193 alt {
4194 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4195 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004197 }
4198 [] RSL.receive { repeat; }
4199 }
4200
4201 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4202 "RF CHAN REL", true);
4203 setverdict(pass);
4204}
4205testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4206 var ConnHdlrPars pars;
4207 var ConnHdlr vc_conn;
4208 f_init(testcasename());
4209
4210 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4211 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4212 vc_conn.done;
4213}
4214
4215/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4216function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4217 var PCUIF_Message first_info;
4218 var integer ts_nr := g_chan_nr.tn;
4219 var integer trx_nr := 0;
4220 var integer bts_nr := 0;
4221 var integer pcu_conn_id := -1;
4222
4223 /* register for the TCH/F channel number */
4224 f_rslem_register(0, g_chan_nr);
4225
4226 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4227
4228 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4229
4230 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4231 "RSL CHAN ACT");
4232
4233 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4234
4235 setverdict(pass);
4236}
4237testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4238 var ConnHdlrPars pars;
4239 var ConnHdlr vc_conn;
4240 f_init(testcasename());
4241
4242 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4243 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
4244 vc_conn.done;
4245}
4246
4247
Harald Welte0472ab42018-03-12 15:02:26 +01004248/***********************************************************************
4249 * LAPDm / RLL related
4250 ***********************************************************************/
4251
4252private function f_tx_lapdm(template (value) LapdmFrame l,
4253 template (value) RslLinkId link_id) runs on ConnHdlr {
4254 var octetstring l2 := enc_LapdmFrame(valueof(l));
4255 if (valueof(link_id.c) == SACCH) {
4256 /* prepend dummy L1 header */
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02004257 var L1ctlDataReq l1hl2 := {
4258 l1header := valueof(ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta)),
4259 l2_payload := f_pad_oct(l2, 21, '2B'O)
4260 }
4261 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1hl2));
4262 } else {
4263 /* If required, pad L2 frame with constant 0x2b filling */
4264 l2 := f_pad_oct(l2, 23, '2B'O);
4265
4266 log("encoding ", l, " to ", l2);
4267 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
Harald Welte0472ab42018-03-12 15:02:26 +01004268 }
Harald Welte0472ab42018-03-12 15:02:26 +01004269}
4270
4271type record RllTestCase {
4272 uint3_t sapi,
4273 RslLinkId link_id,
4274 octetstring l3,
4275 boolean exp
4276}
4277type record of RllTestCase RllTestCases;
4278template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
4279 sapi := sapi,
4280 link_id := id,
4281 l3 := l3,
4282 exp := exp
4283}
4284
4285/* execute the same callback function with a set of different parameters (tcs) on a
4286 * variety of logical channels */
4287private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
4288 var ConnHdlrPars pars;
4289 var ConnHdlr vc_conn;
4290 f_init(testcasename());
4291
4292 /* test on each of the channels we have */
4293 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
4294 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
4295
4296 /* test each of the test cases on the current channel */
4297 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
4298 pars.spec.rll := tcs[j];
4299 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
4300 vc_conn := f_start_handler(fn, pars);
4301 vc_conn.done;
4302 }
4303 }
4304
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004305 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01004306}
4307
4308/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
4309private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
4310 var RllTestCase tc := g_pars.spec.rll;
4311 timer T := 3.0;
4312
4313 f_l1_tune(L1CTL);
4314 RSL.clear;
4315
4316 /* activate the logical channel */
4317 f_est_dchan();
4318 L1CTL.clear;
4319
4320 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
4321 T.start;
4322 alt {
4323 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
4324 if (tc.exp) {
4325 setverdict(pass);
4326 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004327 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004328 }
4329 }
4330 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
4331 if (tc.exp) {
4332 setverdict(pass);
4333 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004334 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004335 }
4336 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004337 /* We also expect to receive the measurements */
4338 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004339 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004340 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004341 }
4342 [not tc.exp] T.timeout {
4343 setverdict(pass);
4344 }
4345 }
4346
4347 f_rsl_chan_deact();
4348 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4349 f_rslem_unregister(0, g_chan_nr);
4350}
4351testcase TC_rll_est_ind() runs on test_CT {
4352 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02004353 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01004354 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02004355 /* normal SAPI0 establishment */
4356 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01004357 /* SAPI 3 doesn't support contention resolution */
4358 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
4359 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
4360 /* normal SAPI3 establishment on main DCCH */
4361 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4362 /* normal SAPI3 establishment on SACCH */
4363 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4364 };
4365 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
4366}
4367
4368/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
4369private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
4370 var RllTestCase tc := g_pars.spec.rll;
4371 var L1ctlDlMessage dl;
4372 timer T := 3.0;
4373
4374 f_l1_tune(L1CTL);
4375 RSL.clear;
4376
4377 /* activate the logical channel */
4378 f_est_dchan();
4379 L1CTL.clear;
4380
4381 /* Send a RSL EST REQ for SAPI3 on main DCCH */
4382 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
4383 T.start;
4384 alt {
4385 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4386 var LapdmFrame lapdm;
4387 var octetstring l2 := dl.payload.data_ind.payload;
4388 if (dl.dl_info.link_id.c == SACCH) {
4389 /* remove L1 header */
4390 l2 := substr(l2, 2, lengthof(l2)-2);
4391 }
4392 lapdm.ab := dec_LapdmFrameAB(l2);
4393 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
4394 setverdict(pass);
4395 } else {
4396 repeat;
4397 }
4398 }
4399 [] L1CTL.receive { repeat; }
4400 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01004402 }
4403 }
4404
4405 f_rsl_chan_deact();
4406 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4407 f_rslem_unregister(0, g_chan_nr);
4408}
4409testcase TC_rll_est_req_DCCH_3() runs on test_CT {
4410 var RllTestCases tcs := {
4411 /* normal SAPI3 establishment on main DCCH */
4412 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
4413 };
4414 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4415}
4416testcase TC_rll_est_req_ACCH_3() runs on test_CT {
4417 var RllTestCases tcs := {
4418 /* normal SAPI3 establishment on SACCH */
4419 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4420 }
4421 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4422}
4423
4424/* altstep to receive a LAPDm frame matching the given template */
4425private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
4426 var L1ctlDlMessage dl;
4427 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4428 var LapdmFrame lapdm;
4429 var octetstring l2 := dl.payload.data_ind.payload;
4430 if (dl.dl_info.link_id.c == SACCH) {
4431 /* remove L1 header */
4432 l2 := substr(l2, 2, lengthof(l2)-2);
4433 }
4434 if (ischosen(exp.ab)) {
4435 lapdm.ab := dec_LapdmFrameAB(l2);
4436 } else if (ischosen(exp.b4)) {
4437 lapdm.b4 := dec_LapdmFrameB4(l2);
4438 } else if (ischosen(exp.bbis)) {
4439 lapdm.bbis := dec_LapdmFrameBbis(l2);
4440 }
4441 log("Rx LAPDm ", lapdm);
4442 if (match(lapdm, exp)) {
4443 setverdict(pass);
4444 } else {
4445 repeat;
4446 }
4447 }
4448 [] L1CTL.receive { repeat; }
4449}
4450private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
4451 timer T := t;
4452 T.start;
4453 alt {
4454 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01004456 }
4457 [] as_l1_exp_lapdm(exp);
4458 }
4459}
4460
4461/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
4462private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4463 /* send SABM from MS -> BTS */
4464 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
4465 /* expect RLL EST IND on Abis */
4466 alt {
4467 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
4468 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
4469 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004470 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004471 }
4472 [] RSL.receive { repeat; }
4473 }
4474 /* expect UA from BTS -> MS */
4475 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
4476}
4477
4478/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
4479private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
4480 var RllTestCase tc := g_pars.spec.rll;
4481
4482 f_l1_tune(L1CTL);
4483 RSL.clear;
4484
4485 /* activate the logical channel */
4486 f_est_dchan();
4487 L1CTL.clear;
4488
4489 /* first establish the link-layer */
4490 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4491
4492 /* then send the DISC */
4493 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
4494 /* ... and expect the REL IND on the RSL side */
4495 alt {
4496 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
4497 setverdict(pass);
4498 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004499 /* We also expect to receive the measurements */
4500 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004501 }
4502
4503 /* release the channel */
4504 f_rsl_chan_deact();
4505 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4506 f_rslem_unregister(0, g_chan_nr);
4507}
4508testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
4509 var RllTestCases tcs := {
4510 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
4511 };
4512 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4513}
4514
4515testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
4516 var RllTestCases tcs := {
4517 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
4518 };
4519 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4520}
4521testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
4522 var RllTestCases tcs := {
4523 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
4524 };
4525 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4526}
4527testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
4528 var RllTestCases tcs := {
4529 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4530 };
4531 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4532}
4533
4534/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
4535private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
4536 var RllTestCase tc := g_pars.spec.rll;
4537 f_l1_tune(L1CTL);
4538 RSL.clear;
4539
4540 /* activate the logical channel */
4541 f_est_dchan();
4542 L1CTL.clear;
4543
4544 /* first establish the link-layer */
4545 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4546
4547 /* then send the REL REQ via RSL */
4548 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
4549 /* ... and expect the DISC on the Um side */
4550 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02004551 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01004552 /* FIXME: send a UA in resposne to the DISC */
4553 }
4554 }
4555
4556 /* release the channel */
4557 f_rsl_chan_deact();
4558 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4559 f_rslem_unregister(0, g_chan_nr);
4560}
4561testcase TC_rll_rel_req() runs on test_CT {
4562 var RllTestCases tcs := {
4563 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
4564 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
4565 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4566 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4567 };
4568 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
4569}
4570
4571/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
4572testcase TC_rll_data_req() runs on test_CT {
4573}
4574
4575/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
4576testcase TC_rll_data_ind() runs on test_CT {
4577}
4578
4579/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
4580private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
4581 var RllTestCase tc := g_pars.spec.rll;
4582
4583 f_l1_tune(L1CTL);
4584 RSL.clear;
4585
4586 f_est_dchan();
4587 L1CTL.clear;
4588
4589 /* Send UNITDATA REQ on RSL side */
4590 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
4591 /* Expect it to arrive on the other side */
4592 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02004593 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004594 } else {
Harald Weltee613f962018-04-18 22:38:16 +02004595 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004596 }
4597
4598 /* release the channel */
4599 f_rsl_chan_deact();
4600 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4601 f_rslem_unregister(0, g_chan_nr);
4602}
4603testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
4604 var octetstring l3 := f_rnd_octstring(15);
4605 var RllTestCases tcs := {
4606 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4607 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4608 };
4609 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4610}
4611testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
4612 var octetstring l3 := f_rnd_octstring(19);
4613 var RllTestCases tcs := {
4614 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4615 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4616 };
4617 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4618}
4619
4620/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
4621private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
4622 var RllTestCase tc := g_pars.spec.rll;
4623
4624 f_l1_tune(L1CTL);
4625 RSL.clear;
4626
4627 f_est_dchan();
4628 L1CTL.clear;
4629
4630 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02004631 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01004632 /* Expdct RLL UNITDATA IND on RSL side */
4633 alt {
4634 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
4635 setverdict(pass);
4636 }
4637 [] RSL.receive { repeat; }
4638 }
4639
4640 /* release the channel */
4641 f_rsl_chan_deact();
4642 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4643 f_rslem_unregister(0, g_chan_nr);
4644}
4645testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02004646 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01004647 var RllTestCases tcs := {
4648 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4649 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4650 };
4651 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4652}
4653testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
4654 var octetstring l3 := f_rnd_octstring(18);
4655 var RllTestCases tcs := {
4656 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4657 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4658 };
4659 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4660}
4661
Harald Weltee613f962018-04-18 22:38:16 +02004662/***********************************************************************
4663 * Encryption Related
4664 ***********************************************************************/
4665
4666/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4667function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4668 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
4669 if (link_id.c == SACCH) {
4670 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
4671 } else {
4672 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
4673 }
4674}
4675
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004676/* Expect (or not expect) other kinds of messages */
4677private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
4678 [exp_any] RSL.receive { repeat; }
4679 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004681 }
4682}
4683
Harald Weltee613f962018-04-18 22:38:16 +02004684/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07004685private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004686 RslLinkId link_id,
4687 octetstring l3,
4688 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004689 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07004690) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02004691 timer T := 3.0;
4692 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
4693 T.start;
4694 /* Expect RLL UNITDATA IND on RSL side */
4695 alt {
4696 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
4697 setverdict(pass);
4698 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004699 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07004700 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02004701 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004702 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02004703 }
Harald Weltee613f962018-04-18 22:38:16 +02004704 }
4705}
4706
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004707/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
4708private function f_data_mo(
4709 RslLinkId link_id,
4710 boolean p, uint3_t nr, uint3_t ns,
4711 octetstring l3,
4712 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07004713 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004714) runs on ConnHdlr {
4715 timer T := 3.0;
4716 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
4717 T.start;
4718 /* Expect RLL DATA IND on RSL side */
4719 alt {
4720 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
4721 setverdict(pass);
4722 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07004723 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004724 [] as_rsl_any_ind(exp_any);
4725 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004726 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004727 }
4728 }
4729}
4730
Harald Weltee613f962018-04-18 22:38:16 +02004731/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
4732function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
4733 f_l1_tune(L1CTL);
4734 f_est_dchan(true);
4735
4736 /* now we actually need to transmit some data both ways to check if the encryption works */
4737 var L1ctlDlMessage dl;
4738
Stefan Sperling603d98e2018-07-25 16:47:28 +02004739 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02004740 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4741
4742 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
4743 f_unitdata_mt(link_id, l3);
4744
4745 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
4746 f_unitdata_mo(link_id, l3);
4747
4748 /* release the channel */
4749 f_rsl_chan_deact();
4750 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4751 f_rslem_unregister(0, g_chan_nr);
4752}
4753testcase TC_chan_act_a51() runs on test_CT {
4754 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4755 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4756 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4757}
4758testcase TC_chan_act_a52() runs on test_CT {
4759 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4760 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4761 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4762}
4763testcase TC_chan_act_a53() runs on test_CT {
4764 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4765 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4766 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
4767}
4768
4769
4770/* Test unencrypted channel activation followed by explicit ENCR CMD later */
4771function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
4772 /* L3 payload doesn't matter, as it is passed transparently */
4773 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
4774 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
4775 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
4776
4777 f_l1_tune(L1CTL);
4778
4779 /* first establish a dedicated channel in the clear */
4780 f_est_dchan(false);
4781
4782 /* Establish ABM */
4783 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
4784
4785 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
4786 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
4787 /* expect the L3 to arrive still unencrypted on the MS side */
4788 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
4789
4790 /* configure L1 to apply ciphering */
4791 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
4792 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
4793
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07004794 /* send first ciphered I-frame in response and expect it on RSL */
4795 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02004796
4797 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
4798 * and hence enable encryption also on the downlink */
4799
4800 /* expect bi-directional communication work in encrypted mode */
4801 f_unitdata_mo(link_id, f_rnd_octstring(15));
4802 f_unitdata_mt(link_id, f_rnd_octstring(15));
4803
4804 /* release the channel */
4805 f_rsl_chan_deact();
4806 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4807 f_rslem_unregister(0, g_chan_nr);
4808}
4809testcase TC_encr_cmd_a51() runs on test_CT {
4810 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4811 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
4812 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4813}
4814testcase TC_encr_cmd_a52() runs on test_CT {
4815 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4816 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
4817 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4818}
4819testcase TC_encr_cmd_a53() runs on test_CT {
4820 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
4821 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
4822 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
4823}
4824
4825private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
4826 var LapdmFrame lf;
4827 var octetstring reenc;
4828
4829 /* decode the LAPDm frame */
4830 if (ischosen(exp_match.ab)) {
4831 lf.ab := dec_LapdmFrameAB(enc);
4832 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02004834 }
4835
4836 /* check if decoder result matches expectation */
4837 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004838 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004839 } else {
4840 log(name, ": matched");
4841 setverdict(pass);
4842 }
4843
4844 /* test if re-encoded frame equals original input */
4845 reenc := enc_LapdmFrame(lf);
4846 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004847 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02004848 } else {
4849 setverdict(pass);
4850 }
4851}
4852
4853testcase TC_lapdm_selftest() runs on test_CT {
4854 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
4855 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
4856 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
4857 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
4858 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
4859 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
4860 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
4861}
4862
Stefan Sperling4880be42018-08-07 18:12:59 +02004863/***********************************************************************
4864 * DTX Related (see GSM 05.08, section 8.3)
4865 ***********************************************************************/
4866
4867/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
4868function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
4869 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
4870 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
4871 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
4872 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
4873}
4874function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
4875 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
4876 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
4877}
4878function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
4879 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
4880 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
4881 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
4882 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
4883}
4884function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
4885 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
4886 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
4887 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
4888 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
4889 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
4890 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
4891 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
4892 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
4893}
4894
4895function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
4896 var L1ctlDlMessage dl;
4897 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
4898 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
4899 var GsmFrameNumber first_fn;
4900 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004901 var integer nfill_frames_sacch := 0;
4902 var integer nfill_frames_nonsacch := 0;
4903 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02004904 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
4905 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004906 const integer frame_dtx_tchf_mod := 104;
4907 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
4908 * which operates in terms of blocks rather than frames. */
4909 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
4910 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02004911 timer T := 5.0;
4912
4913 f_l1_tune(L1CTL);
4914 RSL.clear;
4915 L1CTL.clear;
4916
4917 /* activate TCHF signalling channel */
4918 f_est_dchan(false);
4919
4920 T.start;
4921 alt {
4922 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4923 var GsmFrameNumber fn := dl.dl_info.frame_nr;
4924 var octetstring l2 := dl.payload.data_ind.payload;
4925
4926 if (is_first_frame) {
4927 is_first_frame := false;
4928 first_fn := dl.dl_info.frame_nr;
4929 }
4930
4931 if (dl.dl_info.link_id.c == SACCH) {
4932 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
4933 if (not match(l2_fill_frame_sacch, l2)) {
4934 repeat;
4935 }
4936 } else if (not match(l2_fill_frame, l2)) {
4937 repeat;
4938 }
4939
4940 if (dtxd) {
4941 if (not f_g_chan_is_tchf()) {
4942 T.stop;
4943 f_rsl_chan_deact();
4944 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004945 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 +02004946 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004947 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004948 T.stop;
4949 f_rsl_chan_deact();
4950 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004951
4952 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
4953 * 2 SACCH, 1 TCH/F */
4954 expected_fill_frames := 3;
4955
4956 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
4957 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
4958 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004959 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02004960 } else {
4961 setverdict(pass);
4962 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004963 } else {
4964 if (dl.dl_info.link_id.c == SACCH) {
4965 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02004966 repeat;
4967 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004968 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
4969 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
4970 * we should only see the subset of frames numbers which correspond to a block boundary.
4971 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
4972 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
4973 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
4974 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4975 repeat;
4976 }
4977 }
4978 log("Received DTX TCH fill frame with bad frame number: ", fn,
4979 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
4980 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
4981 f_rsl_chan_deact();
4982 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02004984 }
Stefan Sperling4880be42018-08-07 18:12:59 +02004985 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02004986 if (dl.dl_info.link_id.c == SACCH) {
4987 nfill_frames_sacch := nfill_frames_sacch + 1;
4988 } else {
4989 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
4990 }
4991 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02004992 T.stop;
4993 if (f_g_chan_is_tchf()) {
4994 /* Without DTX we can expect 25 fill frames for every 104 frames.
4995 * (24 FACCH + 1 SACCH filling) */
4996 expected_fill_frames := 25;
4997 } else if (f_g_chan_is_tchh()) {
4998 /* We can expect 2 fill frames for every 104 frames. */
4999 expected_fill_frames := 2;
5000 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
5001 /* We can expect 5 fill frames for every 104 frames. */
5002 expected_fill_frames := 5;
5003 } else {
5004 f_rsl_chan_deact();
5005 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005006 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02005007 }
5008
5009 f_rsl_chan_deact();
5010 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005011
5012 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005013 setverdict(pass);
5014 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005015 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5016 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005017 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005018 }
5019 } else {
5020 repeat;
5021 }
5022 }
5023 }
5024 [] L1CTL.receive { repeat; }
5025 [] T.timeout {
5026 f_rsl_chan_deact();
5027 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005029 }
5030 }
5031}
5032
5033function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
5034 f_test_l2_fill_frames(false);
5035}
5036
5037function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
5038 f_test_l2_fill_frames(true);
5039}
5040
5041function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
5042 var ConnHdlr vc_conn;
5043 var ConnHdlrPars pars;
5044 pars.t_guard := 60.0;
5045 f_init(testcasename());
5046 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
5047 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
5048 if (dtxd) {
5049 if (i >= 4) { /* DTX is only allowed on TCH/F */
5050 break;
5051 }
5052 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
5053 } else {
5054 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
5055 }
5056 vc_conn.done;
5057 }
5058}
5059
5060/* Verify that L2 fill frames are sent on TCH in signaling mode if
5061 * there is nothing to transmit while DTX is disabled on downlink. */
5062testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
5063 f_tch_sign_l2_fill_frame(false);
5064}
5065
5066/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
5067 * there is nothing to transmit while DTX is enabled on downlink. */
5068testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
5069 f_tch_sign_l2_fill_frame(true);
5070}
Harald Welte0472ab42018-03-12 15:02:26 +01005071
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005072testcase TC_chopped_ipa_ping() runs on test_CT {
5073 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5074}
5075
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005076testcase TC_chopped_ipa_payload() runs on test_CT {
5077 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5078}
5079
Harald Welte0472ab42018-03-12 15:02:26 +01005080/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
5081/* protocol error as per 44.006 */
5082/* link layer failure (repetition of I-frame N200 times without ACK */
5083/* repetition of SABM or DISC N200 times without ACK */
5084/* receptiom of SABM in multi-frame established state */
5085
5086
Harald Welte68e495b2018-02-25 00:05:57 +01005087/* TODO Areas:
5088
5089* channel activation
5090** with BS_Power / MS_Power, bypassing power control loop
5091** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01005092** with timing advance from initial activation on
5093* mode modify
5094** encryption
5095** multirate
5096* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01005097** unsupported algorithm
5098* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01005099* BS Power Control
5100* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01005101* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01005102* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01005103** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01005104* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01005105** DATA_IND from BTS->PCU
5106** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01005107
5108*/
Harald Welte70767382018-02-21 12:16:40 +01005109
5110control {
5111 execute( TC_chan_act_stress() );
5112 execute( TC_chan_act_react() );
5113 execute( TC_chan_deact_not_active() );
5114 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01005115 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01005116 execute( TC_sacch_filling() );
5117 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01005118 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01005119 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02005120 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02005121 execute( TC_sacch_chan_act_ho_async() );
5122 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01005123 execute( TC_rach_content() );
5124 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01005125 execute( TC_rach_max_ta() );
Harald Welte3453ab42019-05-24 21:19:58 +02005126 execute( TC_rach_load_idle_thresh0() );
5127 execute( TC_rach_load_idle_below_thresh() );
5128 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01005129 execute( TC_meas_res_sign_tchf() );
5130 execute( TC_meas_res_sign_tchh() );
5131 execute( TC_meas_res_sign_sdcch4() );
5132 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01005133 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01005134 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wild6833cc92019-05-23 19:34:44 +02005135 execute( TC_rsl_chan_initial_ta() );
Harald Welte70767382018-02-21 12:16:40 +01005136 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01005137 execute( TC_paging_imsi_80percent() );
5138 execute( TC_paging_tmsi_80percent() );
5139 execute( TC_paging_imsi_200percent() );
5140 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01005141 execute( TC_rsl_protocol_error() );
5142 execute( TC_rsl_mand_ie_error() );
5143 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01005144 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01005145 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01005146 execute( TC_si_sched_2bis() );
5147 execute( TC_si_sched_2ter() );
5148 execute( TC_si_sched_2ter_2bis() );
5149 execute( TC_si_sched_2quater() );
5150 execute( TC_si_sched_13() );
5151 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01005152 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01005153 execute( TC_ipa_crcx_twice_not_active() );
5154 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01005155 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01005156 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01005157
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005158 if (mp_pcu_socket != "") {
5159 execute( TC_pcu_act_req() );
5160 execute( TC_pcu_act_req_wrong_ts() );
5161 execute( TC_pcu_act_req_wrong_bts() );
5162 execute( TC_pcu_act_req_wrong_trx() );
5163 execute( TC_pcu_deact_req() );
5164 execute( TC_pcu_deact_req_wrong_ts() );
5165 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02005166 if (mp_l1_supports_gprs) {
5167 execute( TC_pcu_data_req_pdtch() );
5168 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02005169 execute( TC_pcu_data_req_wrong_bts() );
5170 execute( TC_pcu_data_req_wrong_trx() );
5171 execute( TC_pcu_data_req_wrong_ts() );
5172 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02005173 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005174 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02005175 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005176 execute( TC_pcu_data_req_imm_ass_pch() );
5177 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005178 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005179 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02005180 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02005181 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02005182 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02005183 execute( TC_pcu_rr_suspend() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005184 } else {
5185 log("PCU socket path not available, skipping PCU tests");
5186 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005187
5188 execute( TC_dyn_osmo_pdch_act_deact() );
5189 execute( TC_dyn_osmo_pdch_unsol_deact() );
5190 execute( TC_dyn_osmo_pdch_double_act() );
5191 execute( TC_dyn_osmo_pdch_tchf_act() );
5192 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02005193 execute( TC_dyn_ipa_pdch_act_deact() );
5194 execute( TC_dyn_ipa_pdch_tchf_act() );
5195 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
5196 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01005197
5198 execute( TC_rll_est_ind() );
5199 execute( TC_rll_est_req_DCCH_3() );
5200 execute( TC_rll_est_req_ACCH_3() );
5201 execute( TC_rll_rel_ind_DCCH_0() );
5202 execute( TC_rll_rel_ind_DCCH_3() );
5203 execute( TC_rll_rel_ind_ACCH_0() );
5204 execute( TC_rll_rel_ind_ACCH_3() );
5205 execute( TC_rll_rel_req() );
5206 execute( TC_rll_unit_data_req_DCCH() );
5207 execute( TC_rll_unit_data_req_ACCH() );
5208 execute( TC_rll_unit_data_ind_DCCH() );
5209 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02005210
5211 execute( TC_chan_act_a51() );
5212 execute( TC_chan_act_a52() );
5213 execute( TC_chan_act_a53() );
5214 execute( TC_encr_cmd_a51() );
5215 execute( TC_encr_cmd_a52() );
5216 execute( TC_encr_cmd_a53() );
5217
Harald Welteee25aae2019-05-19 14:32:37 +02005218 execute( TC_err_rep_wrong_mdisc() );
5219 execute( TC_err_rep_wrong_msg_type() );
5220 execute( TC_err_rep_wrong_sequence() );
5221
Harald Weltee613f962018-04-18 22:38:16 +02005222 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02005223
5224 execute( TC_tch_sign_l2_fill_frame() );
5225 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005226
5227 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005228 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01005229}
5230
5231
5232}