blob: 931c9ab4125bd66196b7bcd286de3927fd2ed4f8 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
3import from General_Types all;
4import from GSM_Types all;
5import from GSM_RR_Types all;
6import from Osmocom_Types all;
7import from GSM_Types all;
8import from GSM_RR_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;
13import from Osmocom_CTRL_Adapter all;
14
15import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010016import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010017import from IPA_Emulation all;
18import from RSL_Emulation all;
19
20import from IPL4asp_Types all;
21import from TRXC_Types all;
22import from TRXC_CodecPort all;
23import from TRXC_CodecPort_CtrlFunct all;
24
Harald Welte883340c2018-02-28 18:59:29 +010025import from PCUIF_Types all;
26import from PCUIF_CodecPort all;
27
Harald Welte7484fc42018-02-24 14:09:45 +010028import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010029import from MobileL3_RRM_Types all;
30import from MobileL3_Types all;
31import from L3_Templates all;
Harald Welte7484fc42018-02-24 14:09:45 +010032
Harald Welte8da48242018-02-27 20:41:32 +010033import from Osmocom_VTY_Functions all;
34import from TELNETasp_PortType all;
35
Harald Welte70767382018-02-21 12:16:40 +010036/* The tests assume a BTS with the following timeslot configuration:
37 * TS0 : Combined CCCH + SDCCH/4
38 * TS1 .. TS 4: TCH/F
39 * TS5 : TCH/H
40 * TS6 : SDCCH/8
41 * TS7 : PDCH
42 */
43
44modulepar {
45 charstring mp_rsl_ip := "127.0.0.2";
46 integer mp_rsl_port := 3003;
47 integer mp_trx0_arfcn := 871;
Harald Weltea4d8f352018-03-01 15:47:20 +010048 charstring mp_bb_trxc_ip := "127.0.0.1";
Harald Welteef3e1c92018-02-28 23:40:14 +010049 integer mp_bb_trxc_port := 6701;
Harald Welte883340c2018-02-28 18:59:29 +010050 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Harald Welte70767382018-02-21 12:16:40 +010051}
52
53type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +010054 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +010055 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +010056 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +010057 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +010058 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +010059 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +010060
61 /* L1CTL port (for classic tests) */
62 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +010063
Harald Welte54a2a2d2018-02-26 09:14:05 +010064 /* TRXC port (for classic tests) */
65 port TRXC_CODEC_PT BB_TRXC;
66 var integer g_bb_trxc_conn_id;
67
Harald Welte8da48242018-02-27 20:41:32 +010068 port TELNETasp_PT BTSVTY;
69
Harald Welte883340c2018-02-28 18:59:29 +010070 /* PCU Interface of BTS */
71 port PCUIF_CODEC_PT PCU;
72 var integer g_pcu_conn_id;
73 /* Last PCU INFO IND we received */
74 var PCUIF_Message g_pcu_last_info;
75
Harald Welte48494ca2018-02-25 16:59:50 +010076 /* SI configuration */
77 var SystemInformationConfig si_cfg := {
78 bcch_extended := false,
79 si1_present := false,
80 si2bis_present := false,
81 si2ter_present := false,
82 si2quater_present := false,
83 si7_present := false,
84 si8_present := false,
85 si9_present := false,
86 si13_present := false,
87 si13alt_present := false,
88 si15_present := false,
89 si16_present := false,
90 si17_present := false,
91 si2n_present := false,
92 si21_present := false,
93 si22_present := false
94 };
Harald Welte70767382018-02-21 12:16:40 +010095}
96
97/* an individual call / channel */
98type component ConnHdlr extends RSL_DchanHdlr {
99 port L1CTL_PT L1CTL;
100
101 port TRXC_CODEC_PT BB_TRXC;
102 var integer g_bb_trxc_conn_id;
103
104 timer g_Tguard;
105 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
106
107 var ConnHdlrPars g_pars;
108 var uint8_t g_next_meas_res_nr := 0;
109}
110
111function f_init_rsl(charstring id) runs on test_CT {
112 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
113 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
114
115 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
116 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
117 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
118
119 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
120 vc_RSL.start(RSL_Emulation.main(false));
121}
122
123type record ConnHdlrPars {
124 RslChannelNr chan_nr,
125 RSL_IE_ChannelMode chan_mode,
126 float t_guard,
127 ConnL1Pars l1_pars
128}
129
Harald Welte82ccef72018-02-25 16:17:33 +0100130template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100131 max_retrans := RACH_MAX_RETRANS_7,
132 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100133 cell_barr_access := false,
134 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100135 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100136};
137
Harald Weltef10153f2018-02-25 16:34:05 +0100138template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100139 cell_resel_hyst_2dB := 2,
140 ms_txpwr_max_cch := 7,
Harald Weltef10153f2018-02-25 16:34:05 +0100141 acs := '0'B,
142 neci := true,
143 rxlev_access_min := 0
144}
145
146template (value) LocationAreaIdentification ts_LAI_default := {
147 mcc_mnc := '262F42'H,
148 lac := 42
149}
150
Harald Welte7484fc42018-02-24 14:09:45 +0100151/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100152template (value) SystemInformation ts_SI3_default := {
153 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100154 payload := {
155 si3 := {
156 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100157 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100158 ctrl_chan_desc := {
159 msc_r99 := true,
160 att := true,
161 bs_ag_blks_res := 1,
162 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100163 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100164 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
165 spare := '00'B,
166 bs_pa_mfrms := 0, /* 2 multiframes */
167 t3212 := 1 /* 6 minutes */
168 },
Harald Welte82ccef72018-02-25 16:17:33 +0100169 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100170 dn_ind := false,
171 pwrc := false,
172 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100173 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100174 },
Harald Weltef10153f2018-02-25 16:34:05 +0100175 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100176 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100177 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100178 }
179 }
180}
Harald Welte70767382018-02-21 12:16:40 +0100181
Harald Weltef8df4cb2018-03-10 15:15:08 +0100182template (value) SystemInformation ts_SI2_default := {
183 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100184 payload := {
185 si2 := {
186 bcch_freq_list := '00000000000000000000000000000000'O,
187 ncc_permitted := '11111111'B,
188 rach_control := ts_RachCtrl_default
189 }
190 }
191}
192
Harald Weltef8df4cb2018-03-10 15:15:08 +0100193template (value) SystemInformation ts_SI4_default := {
194 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100195 payload := {
196 si4 := {
197 lai := ts_LAI_default,
198 cell_sel_par := ts_CellSelPar_default,
199 rach_control := ts_RachCtrl_default,
200 cbch_chan_desc := omit,
201 cbch_mobile_alloc := omit,
202 rest_octets := ''O
203 }
204 }
205}
206
207function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
208runs on test_CT {
209 log("Setting ", rsl_si_type, ": ", si_enc);
210 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
211}
212
213function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
214runs on test_CT {
215 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
216 log("Setting ", rsl_si_type, ": ", si_dec);
217 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
218}
219
Harald Welte8da48242018-02-27 20:41:32 +0100220private function f_init_vty(charstring id) runs on test_CT {
221 map(self:BTSVTY, system:BTSVTY);
222 f_vty_set_prompts(BTSVTY);
223 f_vty_transceive(BTSVTY, "enable");
224}
225
Harald Welte883340c2018-02-28 18:59:29 +0100226/* PCU socket may at any time receive a new INFO.ind */
227private altstep as_pcu_info_ind() runs on test_CT {
228 var PCUIF_send_data sd;
229 [] PCU.receive(t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_INFO_IND)) -> value sd {
230 g_pcu_last_info := sd.data;
231 repeat;
232 }
233}
234
235private function f_init_pcu(charstring id) runs on test_CT {
236 timer T := 2.0;
237 var PCUIF_send_data sd;
238 map(self:PCU, system:PCU);
Harald Welte84271622018-03-10 17:21:03 +0100239 if (mp_pcu_socket == "") {
240 g_pcu_conn_id := -1;
241 return;
242 }
Harald Welte883340c2018-02-28 18:59:29 +0100243 g_pcu_conn_id := f_pcuif_connect(PCU, mp_pcu_socket);
244
245 T.start;
246 alt {
247 [] PCU.receive(t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_INFO_IND)) -> value sd {
248 g_pcu_last_info := sd.data;
249 }
250 [] T.timeout {
251 setverdict(fail, "Timeout waiting for PCU INFO_IND");
252 self.stop;
253 }
254 }
255}
256
Harald Welte70767382018-02-21 12:16:40 +0100257/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100258function f_init(charstring id := "BTS-Test") runs on test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100259 f_init_rsl(id);
260 RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
Harald Welte2d142592018-02-25 13:19:44 +0100261 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100262 f_init_vty(id);
Harald Welte7484fc42018-02-24 14:09:45 +0100263
264 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100265 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
266 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
267 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
268 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100269
Harald Welte883340c2018-02-28 18:59:29 +0100270 f_init_pcu(id);
271
Harald Welte84271622018-03-10 17:21:03 +0100272 if (mp_bb_trxc_port != -1) {
273 var TrxcMessage ret;
274 /* start with a default moderate timing offset equalling TA=2 */
275 f_main_trxc_connect();
276 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
277 }
Harald Welte70767382018-02-21 12:16:40 +0100278}
279
Harald Welte68e495b2018-02-25 00:05:57 +0100280/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
281function f_init_l1ctl() runs on test_CT {
282 map(self:L1CTL, system:L1CTL);
283 f_connect_reset(L1CTL);
284}
285
Harald Welte70767382018-02-21 12:16:40 +0100286type function void_fn(charstring id) runs on ConnHdlr;
287
288/* create a new test component */
289function f_start_handler(void_fn fn, ConnHdlrPars pars)
290runs on test_CT return ConnHdlr {
291 var charstring id := testcasename();
292 var ConnHdlr vc_conn;
293
294 vc_conn := ConnHdlr.create(id);
295 /* connect to RSL Emulation main component */
296 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
297 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
298
299 vc_conn.start(f_handler_init(fn, id, pars));
300 return vc_conn;
301}
302
Harald Welte7484fc42018-02-24 14:09:45 +0100303template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
304 streamId := sid,
305 rsl := rsl
306}
307
308template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
309 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
310 streamId := sid,
311 rsl := rsl
312}
313
Harald Welte70767382018-02-21 12:16:40 +0100314private altstep as_Tguard() runs on ConnHdlr {
315 [] g_Tguard.timeout {
316 setverdict(fail, "Tguard timeout");
317 self.stop;
318 }
319}
320
Harald Welte68e495b2018-02-25 00:05:57 +0100321private function f_l1_tune(L1CTL_PT L1CTL) {
Harald Welte70767382018-02-21 12:16:40 +0100322 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED);
323}
324
325private function f_trxc_connect() runs on ConnHdlr {
326 map(self:BB_TRXC, system:BB_TRXC);
327 var Result res;
Harald Weltea4d8f352018-03-01 15:47:20 +0100328 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
329 "", -1, -1, {udp:={}}, {});
Harald Welte70767382018-02-21 12:16:40 +0100330 g_bb_trxc_conn_id := res.connId;
331}
332
333private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100334 var TrxcMessage ret;
335 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100336}
337
338private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100339 var TrxcMessage ret;
340 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100341}
342
343/* first function started in ConnHdlr component */
344private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
345runs on ConnHdlr {
346 g_pars := pars;
347 g_chan_nr := pars.chan_nr;
348
349 map(self:L1CTL, system:L1CTL);
350 f_connect_reset(L1CTL);
351
Harald Welte84271622018-03-10 17:21:03 +0100352 if (mp_bb_trxc_port != -1) {
353 f_trxc_connect();
354 }
Harald Welte70767382018-02-21 12:16:40 +0100355
356 g_Tguard.start(pars.t_guard);
357 activate(as_Tguard());
358
359 f_rslem_register(0, pars.chan_nr);
360
361 /* call the user-supplied test case function */
362 fn.apply(id);
363}
364
Harald Welte1eba3742018-02-25 12:48:14 +0100365function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id)
366runs on ConnHdlr {
367 timer T := 3.0;
368 RSL.send(tx);
369 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100370 alt {
Harald Welte1eba3742018-02-25 12:48:14 +0100371 [] RSL.receive(exp_rx) {
372 T.stop;
373 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100374 }
Harald Welte1eba3742018-02-25 12:48:14 +0100375 [] T.timeout {
376 setverdict(fail, "Timeout expecting " & id);
377 self.stop;
378 }
379 [] RSL.receive {
380 setverdict(fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100381 }
382 }
383}
384
Harald Welte1eba3742018-02-25 12:48:14 +0100385function f_rsl_chan_act(RSL_IE_ChannelMode mode) runs on ConnHdlr {
386 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
387 "RSL CHAN ACT");
388}
389
Harald Welte70767382018-02-21 12:16:40 +0100390function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100391 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
392 "RF CHAN REL");
Harald Welte70767382018-02-21 12:16:40 +0100393}
394
Harald Welte70767382018-02-21 12:16:40 +0100395private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
396 template RSL_IE_ChannelMode chan_mode,
397 float t_guard := 20.0) := {
398 chan_nr := valueof(chan_nr),
399 chan_mode := valueof(chan_mode),
400 t_guard := t_guard,
401 l1_pars := {
402 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100403 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100404 meas_ul := {
405 full := {
406 rxlev := dbm2rxlev(-53),
407 rxqual := 0
408 },
409 sub := {
410 rxlev := dbm2rxlev(-53),
411 rxqual := 0
412 }
413 },
414 timing_offset_256syms := 0,
415 bs_power_level := 0,
416 ms_power_level := 0,
417 ms_actual_ta := 0
418 }
419}
420
Harald Welte93640c62018-02-25 16:59:33 +0100421/***********************************************************************
422 * Channel Activation / Deactivation
423 ***********************************************************************/
424
Harald Welte70767382018-02-21 12:16:40 +0100425/* Stress test: Do 500 channel activations/deactivations in rapid succession */
426function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
427 for (var integer i := 0; i < 500; i := i+1) {
428 f_rsl_chan_act(g_pars.chan_mode);
429 f_rsl_chan_deact();
430 }
431 setverdict(pass);
432}
433testcase TC_chan_act_stress() runs on test_CT {
434 var ConnHdlr vc_conn;
435 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
436 f_init(testcasename());
437 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
438 vc_conn.done;
439}
440
441/* Test if re-activation of an already active channel fails as expected */
442function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
443 f_rsl_chan_act(g_pars.chan_mode);
444 /* attempt to activate the same lchan again -> expect reject */
445 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
446 alt {
447 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
448 setverdict(fail, "Unexpected CHAN ACT ACK on double activation");
449 }
450 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
451 setverdict(pass);
452 }
453 }
454 f_rsl_chan_deact();
455}
456testcase TC_chan_act_react() runs on test_CT {
457 var ConnHdlr vc_conn;
458 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
459 f_init(testcasename());
460 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
461 vc_conn.done;
462}
463
464/* Attempt to de-activate a channel that's not active */
465function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
466 timer T := 3.0;
467 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
468 T.start;
469 alt {
470 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
471 setverdict(pass);
472 }
473 [] T.timeout {
474 setverdict(fail, "Timeout expecting RF_CHAN_REL_ACK");
475 }
476 }
477}
478testcase TC_chan_deact_not_active() runs on test_CT {
479 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
480 f_init(testcasename());
481 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
482 vc_conn.done;
483}
484
485/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
486function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
487 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
488 alt {
489 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
490 setverdict(fail, "Unexpected CHAN ACT ACK");
491 }
492 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
493 setverdict(pass);
494 }
495 }
496}
497private type record WrongChanNrCase {
498 RslChannelNr chan_nr,
499 charstring description
500}
501private type record of WrongChanNrCase WrongChanNrCases;
502private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
503 chan_nr := chan_nr,
504 description := desc
505}
506
507testcase TC_chan_act_wrong_nr() runs on test_CT {
508 var ConnHdlr vc_conn;
509 var ConnHdlrPars pars;
510
511 f_init(testcasename());
512
513 var WrongChanNrCases wrong := {
514 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
515 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
516 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
517 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
518 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
519 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
520 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
521 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
522 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
523 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
524 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
525 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
526 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
527 };
528
529 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
530 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
531 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
532 vc_conn.done;
533 }
534}
535
Harald Welte93640c62018-02-25 16:59:33 +0100536/***********************************************************************
537 * RACH Handling
538 ***********************************************************************/
539
Harald Welte8c24c2b2018-02-26 08:31:31 +0100540/* like L1SAP_IS_PACKET_RACH */
541private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +0100542 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +0100543 return true;
544 }
545 return false;
546}
547
548/* generate a random RACH for circuit-switched */
549private function f_rnd_ra_cs() return OCT1 {
550 var OCT1 ra;
551 do {
552 ra := f_rnd_octstring(1);
553 } while (ra_is_ps(ra));
554 return ra;
555}
556
Harald Welte883340c2018-02-28 18:59:29 +0100557/* generate a random RACH for packet-switched */
558private function f_rnd_ra_ps() return OCT1 {
559 var OCT1 ra;
560 do {
561 ra := f_rnd_octstring(1);
562 } while (not ra_is_ps(ra));
563 return ra;
564}
565
Harald Welte8c24c2b2018-02-26 08:31:31 +0100566/* Send 1000 RACH requests and check their RA+FN on the RSL side */
567testcase TC_rach_content() runs on test_CT {
568 f_init(testcasename());
569 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +0100570 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100571
Harald Welte8c24c2b2018-02-26 08:31:31 +0100572 var GsmFrameNumber fn_last := 0;
573 for (var integer i := 0; i < 1000; i := i+1) {
574 var OCT1 ra := f_rnd_ra_cs();
575 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
576 if (fn == fn_last) {
577 setverdict(fail, "Two RACH in same FN?!?");
578 self.stop;
579 }
580 fn_last := fn;
581
582 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +0100583 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +0100584 alt {
585 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
586 T.stop;
587 }
588 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
589 setverdict(fail, "Unexpected CHAN RQD");
590 self.stop;
591 }
592 [] RSL_CCHAN.receive { repeat; }
593 [] T.timeout {
594 setverdict(fail, "Timeout waiting for CHAN RQD");
595 self.stop;
596 }
597 }
598 }
599 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100600}
Harald Welte8c24c2b2018-02-26 08:31:31 +0100601
602/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
603testcase TC_rach_count() runs on test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100604 f_init(testcasename());
Harald Welte8c24c2b2018-02-26 08:31:31 +0100605 f_init_l1ctl();
606 f_l1_tune(L1CTL);
607
608 var GsmFrameNumber fn_last := 0;
609 for (var integer i := 0; i < 1000; i := i+1) {
610 var OCT1 ra := f_rnd_ra_cs();
611 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
612 if (fn == fn_last) {
613 setverdict(fail, "Two RACH in same FN?!?");
614 self.stop;
615 }
616 fn_last := fn;
617 }
618 var integer rsl_chrqd := 0;
619 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +0100620 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +0100621 alt {
622 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
623 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +0100624 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +0100625 repeat;
626 }
627 [] RSL_CCHAN.receive { repeat; }
628 [] T.timeout { }
629 }
630 if (rsl_chrqd == 1000) {
631 setverdict(pass);
632 } else {
633 setverdict(fail, "Received only ", rsl_chrqd, " out of 1000 RACH");
634 }
Harald Welte70767382018-02-21 12:16:40 +0100635}
636
Harald Welte54a2a2d2018-02-26 09:14:05 +0100637private function f_main_trxc_connect() runs on test_CT {
638 map(self:BB_TRXC, system:BB_TRXC);
639 var Result res;
Harald Welted3a88a62018-03-01 16:04:52 +0100640 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
641 "", -1, -1, {udp:={}}, {});
Harald Welte54a2a2d2018-02-26 09:14:05 +0100642 g_bb_trxc_conn_id := res.connId;
643}
644
645private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100646 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100647 /* tell fake_trx to use a given timing offset for all bursts */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100648 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +0100649 f_sleep(0.5);
650
651 /* Transmit RACH request + wait for confirmation */
652 var OCT1 ra := f_rnd_ra_cs();
653 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
654
655 /* Check for expected result */
656 timer T := 1.5;
657 T.start;
658 alt {
659 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
660 setverdict(pass);
661 }
662 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welteb3e30942018-03-02 10:33:42 +0100663 setverdict(fail, "RACH passed but was expected to be dropped: ", toffs256);
Harald Welte54a2a2d2018-02-26 09:14:05 +0100664 }
665 [] RSL_CCHAN.receive { repeat; }
666 [not expect_pass] T.timeout {
667 setverdict(pass);
668 }
669 [expect_pass] T.timeout {
670 setverdict(fail, "Timeout waiting for CHAN RQD");
671 }
672 }
673}
674
675/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
676testcase TC_rach_max_ta() runs on test_CT {
677 f_init(testcasename());
678 f_init_l1ctl();
679 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +0100680 f_sleep(1.0);
681
682 /* default max-ta is 63 (full range of GSM timing advance */
683
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +0700684 /* We allow early arrival up to 2 symbols */
685 f_rach_toffs(-1*256, true);
686 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +0100687 f_rach_toffs(-10*256, false);
688
689 /* 0 / 32 / 63 bits is legal / permitted */
690 f_rach_toffs(0, true);
691 f_rach_toffs(32*256, true);
692 f_rach_toffs(63*256, true);
693
694 /* more than 63 bits is not legal / permitted */
695 f_rach_toffs(64*256, false);
696 f_rach_toffs(127*256, false);
697}
Harald Welte8c24c2b2018-02-26 08:31:31 +0100698
Harald Welte93640c62018-02-25 16:59:33 +0100699/***********************************************************************
700 * Measurement Processing / Reporting
701 ***********************************************************************/
702
Harald Welte70767382018-02-21 12:16:40 +0100703template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
704 spare := '0'B,
705 lpd := 0,
706 sapi := sapi,
707 c_r := c_r,
708 ea := true
709}
710
711template LapdmFrameB ts_LAPDm_B(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
712 addr := ts_LapdmAddr(sapi, c_r),
713 ctrl := t_LapdmCtrlUI(p),
714 len := 0, /* overwritten */
715 m := false,
716 el := 1,
717 payload := pl
718}
719
720/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
721altstep as_l1_sacch() runs on ConnHdlr {
722 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +0100723 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +0100724 log("SACCH received: ", l1_dl.payload.data_ind.payload);
725 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, 23, 23, 0, 0, omit));
726 var LapdmFrameB lb := valueof(ts_LAPDm_B(0, false, false, enc_GsmRrL3Message(meas_rep)));
727 log("LAPDm: ", lb);
728 var octetstring pl := '0000'O & enc_LapdmFrameB(lb);
Harald Weltef8df4cb2018-03-10 15:15:08 +0100729 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_SACCH(0), pl));
Harald Welte70767382018-02-21 12:16:40 +0100730 repeat;
731 }
732}
733
734altstep as_l1_dcch() runs on ConnHdlr {
735 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +0100736 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +0100737 log("DCCH received: ", l1_dl.payload.data_ind.payload);
738 var octetstring pl := '010301'O;
Harald Weltef8df4cb2018-03-10 15:15:08 +0100739 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), pl));
Harald Welte70767382018-02-21 12:16:40 +0100740 repeat;
741 }
742}
743
744type record MeasElem {
745 uint6_t rxlev,
746 uint3_t rxqual
747}
748
749type record MeasElemFS {
750 MeasElem full,
751 MeasElem sub
752}
753
754type record ConnL1Pars {
755 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +0100756 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +0100757 MeasElemFS meas_ul,
758 int16_t timing_offset_256syms,
759 uint5_t bs_power_level,
760 uint5_t ms_power_level,
761 uint8_t ms_actual_ta
762}
763
764/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
765private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
766 return 63 + (toffs256s/256);
767}
768
769/* build a template for matching measurement results against */
770private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
771 var ConnL1Pars l1p := g_pars.l1_pars;
772 var template RSL_IE_UplinkMeas ul_meas := {
773 len := 3,
774 rfu := '0'B,
775 dtx_d := l1p.dtx_enabled,
776 rxlev_f_u := l1p.meas_ul.full.rxlev,
777 reserved1 := '00'B,
778 rxlev_s_u := l1p.meas_ul.sub.rxlev,
779 reserved2 := '00'B,
780 rxq_f_u := l1p.meas_ul.full.rxqual,
781 rxq_s_u := l1p.meas_ul.sub.rxqual,
782 supp_meas_info := omit
783 };
Harald Welte685d5982018-02-27 20:42:05 +0100784 if (l1p.toa256_enabled) {
785 ul_meas.len := 5;
786 ul_meas.supp_meas_info := int2oct(l1p.timing_offset_256syms, 2);
787 }
Harald Welte70767382018-02-21 12:16:40 +0100788 /* HACK HACK HACK FIXME HACK HACK HACK see https://osmocom.org/issues/2988 */
789 ul_meas.rxlev_f_u := ?;
790 ul_meas.rxlev_s_u := ?;
791 ul_meas.rxq_f_u := ?;
792 ul_meas.rxq_s_u := ?;
793 var template RSL_IE_BS_Power bs_power := {
794 reserved := 0,
795 epc := false,
796 fpc := false,
797 power_level := l1p.bs_power_level
798 };
799 var template RSL_IE_L1Info l1_info := {
800 ms_power_lvl := l1p.ms_power_level,
801 fpc := false,
802 reserved := 0,
803 actual_ta := l1p.ms_actual_ta
804 };
805 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
806 var template uint8_t t_toffs := (offs-1 .. offs+1); /* some tolerance */
807 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
808 ?, t_toffs);
809}
810
811/* verify we regularly receive measurement reports with incrementing numbers */
812altstep as_meas_res() runs on ConnHdlr {
813 var RSL_Message rsl;
814 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
815 /* increment counter of next to-be-expected meas rep */
816 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
817 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +0100818 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +0100819 repeat;
820 }
821 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
822 setverdict(fail, "Received unspecific MEAS RES ", rsl);
823 self.stop;
824 }
825 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
826 setverdict(fail, "Received unexpected MEAS RES ", rsl);
827 self.stop;
828 }
829 [] g_Tmeas_exp.timeout {
830 setverdict(fail, "Didn't receive expected measurement result")
831 self.stop;
832 }
833}
834
835/* Establish dedicated channel: L1CTL + RSL side */
836private function f_est_dchan() runs on ConnHdlr {
837 var GsmFrameNumber fn;
838 var ImmediateAssignment imm_ass;
839 var integer ra := 23;
840
841 fn := f_L1CTL_RACH(L1CTL, ra);
842 /* This arrives on CCHAN, so we cannot test for receiving CHAN RQDhere */
843 //RSL.receive(tr_RSL_CHAN_RQD(int2oct(23,1)));
844
845 /* Activate channel on BTS side */
846 f_rsl_chan_act(g_pars.chan_mode);
847
848 /* Send IMM.ASS via CCHAN */
849 var ChannelDescription ch_desc := {
850 chan_nr := g_pars.chan_nr,
851 tsc := 7,
852 h := false,
853 arfcn := mp_trx0_arfcn,
854 maio_hsn := omit
855 };
856 var MobileAllocation ma := {
857 len := 0,
858 ma := ''B
859 };
860 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
861 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
862
863 /* receive IMM.ASS on MS side */
864 var ImmediateAssignment ia_um;
865 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
866 /* enable dedicated mode */
867 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
868}
869
870/* establish DChan, verify existance + contents of measurement reports */
871function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +0100872 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100873 RSL.clear;
874
875 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-100);
876 g_pars.l1_pars.meas_ul.sub.rxlev := g_pars.l1_pars.meas_ul.full.rxlev;
877 f_trxc_fake_rssi(100);
878
879 g_pars.l1_pars.timing_offset_256syms := 512; /* 2 symbols */
880 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
881
882 f_est_dchan();
883
884 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
885 * RSL measurement reports on Abis side */
886 timer T := 8.0;
887 T.start;
888 alt {
889 [] as_l1_sacch();
890 [] as_meas_res();
891 [] as_l1_dcch();
892 [] L1CTL.receive { repeat; }
893 [g_Tmeas_exp.running] T.timeout {
894 /* as_meas_res() would have done setverdict(fail) / self.stop in case
895 * of any earlier errors, so if we reach this timeout, we're good */
896 setverdict(pass);
897 }
898 [] T.timeout {
899 setverdict(fail, "No MEAS RES received at all");
900 }
901 }
902 f_rsl_chan_deact();
903}
904testcase TC_meas_res_sign_tchf() runs on test_CT {
905 var ConnHdlr vc_conn;
906 var ConnHdlrPars pars;
907 f_init(testcasename());
908 for (var integer tn := 1; tn <= 4; tn := tn+1) {
909 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
910 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
911 vc_conn.done;
912 }
913}
914testcase TC_meas_res_sign_tchh() runs on test_CT {
915 var ConnHdlr vc_conn;
916 var ConnHdlrPars pars;
917 f_init(testcasename());
918 for (var integer ss := 0; ss <= 1; ss := ss+1) {
919 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
920 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
921 vc_conn.done;
922 }
923}
924testcase TC_meas_res_sign_sdcch4() runs on test_CT {
925 var ConnHdlr vc_conn;
926 var ConnHdlrPars pars;
927 f_init(testcasename());
928 for (var integer ss := 0; ss <= 3; ss := ss+1) {
929 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
930 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
931 vc_conn.done;
932 }
933}
934testcase TC_meas_res_sign_sdcch8() runs on test_CT {
935 var ConnHdlr vc_conn;
936 var ConnHdlrPars pars;
937 f_init(testcasename());
938 for (var integer ss := 0; ss <= 7; ss := ss+1) {
939 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
940 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
941 vc_conn.done;
942 }
943}
Harald Welte685d5982018-02-27 20:42:05 +0100944testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
945 var ConnHdlr vc_conn;
946 var ConnHdlrPars pars;
947 f_init(testcasename());
948 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
949 for (var integer ss := 0; ss <= 1; ss := ss+1) {
950 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
951 pars.l1_pars.toa256_enabled := true;
952 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
953 vc_conn.done;
954 }
955}
956
Harald Welte70767382018-02-21 12:16:40 +0100957
958/* Test if a channel without valid uplink bursts generates RSL CONN FAIL IND */
959private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +0100960 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100961 RSL.clear;
962
963 f_est_dchan();
964 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +0100965 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +0100966
967 timer T := 40.0;
968 T.start;
969 alt {
970 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
971 setverdict(pass)
972 }
973 [] RSL.receive { repeat };
974 [] T.timeout {
975 setverdict(fail, "No CONN FAIL IND received");
976 }
977 }
978 f_rsl_chan_deact();
979}
980testcase TC_conn_fail_crit() runs on test_CT {
981 var ConnHdlr vc_conn;
982 var ConnHdlrPars pars;
983 f_init(testcasename());
984 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
985 pars.t_guard := 60.0;
986 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
987 vc_conn.done;
988}
989
Harald Welte93640c62018-02-25 16:59:33 +0100990/***********************************************************************
991 * Paging
992 ***********************************************************************/
993
Harald Welte68e495b2018-02-25 00:05:57 +0100994function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
995 if (tmsi == 'FFFFFFFF'O) {
996 return true;
997 } else {
998 return false;
999 }
1000}
Harald Welte70767382018-02-21 12:16:40 +01001001
Harald Welte68e495b2018-02-25 00:05:57 +01001002altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids)
1003runs on test_CT {
1004 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001005 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01001006 repeat;
1007 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01001008 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01001009 var octetstring without_plen :=
1010 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
1011 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
1012 if (match(rr, tr_PAGING_REQ1)) {
1013 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1014 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1015 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
1016 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1017 }
1018 } else if (match(rr, tr_PAGING_REQ2)) {
1019 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1020 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
1021 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1022 }
1023 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
1024 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1025 }
1026 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
1027 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1028 }
1029 } else if (match(rr, tr_PAGING_REQ3)) {
1030 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1031 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
1032 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1033 }
1034 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
1035 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1036 }
1037 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
1038 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1039 }
1040 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
1041 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1042 }
1043 }
1044 repeat;
1045 }
1046}
1047
1048type record PagingTestCfg {
1049 boolean combined_ccch,
1050 integer bs_ag_blks_res,
1051 float load_factor,
1052 boolean exp_load_ind,
1053 boolean exp_overload,
1054 boolean use_tmsi
1055}
1056
1057type record PagingTestState {
1058 integer num_paging_sent,
1059 integer num_paging_rcv_msgs,
1060 integer num_paging_rcv_ids,
1061 integer num_overload
1062}
1063
1064/* receive + ignore RSL RF RES IND */
1065altstep as_rsl_res_ind() runs on test_CT {
1066 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
1067 repeat;
1068 }
1069}
1070
1071/* Helper function for paging related testing */
1072private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
1073 f_init(testcasename());
1074 f_init_l1ctl();
1075 f_l1_tune(L1CTL);
1076
1077 var PagingTestState st := {
1078 num_paging_sent := 0,
1079 num_paging_rcv_msgs := 0,
1080 num_paging_rcv_ids := 0,
1081 num_overload := 0
1082 };
1083
1084 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
1085 var float max_pch_imsi_per_sec;
1086 if (cfg.use_tmsi) {
1087 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
1088 } else {
1089 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
1090 }
1091 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
1092 var float interval := 1.0 / pch_blocks_per_sec;
1093 log("pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
1094
1095 for (var integer i := 0; i < float2int(20.0/interval); i := i+1) {
1096 /* build mobile Identity */
1097 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
1098 if (cfg.use_tmsi) {
1099 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
1100 } else {
1101 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
1102 }
1103 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
1104 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
1105
1106 /* Send RSL PAGING COMMAND */
1107 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
1108 st.num_paging_sent := st.num_paging_sent + 1;
1109
1110 /* Wait for interval to next PAGING COMMAND */
1111 timer T_itv := interval;
1112 T_itv.start;
1113 alt {
1114 /* check for presence of CCCH LOAD IND (paging load) */
1115 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1116 st.num_overload := st.num_overload + 1;
1117 repeat;
1118 }
1119 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1120 setverdict(fail, "Unexpected PCH Overload");
1121 }
1122 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
1123 log("Rx LOAD_IND");
1124 /* FIXME: analyze/verify interval + contents */
1125 repeat;
1126 }
1127 /* check if paging requests arrive on Um side */
1128 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1129 [] L1CTL.receive { repeat; }
1130 [] T_itv.timeout { }
1131 [] as_rsl_res_ind();
1132 }
1133 }
1134
1135 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
1136 timer T_wait := 18.0;
1137 T_wait.start;
1138 alt {
1139 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1140 [] L1CTL.receive { repeat; }
1141 /* 65535 == empty paging queue, we can terminate*/
1142 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
1143 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
1144 [] T_wait.timeout {
1145 setverdict(fail, "Waiting for empty paging queue");
1146 }
1147 [] as_rsl_res_ind();
1148 }
1149
1150 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
1151 " rcvd_ids=", st.num_paging_rcv_ids);
1152 return st;
1153}
1154
1155/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
1156 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1157 * - that CCCH LOAD IND (PCH) are being generated
1158 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1159testcase TC_paging_imsi_80percent() runs on test_CT {
1160 var PagingTestCfg cfg := {
1161 combined_ccch := true,
1162 bs_ag_blks_res := 1,
1163 load_factor := 0.8,
1164 exp_load_ind := true,
1165 exp_overload := false,
1166 use_tmsi := false
1167 };
1168 var PagingTestState st := f_TC_paging(cfg);
1169 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1170 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1171 st.num_paging_rcv_ids);
1172 } else {
1173 setverdict(pass);
1174 }
1175}
1176
1177/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
1178 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1179 * - that CCCH LOAD IND (PCH) are being generated
1180 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1181testcase TC_paging_tmsi_80percent() runs on test_CT {
1182 var PagingTestCfg cfg := {
1183 combined_ccch := true,
1184 bs_ag_blks_res := 1,
1185 load_factor := 0.8,
1186 exp_load_ind := true,
1187 exp_overload := false,
1188 use_tmsi := true
1189 };
1190 var PagingTestState st := f_TC_paging(cfg);
1191 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1192 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1193 st.num_paging_rcv_ids);
1194 } else {
1195 setverdict(pass);
1196 }
1197}
1198
1199/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
1200 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1201 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1202 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1203testcase TC_paging_imsi_200percent() runs on test_CT {
1204 var PagingTestCfg cfg := {
1205 combined_ccch := true,
1206 bs_ag_blks_res := 1,
1207 load_factor := 2.0,
1208 exp_load_ind := true,
1209 exp_overload := true,
1210 use_tmsi := false
1211 };
1212 var PagingTestState st := f_TC_paging(cfg);
1213 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
1214 * slots and will fully drain that buffer before returning */
1215 var template integer tpl := (st.num_paging_sent*80/100 .. st.num_paging_sent *85/100);
1216 if (not match(st.num_paging_rcv_ids, tpl)) {
1217 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1218 } else {
1219 setverdict(pass);
1220 }
1221}
1222
1223/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
1224 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1225 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1226 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1227testcase TC_paging_tmsi_200percent() runs on test_CT {
1228 var PagingTestCfg cfg := {
1229 combined_ccch := true,
1230 bs_ag_blks_res := 1,
1231 load_factor := 2.0,
1232 exp_load_ind := true,
1233 exp_overload := true,
1234 use_tmsi := true
1235 };
1236 var PagingTestState st := f_TC_paging(cfg);
1237 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
1238 * slots and will fully drain that buffer before returning */
1239 var template integer tpl := (st.num_paging_sent*68/100 .. st.num_paging_sent *72/100);
1240 if (not match(st.num_paging_rcv_ids, tpl)) {
1241 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1242 } else {
1243 setverdict(pass);
1244 }
1245}
1246
1247
Harald Welte93640c62018-02-25 16:59:33 +01001248/***********************************************************************
1249 * Immediate Assignment / AGCH
1250 ***********************************************************************/
1251
Harald Welte68e495b2018-02-25 00:05:57 +01001252testcase TC_imm_ass() runs on test_CT {
1253 f_init(testcasename());
1254 for (var integer i := 0; i < 1000; i := i+1) {
1255 var octetstring ia_enc := f_rnd_octstring(8);
1256 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
1257 f_sleep(0.02);
1258 }
1259 /* FIXME: check if imm.ass arrive on Um side */
1260 /* FIXME: check for DELETE INDICATION */
1261 f_sleep(100.0);
1262}
1263
Harald Welte48494ca2018-02-25 16:59:50 +01001264/***********************************************************************
1265 * BCCH
1266 ***********************************************************************/
1267
1268/* tuple of Frame Number + decoded SI */
1269type record SystemInformationFn {
1270 GsmFrameNumber frame_number,
1271 SystemInformation si
1272}
1273
1274/* an arbitrary-length vector of decoded SI + gsmtap header */
1275type record of SystemInformationFn SystemInformationVector;
1276
1277/* an array of SI-vectors indexed by TC value */
1278type SystemInformationVector SystemInformationVectorPerTc[8];
1279
1280/* determine if a given SI vector contains given SI type at least once */
1281function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1282 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1283 var integer fn_mod51 := arr[i].frame_number mod 51;
1284 if (not bcch_ext and fn_mod51 == 2 or
1285 bcch_ext and fn_mod51 == 6) {
1286 if (arr[i].si.header.message_type == key) {
1287 return true;
1288 }
1289 }
1290 }
1291 return false;
1292}
1293
1294/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
1295function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1296 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
1297 setverdict(fail, "No ", key, " in TC=", tc, "!");
1298 }
1299}
1300
1301/* check if a given SI vector contains given SI type at least once on any TC */
1302function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
1303 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
1304 if (f_si_vecslot_contains(arr[tc], key) or
1305 f_si_vecslot_contains(arr[tc], key, true)) {
1306 return true;
1307 }
1308 }
1309 return false;
1310}
1311
1312/* determine if a given SI vector contains given SI type at least N of M times */
1313function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
1314 var integer count := 0;
1315 if (sizeof(arr) < m) {
1316 setverdict(fail, "Error: Insufficient SI in array");
1317 self.stop;
1318 }
1319 for (var integer i:= 0; i < m; i := i + 1) {
1320 var integer fn_mod51 := arr[i].frame_number mod 51;
1321 if (not bcch_ext and fn_mod51 == 2 or
1322 bcch_ext and fn_mod51 == 6) {
1323 if (arr[i].si.header.message_type == key) {
1324 count := count + 1;
1325 }
1326 }
1327 }
1328 if (count >= n) {
1329 return true;
1330 } else {
1331 return false;
1332 }
1333}
1334
1335/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
1336function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
1337 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
1338 setverdict(fail, "Not ", n, "/", m, " of ", key, " in TC=", tc, "!");
1339 }
1340}
1341
1342/* determine if a given SI vector contains given SI type at least once */
1343function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1344 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1345 var integer fn_mod51 := arr[i].frame_number mod 51;
1346 if (not bcch_ext and fn_mod51 == 2 or
1347 bcch_ext and fn_mod51 == 6) {
1348 if (arr[i].si.header.message_type != key) {
1349 return false;
1350 }
1351 }
1352 }
1353 return true;
1354}
1355
1356/* ensure a given TC slot of the SI vector contains only given SI type */
1357function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1358 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
1359 setverdict(fail, "Not all ", key, " in TC=", tc, "!");
1360 }
1361}
1362
1363/* SI configuration of cell, against which we validate actual SI messages */
1364type set SystemInformationConfig {
1365 boolean bcch_extended,
1366 boolean si1_present,
1367 boolean si2bis_present,
1368 boolean si2ter_present,
1369 boolean si2quater_present,
1370 boolean si7_present,
1371 boolean si8_present,
1372 boolean si9_present,
1373 boolean si13_present,
1374 boolean si13alt_present,
1375 boolean si15_present,
1376 boolean si16_present,
1377 boolean si17_present,
1378 boolean si2n_present,
1379 boolean si21_present,
1380 boolean si22_present
1381}
1382
1383/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
1384function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
1385 var integer i;
1386 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
1387 if (sizeof(si_per_tc[i]) == 0) {
Harald Welte544565a2018-03-02 10:34:08 +01001388 setverdict(fail, "No SI messages for TC=", i);
Harald Welte48494ca2018-02-25 16:59:50 +01001389 }
1390 }
1391 if (cfg.si1_present) {
1392 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
1393 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
1394 * when TC = 0, it can assume that System Information Type 1 is not in use. */
1395 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
1396 /* make sure *ALL* contain SI1 */
1397 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
1398 }
1399 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
1400 /* iii) A SI 2 message will be sent at least every time TC = 1 */
1401 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
1402 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
1403 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
1404 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
1405
1406 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
1407 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
1408 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
1409 * consecutive occurrences of TC = 4. */
1410 if (cfg.si2bis_present and not cfg.si2ter_present) {
1411 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
1412 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
1413 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
1414 } else if (cfg.si2ter_present and cfg.si2bis_present) {
1415 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
1416 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
1417 }
1418
1419 if (cfg.si7_present or cfg.si8_present) {
1420 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
1421 * if System Information type 4 does not contain all information needed for cell
1422 * selection and reselection. */
1423 if (not cfg.bcch_extended) {
1424 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
1425 }
1426 if (cfg.si7_present) {
1427 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
1428 }
1429 if (cfg.si8_present) {
1430 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
1431 }
1432 }
1433
1434 if (cfg.si2quater_present) {
1435 /* iii) System information type 2 quater is sent if needed, as determined by the system
1436 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
1437 * and 2ter are used, otherwise it shall be sent at least once within any of 4
1438 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
1439 * within any of 4 consecutive occurrences of TC = 5. */
1440 if (not (cfg.bcch_extended)) {
1441 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
1442 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
1443 } else {
1444 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
1445 }
1446 } else {
1447 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
1448 }
1449 }
1450 if (cfg.si9_present) {
1451 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
1452 * in system information type 3 as defined in 3GPP TS 44.018. */
1453 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
1454 }
1455 if (cfg.si13_present) {
1456 /* vii) System Information type 13 is only related to the GPRS service. System Information
1457 * Type 13 need only be sent if GPRS support is indicated in one or more of System
1458 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
1459 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
1460 * In the case that the message is sent on the BCCH Norm, it is sent at least once
1461 * within any of 4 consecutive occurrences of TC=4. */
1462 if (not cfg.bcch_extended) {
1463 log("not-bccch-extended");
1464 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
1465 } else {
1466 log("bccch-extended");
1467 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
1468 }
1469 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
1470 setverdict(fail, "Cannot have SI13alt and SI13");
1471 }
1472 }
1473 if (cfg.si16_present or cfg.si17_present) {
1474 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
1475 * should not be sent in a cell where network sharing is used (see rule xv). */
1476 if (cfg.si22_present) {
1477 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
1478 }
1479 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
1480 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
1481 }
1482 if (not cfg.bcch_extended) {
1483 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
1484 }
1485 if (cfg.si16_present) {
1486 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
1487 }
1488 if (cfg.si17_present) {
1489 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
1490 }
1491 }
1492
1493 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
1494 * broadcast information. The frequency with which they are sent is determined by the
1495 * system operator. System Information type 9 identifies the scheduling of System
1496 * Information type 18 and 20 messages. */
1497
1498 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
1499 * Information Type 19 is present, then its scheduling shall be indicated in System
1500 * Information Type 9. */
1501
1502 if (cfg.si15_present) {
1503 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
1504 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
1505 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
1506 * 4 consecutive occurrences of TC = 1. */
1507 if (not cfg.bcch_extended) {
1508 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
1509 } else {
1510 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
1511 }
1512 }
1513 if (cfg.si13alt_present) {
1514 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
1515 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
1516 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
1517 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
1518 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
1519 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
1520 * of TC = 4. */
1521 if (cfg.si13_present) {
1522 testcase.stop("Error: Cannot have SI13alt and SI13");
1523 }
1524 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
1525 setverdict(fail, "Cannot have SI13alt and SI13");
1526 }
1527 if (not cfg.bcch_extended) {
1528 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
1529 } else {
1530 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
1531 }
1532 }
1533 if (cfg.si2n_present) {
1534 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
1535 * as determined by the system operator. In the case that the message is sent on the
1536 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
1537 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
1538 * consecutive occurrences of TC = 4. */
1539 if (not cfg.bcch_extended) {
1540 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
1541 } else {
1542 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
1543 }
1544 }
1545 if (cfg.si21_present) {
1546 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
1547 * determined by the system operator. If Extended Access Barring is in use in the cell
1548 * then this message is sent at least once within any of 4 consecutive occurrences of
1549 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
1550 * cell then this message shall only be sent on BCCH Ext. */
1551 if (not cfg.bcch_extended) {
1552 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
1553 } else {
1554 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
1555 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
1556 setverdict(fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
1557 }
1558 }
1559 }
1560 if (cfg.si22_present) {
1561 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
1562 * should not be sent in a cell where SoLSA is used (see rule viii). System
1563 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
1564 * =2 and TC=6. */
1565 if (cfg.si16_present or cfg.si17_present) {
1566 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
1567 }
1568 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
1569 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
1570 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
1571 }
1572 if (not cfg.bcch_extended) {
1573 testcase.stop("Error: SI22 requires BCCH Extd!");
1574 } else {
1575 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
1576 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
1577 }
1578 }
1579}
1580
1581/* sample Systme Information for specified duration via L1CTL */
1582function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
1583 timer T := duration;
1584 var SystemInformationVectorPerTc si_per_tc;
1585 var L1ctlDlMessage l1_dl;
1586
1587 /* initialize all per-TC vectors empty */
1588 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
1589 si_per_tc[i] := {};
1590 }
1591
1592 /* flush all previous L1 queued msgs */
1593 pt.clear;
1594
1595 T.start;
1596 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001597 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01001598 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
1599 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
1600 log("Ignoring non-RR SI ", l1_dl);
1601 repeat;
1602 }
1603 var SystemInformationFn sig := {
1604 frame_number := l1_dl.dl_info.frame_nr,
1605 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
1606 }
1607 var integer tc := f_gsm_compute_tc(sig.frame_number);
1608 log("SI received at TC=", tc, ": ", sig.si);
1609 /* append to the per-TC bucket */
1610 si_per_tc[tc] := si_per_tc[tc] & { sig };
1611 repeat;
1612 }
1613 [] pt.receive { repeat; }
1614 [] T.timeout { }
1615 }
1616
1617 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
1618 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
1619 }
1620 log("si_per_tc=", si_per_tc);
1621 return si_per_tc;
1622}
1623
1624/* helper function: Set given SI via RSL + validate scheduling.
1625 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
1626function f_TC_si_sched() runs on test_CT {
1627 var SystemInformationVectorPerTc si_per_tc;
1628 f_init_l1ctl();
1629 f_l1_tune(L1CTL);
1630
1631 /* Sample + Validate Scheduling */
1632 si_per_tc := f_l1_sample_si(L1CTL);
1633 f_validate_si_scheduling(si_cfg, si_per_tc);
1634
1635 setverdict(pass);
1636}
1637
1638testcase TC_si_sched_default() runs on test_CT {
1639 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01001640 /* 2+3+4 are mandatory and set in f_init() */
1641 f_TC_si_sched();
1642}
1643
1644testcase TC_si_sched_1() runs on test_CT {
1645 f_init();
1646 si_cfg.si1_present := true;
1647 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01001648 f_TC_si_sched();
1649}
1650
1651testcase TC_si_sched_2bis() runs on test_CT {
1652 f_init();
1653 si_cfg.si2bis_present := true;
1654 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
1655 f_TC_si_sched();
1656}
1657
1658testcase TC_si_sched_2ter() runs on test_CT {
1659 f_init();
1660 si_cfg.si2ter_present := true;
1661 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
1662 f_TC_si_sched();
1663}
1664
1665testcase TC_si_sched_2ter_2bis() runs on test_CT {
1666 f_init();
1667 si_cfg.si2bis_present := true;
1668 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
1669 si_cfg.si2ter_present := true;
1670 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
1671 f_TC_si_sched();
1672}
1673
1674testcase TC_si_sched_2quater() runs on test_CT {
1675 f_init();
1676 si_cfg.si2quater_present := true;
1677 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
1678 f_TC_si_sched();
1679}
1680
1681testcase TC_si_sched_13() runs on test_CT {
1682 f_init();
1683 si_cfg.si13_present := true;
1684 //f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, fixme);
1685 f_TC_si_sched();
1686}
1687
1688testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
1689 f_init();
1690 si_cfg.si2bis_present := true;
1691 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
1692 si_cfg.si2ter_present := true;
1693 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
1694 si_cfg.si2quater_present := true;
1695 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
1696 si_cfg.si13_present := true;
1697 //f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, fixme);
1698 f_TC_si_sched();
1699}
1700
1701
Harald Welte68e495b2018-02-25 00:05:57 +01001702testcase TC_bcch_info() runs on test_CT {
1703 f_init(testcasename());
1704 /* FIXME: enable / disable individual BCCH info */
1705 //ts_RSL_BCCH_INFO(si_type, info);
1706 /* expect no ERROR REPORT after either of them *
1707 /* negative test: ensure ERROR REPORT on unsupported types */
1708}
1709
Harald Welte93640c62018-02-25 16:59:33 +01001710/***********************************************************************
1711 * Low-Level Protocol Errors / ERROR REPORT
1712 ***********************************************************************/
1713
Harald Welte01d982c2018-02-25 01:31:40 +01001714private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
1715 timer T := 5.0;
1716 T.start;
1717 alt {
1718 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
1719 setverdict(pass);
1720 }
1721 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
1722 setverdict(fail, "Wrong cause in RSL ERR REP");
1723 }
1724 [] RSL_CCHAN.receive {
1725 repeat;
1726 }
1727 [] T.timeout {
1728 setverdict(fail, "Timeout waiting for RSL ERR REP");
1729 }
1730 }
1731}
1732
1733/* Provoke a protocol error (message too short) and match on ERROR REPORT */
1734testcase TC_rsl_protocol_error() runs on test_CT {
1735 f_init(testcasename());
1736 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
1737 rsl.ies := omit;
1738 RSL_CCHAN.send(ts_RSL_UD(rsl));
1739
1740 f_exp_err_rep(RSL_ERR_PROTO);
1741}
1742
1743/* Provoke a mandatory IE error and match on ERROR REPORT */
1744testcase TC_rsl_mand_ie_error() runs on test_CT {
1745 f_init(testcasename());
1746
1747 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
1748 rsl.ies := { rsl.ies[0] };
1749 RSL_CCHAN.send(ts_RSL_UD(rsl));
1750
1751 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
1752}
1753
1754/* Provoke an IE content error and match on ERROR REPORT */
1755testcase TC_rsl_ie_content_error() runs on test_CT {
1756 f_init(testcasename());
1757 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
1758 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
1759 RSL_CCHAN.send(ts_RSL_UD(rsl));
1760
1761 f_exp_err_rep(RSL_ERR_IE_CONTENT);
1762}
1763
Harald Welte93640c62018-02-25 16:59:33 +01001764/***********************************************************************
1765 * IPA CRCX/MDCX/DLCS media stream handling
1766 ***********************************************************************/
1767
Harald Weltea871a382018-02-25 02:03:14 +01001768/* Send IPA DLCX to inactive lchan */
1769function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01001770 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
1771 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01001772}
1773testcase TC_ipa_dlcx_not_active() runs on test_CT {
1774 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1775 f_init(testcasename());
1776 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
1777 vc_conn.done;
1778}
Harald Welte68e495b2018-02-25 00:05:57 +01001779
Harald Weltea3f1df92018-02-25 12:49:55 +01001780/* Send IPA CRCX twice to inactive lchan */
1781function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
1782 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
1783 "IPA CRCX ACK");
1784 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
1785 "IPA CRCX NACK");
1786}
1787testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
1788 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1789 f_init(testcasename());
1790 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
1791 vc_conn.done;
1792}
1793
1794/* Regular sequence of CRCX/MDCX/DLCX */
1795function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
1796 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
1797 "IPA CRCX ACK");
1798 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
1799 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
1800 var uint7_t rtp_pt2 := f_rnd_int(127);
1801 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
1802 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
1803 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
1804 "IPA MDCX ACK");
1805 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
1806 "IPA DLCX ACK");
1807}
1808testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
1809 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1810 f_init(testcasename());
1811 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
1812 vc_conn.done;
1813}
1814
Harald Welte3ae11da2018-02-25 13:36:06 +01001815/* Sequence of CRCX, 2x MDCX, DLCX */
1816function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
1817 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
1818 "IPA CRCX ACK");
1819 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
1820 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
1821 var uint7_t rtp_pt2 := f_rnd_int(127);
1822 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
1823 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
1824 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
1825 "IPA MDCX ACK");
1826 /* Second MDCX */
1827 remote_ip := f_rnd_int(c_UINT32_MAX);
1828 remote_port := f_rnd_int(c_UINT16_MAX);
1829 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
1830 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
1831 "IPA MDCX ACK");
1832 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
1833 "IPA DLCX ACK");
1834}
1835testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
1836 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1837 f_init(testcasename());
1838 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
1839 vc_conn.done;
1840}
1841
Harald Welte9912eb52018-02-25 13:30:15 +01001842/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
1843function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
1844 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
1845 "IPA CRCX NACK");
1846}
1847testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
1848 var ConnHdlrPars pars;
1849 var ConnHdlr vc_conn;
1850 f_init(testcasename());
1851
1852 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
1853 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
1854 vc_conn.done;
1855
1856 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
1857 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
1858 vc_conn.done;
1859}
1860
Harald Weltea3f1df92018-02-25 12:49:55 +01001861
Harald Welte883340c2018-02-28 18:59:29 +01001862/***********************************************************************
1863 * PCU Socket related tests
1864 ***********************************************************************/
1865
1866private function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
1867runs on test_CT {
1868 timer T := 3.0;
1869
1870 /* we don't expect any RTS.req before PDCH are active */
1871 T.start;
1872 alt {
1873 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
1874 setverdict(fail, "PCU RTS.req before PDCH active?");
1875 self.stop;
1876 }
1877 [] PCU.receive { repeat; }
1878 [] T.timeout { }
1879 }
1880
1881 /* Send PDCH activate request for known PDCH timeslot */
1882 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
1883
1884 /* we now expect RTS.req for this timeslot (only) */
1885 T.start;
1886 alt {
1887 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
1888 setverdict(pass);
1889 }
1890 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
1891 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
1892 setverdict(fail, "Unexpected RTS.req for supposedly failing activation");
1893 self.stop;
1894 }
1895 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
1896 setverdict(fail, "RTS.req for wrong TRX/TS");
1897 self.stop;
1898 }
1899 [] PCU.receive { repeat; }
1900 [exp_success] T.timeout {
1901 setverdict(fail, "Timeout waiting for PCU RTS.req");
1902 }
1903 [not exp_success] T.timeout {
1904 setverdict(pass);
1905 }
1906 }
1907}
1908
1909private function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
1910runs on test_CT {
1911 timer T := 3.0;
1912
1913 /* Send PDCH activate request for known PDCH timeslot */
1914 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
1915
1916 PCU.clear;
1917 /* we now expect no RTS.req for this timeslot */
1918 T.start;
1919 alt {
1920 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
1921 setverdict(fail, "Received unexpected PCU RTS.req");
1922 self.stop;
1923 }
1924 [] PCU.receive { repeat; }
1925 [] T.timeout {
1926 setverdict(pass);
1927 }
1928 }
1929}
1930
1931/* PDCH activation via PCU socket; check for presence of RTS.req */
1932testcase TC_pcu_act_req() runs on test_CT {
1933 f_init();
1934 f_TC_pcu_act_req(0, 0, 7, true);
1935}
1936
1937/* PDCH activation via PCU socket on non-PDCU timeslot */
1938testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
1939 f_init();
1940 f_TC_pcu_act_req(0, 0, 1, false);
1941}
1942
1943/* PDCH activation via PCU socket on wrong BTS */
1944testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
1945 f_init();
1946 f_TC_pcu_act_req(23, 0, 7, false);
1947}
1948
1949/* PDCH activation via PCU socket on wrong TRX */
1950testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
1951 f_init();
1952 f_TC_pcu_act_req(0, 23, 7, false);
1953}
1954
1955/* PDCH deactivation via PCU socket; check for absence of RTS.req */
1956testcase TC_pcu_deact_req() runs on test_CT {
1957 f_init();
1958 /* Activate PDCH */
1959 f_TC_pcu_act_req(0, 0, 7, true);
1960 f_sleep(1.0);
1961 /* and De-Activate again */
1962 f_TC_pcu_deact_req(0, 0, 7);
1963}
1964
1965/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
1966testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
1967 f_init();
1968 f_TC_pcu_deact_req(0, 0, 1);
1969}
1970
1971/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
1972testcase TC_pcu_ver_si13() runs on test_CT {
1973 const octetstring si13 := '00010203040506070909'O;
1974 var PCUIF_send_data sd;
1975 timer T:= 3.0;
1976 f_init();
1977
1978 /* Set SI13 via RSL */
1979 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
1980 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, "BTS_Test v23")));
1981 T.start;
1982 alt {
1983 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
1984 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
1985 setverdict(pass);
1986 } else {
1987 repeat;
1988 }
1989 }
1990 [] PCU.receive { repeat; }
1991 [] T.timeout {
1992 setverdict(fail, "Timeout waiting for SI13");
1993 self.stop;
1994 }
1995 }
1996}
1997
1998private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
1999
2000/* helper function to send a PCU DATA.req */
2001private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2002 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
2003runs on test_CT
2004{
2005 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
2006 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
2007}
2008
2009/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
2010private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2011 PCUIF_Sapi sapi, octetstring data)
2012runs on test_CT
2013{
2014 var PCUIF_send_data sd;
2015
2016 timer T := 3.0;
2017 T.start;
2018 alt {
2019 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2020 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2021 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2022 sd.data.u.rts_req.fn, sapi, data);
2023 }
2024 [] PCU.receive { repeat; }
2025 [] T.timeout {
2026 setverdict(fail, "Timeout waiting for RTS.ind");
2027 }
2028 }
2029}
2030
2031/* Send DATA.req on invalid BTS */
2032testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
2033 f_init();
2034 f_TC_pcu_act_req(0, 0, 7, true);
2035 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2036 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2037 f_sleep(10.0);
2038}
2039
2040/* Send DATA.req on invalid TRX */
2041testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
2042 f_init();
2043 f_TC_pcu_act_req(0, 0, 7, true);
2044 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2045 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2046 f_sleep(10.0);
2047}
2048
2049/* Send DATA.req on invalid timeslot */
2050testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
2051 f_init();
2052 f_TC_pcu_act_req(0, 0, 7, true);
2053 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2054 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2055 f_sleep(10.0);
2056}
2057
2058/* Send DATA.req on timeslot that hasn't been activated */
2059testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
2060 f_init();
2061 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2062 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2063 f_sleep(2.0);
2064}
2065
2066testcase TC_pcu_data_req_pdtch() runs on test_CT {
2067 f_init();
2068 f_TC_pcu_act_req(0, 0, 7, true);
2069 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2070 /* FIXME: how to check this was actually sent */
2071 f_sleep(2.0);
2072}
2073
2074testcase TC_pcu_data_req_ptcch() runs on test_CT {
2075 f_init();
2076 f_TC_pcu_act_req(0, 0, 7, true);
2077 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
2078 /* FIXME: how to check this was actually sent */
2079 f_sleep(2.0);
2080}
2081
2082/* Send AGCH from PCU; check it appears on Um side */
2083testcase TC_pcu_data_req_agch() runs on test_CT {
2084 timer T := 3.0;
2085 f_init();
2086 f_init_l1ctl();
2087 f_l1_tune(L1CTL);
2088
2089 f_TC_pcu_act_req(0, 0, 7, true);
2090 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
2091
2092 T.start;
2093 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002094 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01002095 setverdict(pass);
2096 }
2097 [] L1CTL.receive { repeat; }
2098 [] T.timeout {
2099 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2100 }
2101 }
2102}
2103
2104/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
2105testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
2106 var octetstring imm_ass := f_rnd_octstring(23);
2107 f_init();
2108 f_init_l1ctl();
2109 f_l1_tune(L1CTL);
2110
2111 /* append 3 last imsi digits so BTS can compute pagng group */
2112 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
2113
2114 timer T := 0.5;
2115 T.start;
2116 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002117 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01002118 /* TODO: verify paging group */
2119 setverdict(pass);
2120 }
2121 [] L1CTL.receive { repeat; }
2122 [] T.timeout {
2123 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2124 }
2125 }
2126}
2127
2128/* Send RACH from Um side, expect it to show up on PCU socket */
2129testcase TC_pcu_rach_content() runs on test_CT {
2130 f_init();
2131 f_init_l1ctl();
2132 f_l1_tune(L1CTL);
2133
2134 var GsmFrameNumber fn_last := 0;
2135 for (var integer i := 0; i < 1000; i := i+1) {
2136 var OCT1 ra := f_rnd_ra_ps();
2137 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
2138 if (fn == fn_last) {
2139 setverdict(fail, "Two RACH in same FN?!?");
2140 self.stop;
2141 }
2142 fn_last := fn;
2143
2144 timer T := 2.0;
2145 T.start;
2146 alt {
2147 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
2148 T.stop;
2149 }
2150 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
2151 setverdict(fail, "Unexpected RACH IND");
2152 self.stop;
2153 }
2154 [] PCU.receive { repeat; }
2155 [] T.timeout {
2156 setverdict(fail, "Timeout waiting for RACH IND");
2157 self.stop;
2158 }
2159 }
2160 }
2161 setverdict(pass);
2162}
2163
2164private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
2165 var integer strlen := lengthof(str);
2166 for (var integer i := 0; i < len-strlen; i := i+1) {
2167 str := str & pad;
2168 }
2169 return str;
2170}
2171
2172/* Send PAGING via RSL, expect it to shw up on PCU socket */
2173testcase TC_pcu_paging_from_rsl() runs on test_CT {
2174 f_init();
2175
2176 for (var integer i := 0; i < 100; i := i+1) {
2177 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2178 timer T := 3.0;
2179 if (i < 50) {
2180 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2181 } else {
2182 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
2183 }
2184 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2185 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2186 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
2187
2188 /* Send RSL PAGING COMMAND */
2189 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
2190 T.start;
2191 alt {
2192 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
2193 }
2194 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
2195 setverdict(fail, "Unexpected PAGING REQ");
2196 self.stop;
2197 }
2198 [] PCU.receive { repeat; }
2199 [] T.timeout {
2200 setverdict(fail, "Timeout waiting for PAGING REQ");
2201 self.stop;
2202 }
2203 }
2204 }
2205 setverdict(pass);
2206}
2207
2208
Harald Welte68e495b2018-02-25 00:05:57 +01002209/* TODO Areas:
2210
2211* channel activation
2212** with BS_Power / MS_Power, bypassing power control loop
2213** on primary vs. secondary TRX
2214** with encryption from initial activation on
2215** with timing advance from initial activation on
2216* mode modify
2217** encryption
2218** multirate
2219* check DEACTIVATE SACCH
2220* encryption command / intricate logic about tx-only/tx+rx/...
2221** unsupported algorithm
2222* handover detection
2223* MS Power Control
2224* BS Power Control
2225* Physical Context
2226* SACCH info modify
Harald Welte68e495b2018-02-25 00:05:57 +01002227* CCCH Load Indication for PCH and RACH
2228* Delete Indication on AGCH overflow
2229* SMS Broadcast Req / Cmd / CBCH LOad Ind
2230* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01002231* error handling
2232* discriminator error
2233** type error
2234** sequence error
2235** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01002236* PCU interface
2237** TIME_IND from BTS->PCU
2238** DATA_IND from BTS->PCU
2239** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01002240
2241*/
Harald Welte70767382018-02-21 12:16:40 +01002242
2243control {
2244 execute( TC_chan_act_stress() );
2245 execute( TC_chan_act_react() );
2246 execute( TC_chan_deact_not_active() );
2247 execute( TC_chan_act_wrong_nr() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01002248 execute( TC_rach_content() );
2249 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01002250 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01002251 execute( TC_meas_res_sign_tchf() );
2252 execute( TC_meas_res_sign_tchh() );
2253 execute( TC_meas_res_sign_sdcch4() );
2254 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01002255 execute( TC_meas_res_sign_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01002256 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01002257 execute( TC_paging_imsi_80percent() );
2258 execute( TC_paging_tmsi_80percent() );
2259 execute( TC_paging_imsi_200percent() );
2260 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01002261 execute( TC_rsl_protocol_error() );
2262 execute( TC_rsl_mand_ie_error() );
2263 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01002264 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01002265 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01002266 execute( TC_si_sched_2bis() );
2267 execute( TC_si_sched_2ter() );
2268 execute( TC_si_sched_2ter_2bis() );
2269 execute( TC_si_sched_2quater() );
2270 execute( TC_si_sched_13() );
2271 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01002272 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01002273 execute( TC_ipa_crcx_twice_not_active() );
2274 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01002275 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01002276 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01002277
2278 execute( TC_pcu_act_req() );
2279 execute( TC_pcu_act_req_wrong_ts() );
2280 execute( TC_pcu_act_req_wrong_bts() );
2281 execute( TC_pcu_act_req_wrong_trx() );
2282 execute( TC_pcu_deact_req() );
2283 execute( TC_pcu_deact_req_wrong_ts() );
2284 execute( TC_pcu_ver_si13() );
2285 execute( TC_pcu_data_req_wrong_bts() );
2286 execute( TC_pcu_data_req_wrong_trx() );
2287 execute( TC_pcu_data_req_wrong_ts() );
2288 execute( TC_pcu_data_req_ts_inactive() );
2289 execute( TC_pcu_data_req_pdtch() );
2290 execute( TC_pcu_data_req_ptcch() );
2291 execute( TC_pcu_data_req_agch() );
2292 execute( TC_pcu_data_req_imm_ass_pch() );
2293 execute( TC_pcu_rach_content() );
2294 execute( TC_pcu_paging_from_rsl() );
Harald Welte70767382018-02-21 12:16:40 +01002295}
2296
2297
2298}