blob: 32269e2cad232a5e1a2d06d85a0891a9d63501a3 [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 := {
131 max_retrans := RACH_MAX_RETRANS_1,
132 tx_integer := '0000'B, /* 3 slots */
133 cell_barr_access := false,
134 re_not_allowed := true,
135 acc := '1111111111111111'B
136};
137
Harald Weltef10153f2018-02-25 16:34:05 +0100138template (value) CellSelectionParameters ts_CellSelPar_default := {
139 cell_resel_hyst_2dB := 0,
140 ms_txpwr_max_cch := 0,
141 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 Welte3778acc2018-03-09 19:32:31 +0100152template SystemInformation ts_SI3_default := {
153 header := t_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,
173 radio_link_tout_div4 := 4/4
174 },
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 Welte3778acc2018-03-09 19:32:31 +0100182template SystemInformation ts_SI2_default := {
183 header := t_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 Welte3778acc2018-03-09 19:32:31 +0100193template SystemInformation ts_SI4_default := {
194 header := t_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);
239 g_pcu_conn_id := f_pcuif_connect(PCU, mp_pcu_socket);
240
241 T.start;
242 alt {
243 [] PCU.receive(t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_INFO_IND)) -> value sd {
244 g_pcu_last_info := sd.data;
245 }
246 [] T.timeout {
247 setverdict(fail, "Timeout waiting for PCU INFO_IND");
248 self.stop;
249 }
250 }
251}
252
Harald Welte70767382018-02-21 12:16:40 +0100253/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100254function f_init(charstring id := "BTS-Test") runs on test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100255 f_init_rsl(id);
256 RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
Harald Welte2d142592018-02-25 13:19:44 +0100257 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100258 f_init_vty(id);
Harald Welte7484fc42018-02-24 14:09:45 +0100259
260 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100261 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
262 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
263 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
264 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100265
Harald Welte883340c2018-02-28 18:59:29 +0100266 f_init_pcu(id);
267
Harald Welte57fe8232018-02-26 17:52:50 +0100268 /* start with a default moderate timing offset equalling TA=2 */
269 f_main_trxc_connect();
Harald Welteef3e1c92018-02-28 23:40:14 +0100270 f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Harald Welte70767382018-02-21 12:16:40 +0100271}
272
Harald Welte68e495b2018-02-25 00:05:57 +0100273/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
274function f_init_l1ctl() runs on test_CT {
275 map(self:L1CTL, system:L1CTL);
276 f_connect_reset(L1CTL);
277}
278
Harald Welte70767382018-02-21 12:16:40 +0100279type function void_fn(charstring id) runs on ConnHdlr;
280
281/* create a new test component */
282function f_start_handler(void_fn fn, ConnHdlrPars pars)
283runs on test_CT return ConnHdlr {
284 var charstring id := testcasename();
285 var ConnHdlr vc_conn;
286
287 vc_conn := ConnHdlr.create(id);
288 /* connect to RSL Emulation main component */
289 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
290 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
291
292 vc_conn.start(f_handler_init(fn, id, pars));
293 return vc_conn;
294}
295
Harald Welte7484fc42018-02-24 14:09:45 +0100296template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
297 streamId := sid,
298 rsl := rsl
299}
300
301template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
302 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
303 streamId := sid,
304 rsl := rsl
305}
306
Harald Welte70767382018-02-21 12:16:40 +0100307private altstep as_Tguard() runs on ConnHdlr {
308 [] g_Tguard.timeout {
309 setverdict(fail, "Tguard timeout");
310 self.stop;
311 }
312}
313
Harald Welte68e495b2018-02-25 00:05:57 +0100314private function f_l1_tune(L1CTL_PT L1CTL) {
Harald Welte70767382018-02-21 12:16:40 +0100315 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED);
316}
317
318private function f_trxc_connect() runs on ConnHdlr {
319 map(self:BB_TRXC, system:BB_TRXC);
320 var Result res;
Harald Weltea4d8f352018-03-01 15:47:20 +0100321 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
322 "", -1, -1, {udp:={}}, {});
Harald Welte70767382018-02-21 12:16:40 +0100323 g_bb_trxc_conn_id := res.connId;
324}
325
326private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Welteef3e1c92018-02-28 23:40:14 +0100327 f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100328}
329
330private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Welteef3e1c92018-02-28 23:40:14 +0100331 f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100332}
333
334/* first function started in ConnHdlr component */
335private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
336runs on ConnHdlr {
337 g_pars := pars;
338 g_chan_nr := pars.chan_nr;
339
340 map(self:L1CTL, system:L1CTL);
341 f_connect_reset(L1CTL);
342
343 f_trxc_connect();
344
345 g_Tguard.start(pars.t_guard);
346 activate(as_Tguard());
347
348 f_rslem_register(0, pars.chan_nr);
349
350 /* call the user-supplied test case function */
351 fn.apply(id);
352}
353
Harald Welte1eba3742018-02-25 12:48:14 +0100354function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id)
355runs on ConnHdlr {
356 timer T := 3.0;
357 RSL.send(tx);
358 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100359 alt {
Harald Welte1eba3742018-02-25 12:48:14 +0100360 [] RSL.receive(exp_rx) {
361 T.stop;
362 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100363 }
Harald Welte1eba3742018-02-25 12:48:14 +0100364 [] T.timeout {
365 setverdict(fail, "Timeout expecting " & id);
366 self.stop;
367 }
368 [] RSL.receive {
369 setverdict(fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100370 }
371 }
372}
373
Harald Welte1eba3742018-02-25 12:48:14 +0100374function f_rsl_chan_act(RSL_IE_ChannelMode mode) runs on ConnHdlr {
375 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
376 "RSL CHAN ACT");
377}
378
Harald Welte70767382018-02-21 12:16:40 +0100379function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100380 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
381 "RF CHAN REL");
Harald Welte70767382018-02-21 12:16:40 +0100382}
383
Harald Welte70767382018-02-21 12:16:40 +0100384private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
385 template RSL_IE_ChannelMode chan_mode,
386 float t_guard := 20.0) := {
387 chan_nr := valueof(chan_nr),
388 chan_mode := valueof(chan_mode),
389 t_guard := t_guard,
390 l1_pars := {
391 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100392 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100393 meas_ul := {
394 full := {
395 rxlev := dbm2rxlev(-53),
396 rxqual := 0
397 },
398 sub := {
399 rxlev := dbm2rxlev(-53),
400 rxqual := 0
401 }
402 },
403 timing_offset_256syms := 0,
404 bs_power_level := 0,
405 ms_power_level := 0,
406 ms_actual_ta := 0
407 }
408}
409
Harald Welte93640c62018-02-25 16:59:33 +0100410/***********************************************************************
411 * Channel Activation / Deactivation
412 ***********************************************************************/
413
Harald Welte70767382018-02-21 12:16:40 +0100414/* Stress test: Do 500 channel activations/deactivations in rapid succession */
415function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
416 for (var integer i := 0; i < 500; i := i+1) {
417 f_rsl_chan_act(g_pars.chan_mode);
418 f_rsl_chan_deact();
419 }
420 setverdict(pass);
421}
422testcase TC_chan_act_stress() runs on test_CT {
423 var ConnHdlr vc_conn;
424 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
425 f_init(testcasename());
426 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
427 vc_conn.done;
428}
429
430/* Test if re-activation of an already active channel fails as expected */
431function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
432 f_rsl_chan_act(g_pars.chan_mode);
433 /* attempt to activate the same lchan again -> expect reject */
434 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
435 alt {
436 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
437 setverdict(fail, "Unexpected CHAN ACT ACK on double activation");
438 }
439 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
440 setverdict(pass);
441 }
442 }
443 f_rsl_chan_deact();
444}
445testcase TC_chan_act_react() runs on test_CT {
446 var ConnHdlr vc_conn;
447 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
448 f_init(testcasename());
449 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
450 vc_conn.done;
451}
452
453/* Attempt to de-activate a channel that's not active */
454function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
455 timer T := 3.0;
456 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
457 T.start;
458 alt {
459 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
460 setverdict(pass);
461 }
462 [] T.timeout {
463 setverdict(fail, "Timeout expecting RF_CHAN_REL_ACK");
464 }
465 }
466}
467testcase TC_chan_deact_not_active() runs on test_CT {
468 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
469 f_init(testcasename());
470 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
471 vc_conn.done;
472}
473
474/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
475function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
476 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
477 alt {
478 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
479 setverdict(fail, "Unexpected CHAN ACT ACK");
480 }
481 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
482 setverdict(pass);
483 }
484 }
485}
486private type record WrongChanNrCase {
487 RslChannelNr chan_nr,
488 charstring description
489}
490private type record of WrongChanNrCase WrongChanNrCases;
491private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
492 chan_nr := chan_nr,
493 description := desc
494}
495
496testcase TC_chan_act_wrong_nr() runs on test_CT {
497 var ConnHdlr vc_conn;
498 var ConnHdlrPars pars;
499
500 f_init(testcasename());
501
502 var WrongChanNrCases wrong := {
503 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
504 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
505 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
506 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
507 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
508 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
509 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
510 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
511 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
512 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
513 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
514 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
515 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
516 };
517
518 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
519 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
520 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
521 vc_conn.done;
522 }
523}
524
Harald Welte93640c62018-02-25 16:59:33 +0100525/***********************************************************************
526 * RACH Handling
527 ***********************************************************************/
528
Harald Welte8c24c2b2018-02-26 08:31:31 +0100529/* like L1SAP_IS_PACKET_RACH */
530private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +0100531 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +0100532 return true;
533 }
534 return false;
535}
536
537/* generate a random RACH for circuit-switched */
538private function f_rnd_ra_cs() return OCT1 {
539 var OCT1 ra;
540 do {
541 ra := f_rnd_octstring(1);
542 } while (ra_is_ps(ra));
543 return ra;
544}
545
Harald Welte883340c2018-02-28 18:59:29 +0100546/* generate a random RACH for packet-switched */
547private function f_rnd_ra_ps() return OCT1 {
548 var OCT1 ra;
549 do {
550 ra := f_rnd_octstring(1);
551 } while (not ra_is_ps(ra));
552 return ra;
553}
554
Harald Welte8c24c2b2018-02-26 08:31:31 +0100555/* Send 1000 RACH requests and check their RA+FN on the RSL side */
556testcase TC_rach_content() runs on test_CT {
557 f_init(testcasename());
558 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +0100559 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100560
Harald Welte8c24c2b2018-02-26 08:31:31 +0100561 var GsmFrameNumber fn_last := 0;
562 for (var integer i := 0; i < 1000; i := i+1) {
563 var OCT1 ra := f_rnd_ra_cs();
564 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
565 if (fn == fn_last) {
566 setverdict(fail, "Two RACH in same FN?!?");
567 self.stop;
568 }
569 fn_last := fn;
570
571 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +0100572 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +0100573 alt {
574 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
575 T.stop;
576 }
577 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
578 setverdict(fail, "Unexpected CHAN RQD");
579 self.stop;
580 }
581 [] RSL_CCHAN.receive { repeat; }
582 [] T.timeout {
583 setverdict(fail, "Timeout waiting for CHAN RQD");
584 self.stop;
585 }
586 }
587 }
588 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100589}
Harald Welte8c24c2b2018-02-26 08:31:31 +0100590
591/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
592testcase TC_rach_count() runs on test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100593 f_init(testcasename());
Harald Welte8c24c2b2018-02-26 08:31:31 +0100594 f_init_l1ctl();
595 f_l1_tune(L1CTL);
596
597 var GsmFrameNumber fn_last := 0;
598 for (var integer i := 0; i < 1000; i := i+1) {
599 var OCT1 ra := f_rnd_ra_cs();
600 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
601 if (fn == fn_last) {
602 setverdict(fail, "Two RACH in same FN?!?");
603 self.stop;
604 }
605 fn_last := fn;
606 }
607 var integer rsl_chrqd := 0;
608 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +0100609 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +0100610 alt {
611 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
612 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +0100613 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +0100614 repeat;
615 }
616 [] RSL_CCHAN.receive { repeat; }
617 [] T.timeout { }
618 }
619 if (rsl_chrqd == 1000) {
620 setverdict(pass);
621 } else {
622 setverdict(fail, "Received only ", rsl_chrqd, " out of 1000 RACH");
623 }
Harald Welte70767382018-02-21 12:16:40 +0100624}
625
Harald Welte54a2a2d2018-02-26 09:14:05 +0100626private function f_main_trxc_connect() runs on test_CT {
627 map(self:BB_TRXC, system:BB_TRXC);
628 var Result res;
Harald Welted3a88a62018-03-01 16:04:52 +0100629 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
630 "", -1, -1, {udp:={}}, {});
Harald Welte54a2a2d2018-02-26 09:14:05 +0100631 g_bb_trxc_conn_id := res.connId;
632}
633
634private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
635 /* tell fake_trx to use a given timing offset for all bursts */
Harald Welteef3e1c92018-02-28 23:40:14 +0100636 f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +0100637 f_sleep(0.5);
638
639 /* Transmit RACH request + wait for confirmation */
640 var OCT1 ra := f_rnd_ra_cs();
641 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
642
643 /* Check for expected result */
644 timer T := 1.5;
645 T.start;
646 alt {
647 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
648 setverdict(pass);
649 }
650 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welteb3e30942018-03-02 10:33:42 +0100651 setverdict(fail, "RACH passed but was expected to be dropped: ", toffs256);
Harald Welte54a2a2d2018-02-26 09:14:05 +0100652 }
653 [] RSL_CCHAN.receive { repeat; }
654 [not expect_pass] T.timeout {
655 setverdict(pass);
656 }
657 [expect_pass] T.timeout {
658 setverdict(fail, "Timeout waiting for CHAN RQD");
659 }
660 }
661}
662
663/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
664testcase TC_rach_max_ta() runs on test_CT {
665 f_init(testcasename());
666 f_init_l1ctl();
667 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +0100668 f_sleep(1.0);
669
670 /* default max-ta is 63 (full range of GSM timing advance */
671
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +0700672 /* We allow early arrival up to 2 symbols */
673 f_rach_toffs(-1*256, true);
674 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +0100675 f_rach_toffs(-10*256, false);
676
677 /* 0 / 32 / 63 bits is legal / permitted */
678 f_rach_toffs(0, true);
679 f_rach_toffs(32*256, true);
680 f_rach_toffs(63*256, true);
681
682 /* more than 63 bits is not legal / permitted */
683 f_rach_toffs(64*256, false);
684 f_rach_toffs(127*256, false);
685}
Harald Welte8c24c2b2018-02-26 08:31:31 +0100686
Harald Welte93640c62018-02-25 16:59:33 +0100687/***********************************************************************
688 * Measurement Processing / Reporting
689 ***********************************************************************/
690
Harald Welte70767382018-02-21 12:16:40 +0100691template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
692 spare := '0'B,
693 lpd := 0,
694 sapi := sapi,
695 c_r := c_r,
696 ea := true
697}
698
699template LapdmFrameB ts_LAPDm_B(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
700 addr := ts_LapdmAddr(sapi, c_r),
701 ctrl := t_LapdmCtrlUI(p),
702 len := 0, /* overwritten */
703 m := false,
704 el := 1,
705 payload := pl
706}
707
708/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
709altstep as_l1_sacch() runs on ConnHdlr {
710 var L1ctlDlMessage l1_dl;
711 [] L1CTL.receive(t_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
712 log("SACCH received: ", l1_dl.payload.data_ind.payload);
713 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, 23, 23, 0, 0, omit));
714 var LapdmFrameB lb := valueof(ts_LAPDm_B(0, false, false, enc_GsmRrL3Message(meas_rep)));
715 log("LAPDm: ", lb);
716 var octetstring pl := '0000'O & enc_LapdmFrameB(lb);
717 L1CTL.send(t_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_SACCH(0), pl));
718 repeat;
719 }
720}
721
722altstep as_l1_dcch() runs on ConnHdlr {
723 var L1ctlDlMessage l1_dl;
724 [] L1CTL.receive(t_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
725 log("DCCH received: ", l1_dl.payload.data_ind.payload);
726 var octetstring pl := '010301'O;
727 L1CTL.send(t_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), pl));
728 repeat;
729 }
730}
731
732type record MeasElem {
733 uint6_t rxlev,
734 uint3_t rxqual
735}
736
737type record MeasElemFS {
738 MeasElem full,
739 MeasElem sub
740}
741
742type record ConnL1Pars {
743 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +0100744 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +0100745 MeasElemFS meas_ul,
746 int16_t timing_offset_256syms,
747 uint5_t bs_power_level,
748 uint5_t ms_power_level,
749 uint8_t ms_actual_ta
750}
751
752/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
753private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
754 return 63 + (toffs256s/256);
755}
756
757/* build a template for matching measurement results against */
758private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
759 var ConnL1Pars l1p := g_pars.l1_pars;
760 var template RSL_IE_UplinkMeas ul_meas := {
761 len := 3,
762 rfu := '0'B,
763 dtx_d := l1p.dtx_enabled,
764 rxlev_f_u := l1p.meas_ul.full.rxlev,
765 reserved1 := '00'B,
766 rxlev_s_u := l1p.meas_ul.sub.rxlev,
767 reserved2 := '00'B,
768 rxq_f_u := l1p.meas_ul.full.rxqual,
769 rxq_s_u := l1p.meas_ul.sub.rxqual,
770 supp_meas_info := omit
771 };
Harald Welte685d5982018-02-27 20:42:05 +0100772 if (l1p.toa256_enabled) {
773 ul_meas.len := 5;
774 ul_meas.supp_meas_info := int2oct(l1p.timing_offset_256syms, 2);
775 }
Harald Welte70767382018-02-21 12:16:40 +0100776 /* HACK HACK HACK FIXME HACK HACK HACK see https://osmocom.org/issues/2988 */
777 ul_meas.rxlev_f_u := ?;
778 ul_meas.rxlev_s_u := ?;
779 ul_meas.rxq_f_u := ?;
780 ul_meas.rxq_s_u := ?;
781 var template RSL_IE_BS_Power bs_power := {
782 reserved := 0,
783 epc := false,
784 fpc := false,
785 power_level := l1p.bs_power_level
786 };
787 var template RSL_IE_L1Info l1_info := {
788 ms_power_lvl := l1p.ms_power_level,
789 fpc := false,
790 reserved := 0,
791 actual_ta := l1p.ms_actual_ta
792 };
793 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
794 var template uint8_t t_toffs := (offs-1 .. offs+1); /* some tolerance */
795 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
796 ?, t_toffs);
797}
798
799/* verify we regularly receive measurement reports with incrementing numbers */
800altstep as_meas_res() runs on ConnHdlr {
801 var RSL_Message rsl;
802 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
803 /* increment counter of next to-be-expected meas rep */
804 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
805 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +0100806 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +0100807 repeat;
808 }
809 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
810 setverdict(fail, "Received unspecific MEAS RES ", rsl);
811 self.stop;
812 }
813 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
814 setverdict(fail, "Received unexpected MEAS RES ", rsl);
815 self.stop;
816 }
817 [] g_Tmeas_exp.timeout {
818 setverdict(fail, "Didn't receive expected measurement result")
819 self.stop;
820 }
821}
822
823/* Establish dedicated channel: L1CTL + RSL side */
824private function f_est_dchan() runs on ConnHdlr {
825 var GsmFrameNumber fn;
826 var ImmediateAssignment imm_ass;
827 var integer ra := 23;
828
829 fn := f_L1CTL_RACH(L1CTL, ra);
830 /* This arrives on CCHAN, so we cannot test for receiving CHAN RQDhere */
831 //RSL.receive(tr_RSL_CHAN_RQD(int2oct(23,1)));
832
833 /* Activate channel on BTS side */
834 f_rsl_chan_act(g_pars.chan_mode);
835
836 /* Send IMM.ASS via CCHAN */
837 var ChannelDescription ch_desc := {
838 chan_nr := g_pars.chan_nr,
839 tsc := 7,
840 h := false,
841 arfcn := mp_trx0_arfcn,
842 maio_hsn := omit
843 };
844 var MobileAllocation ma := {
845 len := 0,
846 ma := ''B
847 };
848 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
849 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
850
851 /* receive IMM.ASS on MS side */
852 var ImmediateAssignment ia_um;
853 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
854 /* enable dedicated mode */
855 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
856}
857
858/* establish DChan, verify existance + contents of measurement reports */
859function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +0100860 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100861 RSL.clear;
862
863 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-100);
864 g_pars.l1_pars.meas_ul.sub.rxlev := g_pars.l1_pars.meas_ul.full.rxlev;
865 f_trxc_fake_rssi(100);
866
867 g_pars.l1_pars.timing_offset_256syms := 512; /* 2 symbols */
868 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
869
870 f_est_dchan();
871
872 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
873 * RSL measurement reports on Abis side */
874 timer T := 8.0;
875 T.start;
876 alt {
877 [] as_l1_sacch();
878 [] as_meas_res();
879 [] as_l1_dcch();
880 [] L1CTL.receive { repeat; }
881 [g_Tmeas_exp.running] T.timeout {
882 /* as_meas_res() would have done setverdict(fail) / self.stop in case
883 * of any earlier errors, so if we reach this timeout, we're good */
884 setverdict(pass);
885 }
886 [] T.timeout {
887 setverdict(fail, "No MEAS RES received at all");
888 }
889 }
890 f_rsl_chan_deact();
891}
892testcase TC_meas_res_sign_tchf() runs on test_CT {
893 var ConnHdlr vc_conn;
894 var ConnHdlrPars pars;
895 f_init(testcasename());
896 for (var integer tn := 1; tn <= 4; tn := tn+1) {
897 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
898 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
899 vc_conn.done;
900 }
901}
902testcase TC_meas_res_sign_tchh() runs on test_CT {
903 var ConnHdlr vc_conn;
904 var ConnHdlrPars pars;
905 f_init(testcasename());
906 for (var integer ss := 0; ss <= 1; ss := ss+1) {
907 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
908 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
909 vc_conn.done;
910 }
911}
912testcase TC_meas_res_sign_sdcch4() runs on test_CT {
913 var ConnHdlr vc_conn;
914 var ConnHdlrPars pars;
915 f_init(testcasename());
916 for (var integer ss := 0; ss <= 3; ss := ss+1) {
917 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
918 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
919 vc_conn.done;
920 }
921}
922testcase TC_meas_res_sign_sdcch8() runs on test_CT {
923 var ConnHdlr vc_conn;
924 var ConnHdlrPars pars;
925 f_init(testcasename());
926 for (var integer ss := 0; ss <= 7; ss := ss+1) {
927 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
928 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
929 vc_conn.done;
930 }
931}
Harald Welte685d5982018-02-27 20:42:05 +0100932testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
933 var ConnHdlr vc_conn;
934 var ConnHdlrPars pars;
935 f_init(testcasename());
936 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
937 for (var integer ss := 0; ss <= 1; ss := ss+1) {
938 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
939 pars.l1_pars.toa256_enabled := true;
940 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
941 vc_conn.done;
942 }
943}
944
Harald Welte70767382018-02-21 12:16:40 +0100945
946/* Test if a channel without valid uplink bursts generates RSL CONN FAIL IND */
947private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +0100948 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100949 RSL.clear;
950
951 f_est_dchan();
952 f_sleep(2.0);
953 L1CTL.send(t_L1CTL_DM_REL_REQ(g_chan_nr));
954
955 timer T := 40.0;
956 T.start;
957 alt {
958 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
959 setverdict(pass)
960 }
961 [] RSL.receive { repeat };
962 [] T.timeout {
963 setverdict(fail, "No CONN FAIL IND received");
964 }
965 }
966 f_rsl_chan_deact();
967}
968testcase TC_conn_fail_crit() runs on test_CT {
969 var ConnHdlr vc_conn;
970 var ConnHdlrPars pars;
971 f_init(testcasename());
972 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
973 pars.t_guard := 60.0;
974 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
975 vc_conn.done;
976}
977
Harald Welte93640c62018-02-25 16:59:33 +0100978/***********************************************************************
979 * Paging
980 ***********************************************************************/
981
Harald Welte68e495b2018-02-25 00:05:57 +0100982function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
983 if (tmsi == 'FFFFFFFF'O) {
984 return true;
985 } else {
986 return false;
987 }
988}
Harald Welte70767382018-02-21 12:16:40 +0100989
Harald Welte68e495b2018-02-25 00:05:57 +0100990altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids)
991runs on test_CT {
992 var L1ctlDlMessage dl;
993 [] L1CTL.receive(t_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
994 repeat;
995 }
996 [] L1CTL.receive(t_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
997 var octetstring without_plen :=
998 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
999 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
1000 if (match(rr, tr_PAGING_REQ1)) {
1001 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1002 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1003 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
1004 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1005 }
1006 } else if (match(rr, tr_PAGING_REQ2)) {
1007 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1008 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
1009 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1010 }
1011 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
1012 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1013 }
1014 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
1015 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1016 }
1017 } else if (match(rr, tr_PAGING_REQ3)) {
1018 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1019 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
1020 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1021 }
1022 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
1023 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1024 }
1025 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
1026 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1027 }
1028 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
1029 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1030 }
1031 }
1032 repeat;
1033 }
1034}
1035
1036type record PagingTestCfg {
1037 boolean combined_ccch,
1038 integer bs_ag_blks_res,
1039 float load_factor,
1040 boolean exp_load_ind,
1041 boolean exp_overload,
1042 boolean use_tmsi
1043}
1044
1045type record PagingTestState {
1046 integer num_paging_sent,
1047 integer num_paging_rcv_msgs,
1048 integer num_paging_rcv_ids,
1049 integer num_overload
1050}
1051
1052/* receive + ignore RSL RF RES IND */
1053altstep as_rsl_res_ind() runs on test_CT {
1054 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
1055 repeat;
1056 }
1057}
1058
1059/* Helper function for paging related testing */
1060private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
1061 f_init(testcasename());
1062 f_init_l1ctl();
1063 f_l1_tune(L1CTL);
1064
1065 var PagingTestState st := {
1066 num_paging_sent := 0,
1067 num_paging_rcv_msgs := 0,
1068 num_paging_rcv_ids := 0,
1069 num_overload := 0
1070 };
1071
1072 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
1073 var float max_pch_imsi_per_sec;
1074 if (cfg.use_tmsi) {
1075 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
1076 } else {
1077 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
1078 }
1079 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
1080 var float interval := 1.0 / pch_blocks_per_sec;
1081 log("pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
1082
1083 for (var integer i := 0; i < float2int(20.0/interval); i := i+1) {
1084 /* build mobile Identity */
1085 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
1086 if (cfg.use_tmsi) {
1087 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
1088 } else {
1089 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
1090 }
1091 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
1092 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
1093
1094 /* Send RSL PAGING COMMAND */
1095 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
1096 st.num_paging_sent := st.num_paging_sent + 1;
1097
1098 /* Wait for interval to next PAGING COMMAND */
1099 timer T_itv := interval;
1100 T_itv.start;
1101 alt {
1102 /* check for presence of CCCH LOAD IND (paging load) */
1103 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1104 st.num_overload := st.num_overload + 1;
1105 repeat;
1106 }
1107 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1108 setverdict(fail, "Unexpected PCH Overload");
1109 }
1110 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
1111 log("Rx LOAD_IND");
1112 /* FIXME: analyze/verify interval + contents */
1113 repeat;
1114 }
1115 /* check if paging requests arrive on Um side */
1116 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1117 [] L1CTL.receive { repeat; }
1118 [] T_itv.timeout { }
1119 [] as_rsl_res_ind();
1120 }
1121 }
1122
1123 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
1124 timer T_wait := 18.0;
1125 T_wait.start;
1126 alt {
1127 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1128 [] L1CTL.receive { repeat; }
1129 /* 65535 == empty paging queue, we can terminate*/
1130 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
1131 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
1132 [] T_wait.timeout {
1133 setverdict(fail, "Waiting for empty paging queue");
1134 }
1135 [] as_rsl_res_ind();
1136 }
1137
1138 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
1139 " rcvd_ids=", st.num_paging_rcv_ids);
1140 return st;
1141}
1142
1143/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
1144 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1145 * - that CCCH LOAD IND (PCH) are being generated
1146 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1147testcase TC_paging_imsi_80percent() runs on test_CT {
1148 var PagingTestCfg cfg := {
1149 combined_ccch := true,
1150 bs_ag_blks_res := 1,
1151 load_factor := 0.8,
1152 exp_load_ind := true,
1153 exp_overload := false,
1154 use_tmsi := false
1155 };
1156 var PagingTestState st := f_TC_paging(cfg);
1157 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1158 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1159 st.num_paging_rcv_ids);
1160 } else {
1161 setverdict(pass);
1162 }
1163}
1164
1165/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
1166 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1167 * - that CCCH LOAD IND (PCH) are being generated
1168 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1169testcase TC_paging_tmsi_80percent() runs on test_CT {
1170 var PagingTestCfg cfg := {
1171 combined_ccch := true,
1172 bs_ag_blks_res := 1,
1173 load_factor := 0.8,
1174 exp_load_ind := true,
1175 exp_overload := false,
1176 use_tmsi := true
1177 };
1178 var PagingTestState st := f_TC_paging(cfg);
1179 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1180 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1181 st.num_paging_rcv_ids);
1182 } else {
1183 setverdict(pass);
1184 }
1185}
1186
1187/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
1188 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1189 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1190 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1191testcase TC_paging_imsi_200percent() runs on test_CT {
1192 var PagingTestCfg cfg := {
1193 combined_ccch := true,
1194 bs_ag_blks_res := 1,
1195 load_factor := 2.0,
1196 exp_load_ind := true,
1197 exp_overload := true,
1198 use_tmsi := false
1199 };
1200 var PagingTestState st := f_TC_paging(cfg);
1201 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
1202 * slots and will fully drain that buffer before returning */
1203 var template integer tpl := (st.num_paging_sent*80/100 .. st.num_paging_sent *85/100);
1204 if (not match(st.num_paging_rcv_ids, tpl)) {
1205 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1206 } else {
1207 setverdict(pass);
1208 }
1209}
1210
1211/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
1212 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1213 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1214 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1215testcase TC_paging_tmsi_200percent() runs on test_CT {
1216 var PagingTestCfg cfg := {
1217 combined_ccch := true,
1218 bs_ag_blks_res := 1,
1219 load_factor := 2.0,
1220 exp_load_ind := true,
1221 exp_overload := true,
1222 use_tmsi := true
1223 };
1224 var PagingTestState st := f_TC_paging(cfg);
1225 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
1226 * slots and will fully drain that buffer before returning */
1227 var template integer tpl := (st.num_paging_sent*68/100 .. st.num_paging_sent *72/100);
1228 if (not match(st.num_paging_rcv_ids, tpl)) {
1229 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1230 } else {
1231 setverdict(pass);
1232 }
1233}
1234
1235
Harald Welte93640c62018-02-25 16:59:33 +01001236/***********************************************************************
1237 * Immediate Assignment / AGCH
1238 ***********************************************************************/
1239
Harald Welte68e495b2018-02-25 00:05:57 +01001240testcase TC_imm_ass() runs on test_CT {
1241 f_init(testcasename());
1242 for (var integer i := 0; i < 1000; i := i+1) {
1243 var octetstring ia_enc := f_rnd_octstring(8);
1244 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
1245 f_sleep(0.02);
1246 }
1247 /* FIXME: check if imm.ass arrive on Um side */
1248 /* FIXME: check for DELETE INDICATION */
1249 f_sleep(100.0);
1250}
1251
Harald Welte48494ca2018-02-25 16:59:50 +01001252/***********************************************************************
1253 * BCCH
1254 ***********************************************************************/
1255
1256/* tuple of Frame Number + decoded SI */
1257type record SystemInformationFn {
1258 GsmFrameNumber frame_number,
1259 SystemInformation si
1260}
1261
1262/* an arbitrary-length vector of decoded SI + gsmtap header */
1263type record of SystemInformationFn SystemInformationVector;
1264
1265/* an array of SI-vectors indexed by TC value */
1266type SystemInformationVector SystemInformationVectorPerTc[8];
1267
1268/* determine if a given SI vector contains given SI type at least once */
1269function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1270 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1271 var integer fn_mod51 := arr[i].frame_number mod 51;
1272 if (not bcch_ext and fn_mod51 == 2 or
1273 bcch_ext and fn_mod51 == 6) {
1274 if (arr[i].si.header.message_type == key) {
1275 return true;
1276 }
1277 }
1278 }
1279 return false;
1280}
1281
1282/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
1283function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1284 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
1285 setverdict(fail, "No ", key, " in TC=", tc, "!");
1286 }
1287}
1288
1289/* check if a given SI vector contains given SI type at least once on any TC */
1290function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
1291 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
1292 if (f_si_vecslot_contains(arr[tc], key) or
1293 f_si_vecslot_contains(arr[tc], key, true)) {
1294 return true;
1295 }
1296 }
1297 return false;
1298}
1299
1300/* determine if a given SI vector contains given SI type at least N of M times */
1301function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
1302 var integer count := 0;
1303 if (sizeof(arr) < m) {
1304 setverdict(fail, "Error: Insufficient SI in array");
1305 self.stop;
1306 }
1307 for (var integer i:= 0; i < m; i := i + 1) {
1308 var integer fn_mod51 := arr[i].frame_number mod 51;
1309 if (not bcch_ext and fn_mod51 == 2 or
1310 bcch_ext and fn_mod51 == 6) {
1311 if (arr[i].si.header.message_type == key) {
1312 count := count + 1;
1313 }
1314 }
1315 }
1316 if (count >= n) {
1317 return true;
1318 } else {
1319 return false;
1320 }
1321}
1322
1323/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
1324function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
1325 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
1326 setverdict(fail, "Not ", n, "/", m, " of ", key, " in TC=", tc, "!");
1327 }
1328}
1329
1330/* determine if a given SI vector contains given SI type at least once */
1331function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1332 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1333 var integer fn_mod51 := arr[i].frame_number mod 51;
1334 if (not bcch_ext and fn_mod51 == 2 or
1335 bcch_ext and fn_mod51 == 6) {
1336 if (arr[i].si.header.message_type != key) {
1337 return false;
1338 }
1339 }
1340 }
1341 return true;
1342}
1343
1344/* ensure a given TC slot of the SI vector contains only given SI type */
1345function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1346 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
1347 setverdict(fail, "Not all ", key, " in TC=", tc, "!");
1348 }
1349}
1350
1351/* SI configuration of cell, against which we validate actual SI messages */
1352type set SystemInformationConfig {
1353 boolean bcch_extended,
1354 boolean si1_present,
1355 boolean si2bis_present,
1356 boolean si2ter_present,
1357 boolean si2quater_present,
1358 boolean si7_present,
1359 boolean si8_present,
1360 boolean si9_present,
1361 boolean si13_present,
1362 boolean si13alt_present,
1363 boolean si15_present,
1364 boolean si16_present,
1365 boolean si17_present,
1366 boolean si2n_present,
1367 boolean si21_present,
1368 boolean si22_present
1369}
1370
1371/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
1372function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
1373 var integer i;
1374 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
1375 if (sizeof(si_per_tc[i]) == 0) {
Harald Welte544565a2018-03-02 10:34:08 +01001376 setverdict(fail, "No SI messages for TC=", i);
Harald Welte48494ca2018-02-25 16:59:50 +01001377 }
1378 }
1379 if (cfg.si1_present) {
1380 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
1381 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
1382 * when TC = 0, it can assume that System Information Type 1 is not in use. */
1383 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
1384 /* make sure *ALL* contain SI1 */
1385 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
1386 }
1387 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
1388 /* iii) A SI 2 message will be sent at least every time TC = 1 */
1389 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
1390 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
1391 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
1392 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
1393
1394 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
1395 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
1396 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
1397 * consecutive occurrences of TC = 4. */
1398 if (cfg.si2bis_present and not cfg.si2ter_present) {
1399 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
1400 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
1401 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
1402 } else if (cfg.si2ter_present and cfg.si2bis_present) {
1403 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
1404 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
1405 }
1406
1407 if (cfg.si7_present or cfg.si8_present) {
1408 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
1409 * if System Information type 4 does not contain all information needed for cell
1410 * selection and reselection. */
1411 if (not cfg.bcch_extended) {
1412 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
1413 }
1414 if (cfg.si7_present) {
1415 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
1416 }
1417 if (cfg.si8_present) {
1418 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
1419 }
1420 }
1421
1422 if (cfg.si2quater_present) {
1423 /* iii) System information type 2 quater is sent if needed, as determined by the system
1424 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
1425 * and 2ter are used, otherwise it shall be sent at least once within any of 4
1426 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
1427 * within any of 4 consecutive occurrences of TC = 5. */
1428 if (not (cfg.bcch_extended)) {
1429 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
1430 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
1431 } else {
1432 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
1433 }
1434 } else {
1435 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
1436 }
1437 }
1438 if (cfg.si9_present) {
1439 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
1440 * in system information type 3 as defined in 3GPP TS 44.018. */
1441 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
1442 }
1443 if (cfg.si13_present) {
1444 /* vii) System Information type 13 is only related to the GPRS service. System Information
1445 * Type 13 need only be sent if GPRS support is indicated in one or more of System
1446 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
1447 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
1448 * In the case that the message is sent on the BCCH Norm, it is sent at least once
1449 * within any of 4 consecutive occurrences of TC=4. */
1450 if (not cfg.bcch_extended) {
1451 log("not-bccch-extended");
1452 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
1453 } else {
1454 log("bccch-extended");
1455 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
1456 }
1457 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
1458 setverdict(fail, "Cannot have SI13alt and SI13");
1459 }
1460 }
1461 if (cfg.si16_present or cfg.si17_present) {
1462 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
1463 * should not be sent in a cell where network sharing is used (see rule xv). */
1464 if (cfg.si22_present) {
1465 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
1466 }
1467 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
1468 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
1469 }
1470 if (not cfg.bcch_extended) {
1471 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
1472 }
1473 if (cfg.si16_present) {
1474 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
1475 }
1476 if (cfg.si17_present) {
1477 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
1478 }
1479 }
1480
1481 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
1482 * broadcast information. The frequency with which they are sent is determined by the
1483 * system operator. System Information type 9 identifies the scheduling of System
1484 * Information type 18 and 20 messages. */
1485
1486 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
1487 * Information Type 19 is present, then its scheduling shall be indicated in System
1488 * Information Type 9. */
1489
1490 if (cfg.si15_present) {
1491 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
1492 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
1493 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
1494 * 4 consecutive occurrences of TC = 1. */
1495 if (not cfg.bcch_extended) {
1496 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
1497 } else {
1498 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
1499 }
1500 }
1501 if (cfg.si13alt_present) {
1502 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
1503 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
1504 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
1505 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
1506 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
1507 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
1508 * of TC = 4. */
1509 if (cfg.si13_present) {
1510 testcase.stop("Error: Cannot have SI13alt and SI13");
1511 }
1512 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
1513 setverdict(fail, "Cannot have SI13alt and SI13");
1514 }
1515 if (not cfg.bcch_extended) {
1516 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
1517 } else {
1518 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
1519 }
1520 }
1521 if (cfg.si2n_present) {
1522 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
1523 * as determined by the system operator. In the case that the message is sent on the
1524 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
1525 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
1526 * consecutive occurrences of TC = 4. */
1527 if (not cfg.bcch_extended) {
1528 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
1529 } else {
1530 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
1531 }
1532 }
1533 if (cfg.si21_present) {
1534 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
1535 * determined by the system operator. If Extended Access Barring is in use in the cell
1536 * then this message is sent at least once within any of 4 consecutive occurrences of
1537 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
1538 * cell then this message shall only be sent on BCCH Ext. */
1539 if (not cfg.bcch_extended) {
1540 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
1541 } else {
1542 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
1543 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
1544 setverdict(fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
1545 }
1546 }
1547 }
1548 if (cfg.si22_present) {
1549 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
1550 * should not be sent in a cell where SoLSA is used (see rule viii). System
1551 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
1552 * =2 and TC=6. */
1553 if (cfg.si16_present or cfg.si17_present) {
1554 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
1555 }
1556 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
1557 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
1558 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
1559 }
1560 if (not cfg.bcch_extended) {
1561 testcase.stop("Error: SI22 requires BCCH Extd!");
1562 } else {
1563 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
1564 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
1565 }
1566 }
1567}
1568
1569/* sample Systme Information for specified duration via L1CTL */
1570function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
1571 timer T := duration;
1572 var SystemInformationVectorPerTc si_per_tc;
1573 var L1ctlDlMessage l1_dl;
1574
1575 /* initialize all per-TC vectors empty */
1576 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
1577 si_per_tc[i] := {};
1578 }
1579
1580 /* flush all previous L1 queued msgs */
1581 pt.clear;
1582
1583 T.start;
1584 alt {
1585 [] pt.receive(t_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
1586 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
1587 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
1588 log("Ignoring non-RR SI ", l1_dl);
1589 repeat;
1590 }
1591 var SystemInformationFn sig := {
1592 frame_number := l1_dl.dl_info.frame_nr,
1593 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
1594 }
1595 var integer tc := f_gsm_compute_tc(sig.frame_number);
1596 log("SI received at TC=", tc, ": ", sig.si);
1597 /* append to the per-TC bucket */
1598 si_per_tc[tc] := si_per_tc[tc] & { sig };
1599 repeat;
1600 }
1601 [] pt.receive { repeat; }
1602 [] T.timeout { }
1603 }
1604
1605 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
1606 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
1607 }
1608 log("si_per_tc=", si_per_tc);
1609 return si_per_tc;
1610}
1611
1612/* helper function: Set given SI via RSL + validate scheduling.
1613 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
1614function f_TC_si_sched() runs on test_CT {
1615 var SystemInformationVectorPerTc si_per_tc;
1616 f_init_l1ctl();
1617 f_l1_tune(L1CTL);
1618
1619 /* Sample + Validate Scheduling */
1620 si_per_tc := f_l1_sample_si(L1CTL);
1621 f_validate_si_scheduling(si_cfg, si_per_tc);
1622
1623 setverdict(pass);
1624}
1625
1626testcase TC_si_sched_default() runs on test_CT {
1627 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01001628 /* 2+3+4 are mandatory and set in f_init() */
1629 f_TC_si_sched();
1630}
1631
1632testcase TC_si_sched_1() runs on test_CT {
1633 f_init();
1634 si_cfg.si1_present := true;
1635 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01001636 f_TC_si_sched();
1637}
1638
1639testcase TC_si_sched_2bis() runs on test_CT {
1640 f_init();
1641 si_cfg.si2bis_present := true;
1642 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
1643 f_TC_si_sched();
1644}
1645
1646testcase TC_si_sched_2ter() runs on test_CT {
1647 f_init();
1648 si_cfg.si2ter_present := true;
1649 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
1650 f_TC_si_sched();
1651}
1652
1653testcase TC_si_sched_2ter_2bis() runs on test_CT {
1654 f_init();
1655 si_cfg.si2bis_present := true;
1656 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
1657 si_cfg.si2ter_present := true;
1658 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
1659 f_TC_si_sched();
1660}
1661
1662testcase TC_si_sched_2quater() runs on test_CT {
1663 f_init();
1664 si_cfg.si2quater_present := true;
1665 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
1666 f_TC_si_sched();
1667}
1668
1669testcase TC_si_sched_13() runs on test_CT {
1670 f_init();
1671 si_cfg.si13_present := true;
1672 //f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, fixme);
1673 f_TC_si_sched();
1674}
1675
1676testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
1677 f_init();
1678 si_cfg.si2bis_present := true;
1679 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
1680 si_cfg.si2ter_present := true;
1681 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
1682 si_cfg.si2quater_present := true;
1683 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
1684 si_cfg.si13_present := true;
1685 //f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, fixme);
1686 f_TC_si_sched();
1687}
1688
1689
Harald Welte68e495b2018-02-25 00:05:57 +01001690testcase TC_bcch_info() runs on test_CT {
1691 f_init(testcasename());
1692 /* FIXME: enable / disable individual BCCH info */
1693 //ts_RSL_BCCH_INFO(si_type, info);
1694 /* expect no ERROR REPORT after either of them *
1695 /* negative test: ensure ERROR REPORT on unsupported types */
1696}
1697
Harald Welte93640c62018-02-25 16:59:33 +01001698/***********************************************************************
1699 * Low-Level Protocol Errors / ERROR REPORT
1700 ***********************************************************************/
1701
Harald Welte01d982c2018-02-25 01:31:40 +01001702private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
1703 timer T := 5.0;
1704 T.start;
1705 alt {
1706 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
1707 setverdict(pass);
1708 }
1709 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
1710 setverdict(fail, "Wrong cause in RSL ERR REP");
1711 }
1712 [] RSL_CCHAN.receive {
1713 repeat;
1714 }
1715 [] T.timeout {
1716 setverdict(fail, "Timeout waiting for RSL ERR REP");
1717 }
1718 }
1719}
1720
1721/* Provoke a protocol error (message too short) and match on ERROR REPORT */
1722testcase TC_rsl_protocol_error() runs on test_CT {
1723 f_init(testcasename());
1724 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
1725 rsl.ies := omit;
1726 RSL_CCHAN.send(ts_RSL_UD(rsl));
1727
1728 f_exp_err_rep(RSL_ERR_PROTO);
1729}
1730
1731/* Provoke a mandatory IE error and match on ERROR REPORT */
1732testcase TC_rsl_mand_ie_error() runs on test_CT {
1733 f_init(testcasename());
1734
1735 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
1736 rsl.ies := { rsl.ies[0] };
1737 RSL_CCHAN.send(ts_RSL_UD(rsl));
1738
1739 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
1740}
1741
1742/* Provoke an IE content error and match on ERROR REPORT */
1743testcase TC_rsl_ie_content_error() runs on test_CT {
1744 f_init(testcasename());
1745 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
1746 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
1747 RSL_CCHAN.send(ts_RSL_UD(rsl));
1748
1749 f_exp_err_rep(RSL_ERR_IE_CONTENT);
1750}
1751
Harald Welte93640c62018-02-25 16:59:33 +01001752/***********************************************************************
1753 * IPA CRCX/MDCX/DLCS media stream handling
1754 ***********************************************************************/
1755
Harald Weltea871a382018-02-25 02:03:14 +01001756/* Send IPA DLCX to inactive lchan */
1757function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01001758 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
1759 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01001760}
1761testcase TC_ipa_dlcx_not_active() runs on test_CT {
1762 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1763 f_init(testcasename());
1764 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
1765 vc_conn.done;
1766}
Harald Welte68e495b2018-02-25 00:05:57 +01001767
Harald Weltea3f1df92018-02-25 12:49:55 +01001768/* Send IPA CRCX twice to inactive lchan */
1769function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
1770 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
1771 "IPA CRCX ACK");
1772 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
1773 "IPA CRCX NACK");
1774}
1775testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
1776 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1777 f_init(testcasename());
1778 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
1779 vc_conn.done;
1780}
1781
1782/* Regular sequence of CRCX/MDCX/DLCX */
1783function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
1784 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
1785 "IPA CRCX ACK");
1786 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
1787 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
1788 var uint7_t rtp_pt2 := f_rnd_int(127);
1789 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
1790 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
1791 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
1792 "IPA MDCX ACK");
1793 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
1794 "IPA DLCX ACK");
1795}
1796testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
1797 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1798 f_init(testcasename());
1799 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
1800 vc_conn.done;
1801}
1802
Harald Welte3ae11da2018-02-25 13:36:06 +01001803/* Sequence of CRCX, 2x MDCX, DLCX */
1804function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
1805 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
1806 "IPA CRCX ACK");
1807 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
1808 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
1809 var uint7_t rtp_pt2 := f_rnd_int(127);
1810 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
1811 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
1812 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
1813 "IPA MDCX ACK");
1814 /* Second MDCX */
1815 remote_ip := f_rnd_int(c_UINT32_MAX);
1816 remote_port := f_rnd_int(c_UINT16_MAX);
1817 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
1818 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
1819 "IPA MDCX ACK");
1820 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
1821 "IPA DLCX ACK");
1822}
1823testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
1824 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1825 f_init(testcasename());
1826 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
1827 vc_conn.done;
1828}
1829
Harald Welte9912eb52018-02-25 13:30:15 +01001830/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
1831function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
1832 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
1833 "IPA CRCX NACK");
1834}
1835testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
1836 var ConnHdlrPars pars;
1837 var ConnHdlr vc_conn;
1838 f_init(testcasename());
1839
1840 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
1841 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
1842 vc_conn.done;
1843
1844 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
1845 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
1846 vc_conn.done;
1847}
1848
Harald Weltea3f1df92018-02-25 12:49:55 +01001849
Harald Welte883340c2018-02-28 18:59:29 +01001850/***********************************************************************
1851 * PCU Socket related tests
1852 ***********************************************************************/
1853
1854private function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
1855runs on test_CT {
1856 timer T := 3.0;
1857
1858 /* we don't expect any RTS.req before PDCH are active */
1859 T.start;
1860 alt {
1861 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
1862 setverdict(fail, "PCU RTS.req before PDCH active?");
1863 self.stop;
1864 }
1865 [] PCU.receive { repeat; }
1866 [] T.timeout { }
1867 }
1868
1869 /* Send PDCH activate request for known PDCH timeslot */
1870 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
1871
1872 /* we now expect RTS.req for this timeslot (only) */
1873 T.start;
1874 alt {
1875 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
1876 setverdict(pass);
1877 }
1878 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
1879 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
1880 setverdict(fail, "Unexpected RTS.req for supposedly failing activation");
1881 self.stop;
1882 }
1883 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
1884 setverdict(fail, "RTS.req for wrong TRX/TS");
1885 self.stop;
1886 }
1887 [] PCU.receive { repeat; }
1888 [exp_success] T.timeout {
1889 setverdict(fail, "Timeout waiting for PCU RTS.req");
1890 }
1891 [not exp_success] T.timeout {
1892 setverdict(pass);
1893 }
1894 }
1895}
1896
1897private function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
1898runs on test_CT {
1899 timer T := 3.0;
1900
1901 /* Send PDCH activate request for known PDCH timeslot */
1902 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
1903
1904 PCU.clear;
1905 /* we now expect no RTS.req for this timeslot */
1906 T.start;
1907 alt {
1908 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
1909 setverdict(fail, "Received unexpected PCU RTS.req");
1910 self.stop;
1911 }
1912 [] PCU.receive { repeat; }
1913 [] T.timeout {
1914 setverdict(pass);
1915 }
1916 }
1917}
1918
1919/* PDCH activation via PCU socket; check for presence of RTS.req */
1920testcase TC_pcu_act_req() runs on test_CT {
1921 f_init();
1922 f_TC_pcu_act_req(0, 0, 7, true);
1923}
1924
1925/* PDCH activation via PCU socket on non-PDCU timeslot */
1926testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
1927 f_init();
1928 f_TC_pcu_act_req(0, 0, 1, false);
1929}
1930
1931/* PDCH activation via PCU socket on wrong BTS */
1932testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
1933 f_init();
1934 f_TC_pcu_act_req(23, 0, 7, false);
1935}
1936
1937/* PDCH activation via PCU socket on wrong TRX */
1938testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
1939 f_init();
1940 f_TC_pcu_act_req(0, 23, 7, false);
1941}
1942
1943/* PDCH deactivation via PCU socket; check for absence of RTS.req */
1944testcase TC_pcu_deact_req() runs on test_CT {
1945 f_init();
1946 /* Activate PDCH */
1947 f_TC_pcu_act_req(0, 0, 7, true);
1948 f_sleep(1.0);
1949 /* and De-Activate again */
1950 f_TC_pcu_deact_req(0, 0, 7);
1951}
1952
1953/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
1954testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
1955 f_init();
1956 f_TC_pcu_deact_req(0, 0, 1);
1957}
1958
1959/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
1960testcase TC_pcu_ver_si13() runs on test_CT {
1961 const octetstring si13 := '00010203040506070909'O;
1962 var PCUIF_send_data sd;
1963 timer T:= 3.0;
1964 f_init();
1965
1966 /* Set SI13 via RSL */
1967 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
1968 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, "BTS_Test v23")));
1969 T.start;
1970 alt {
1971 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
1972 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
1973 setverdict(pass);
1974 } else {
1975 repeat;
1976 }
1977 }
1978 [] PCU.receive { repeat; }
1979 [] T.timeout {
1980 setverdict(fail, "Timeout waiting for SI13");
1981 self.stop;
1982 }
1983 }
1984}
1985
1986private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
1987
1988/* helper function to send a PCU DATA.req */
1989private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
1990 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
1991runs on test_CT
1992{
1993 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
1994 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
1995}
1996
1997/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
1998private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
1999 PCUIF_Sapi sapi, octetstring data)
2000runs on test_CT
2001{
2002 var PCUIF_send_data sd;
2003
2004 timer T := 3.0;
2005 T.start;
2006 alt {
2007 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2008 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2009 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2010 sd.data.u.rts_req.fn, sapi, data);
2011 }
2012 [] PCU.receive { repeat; }
2013 [] T.timeout {
2014 setverdict(fail, "Timeout waiting for RTS.ind");
2015 }
2016 }
2017}
2018
2019/* Send DATA.req on invalid BTS */
2020testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
2021 f_init();
2022 f_TC_pcu_act_req(0, 0, 7, true);
2023 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2024 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2025 f_sleep(10.0);
2026}
2027
2028/* Send DATA.req on invalid TRX */
2029testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
2030 f_init();
2031 f_TC_pcu_act_req(0, 0, 7, true);
2032 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2033 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2034 f_sleep(10.0);
2035}
2036
2037/* Send DATA.req on invalid timeslot */
2038testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
2039 f_init();
2040 f_TC_pcu_act_req(0, 0, 7, true);
2041 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2042 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2043 f_sleep(10.0);
2044}
2045
2046/* Send DATA.req on timeslot that hasn't been activated */
2047testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
2048 f_init();
2049 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2050 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2051 f_sleep(2.0);
2052}
2053
2054testcase TC_pcu_data_req_pdtch() runs on test_CT {
2055 f_init();
2056 f_TC_pcu_act_req(0, 0, 7, true);
2057 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2058 /* FIXME: how to check this was actually sent */
2059 f_sleep(2.0);
2060}
2061
2062testcase TC_pcu_data_req_ptcch() runs on test_CT {
2063 f_init();
2064 f_TC_pcu_act_req(0, 0, 7, true);
2065 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
2066 /* FIXME: how to check this was actually sent */
2067 f_sleep(2.0);
2068}
2069
2070/* Send AGCH from PCU; check it appears on Um side */
2071testcase TC_pcu_data_req_agch() runs on test_CT {
2072 timer T := 3.0;
2073 f_init();
2074 f_init_l1ctl();
2075 f_l1_tune(L1CTL);
2076
2077 f_TC_pcu_act_req(0, 0, 7, true);
2078 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
2079
2080 T.start;
2081 alt {
2082 [] L1CTL.receive(t_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
2083 setverdict(pass);
2084 }
2085 [] L1CTL.receive { repeat; }
2086 [] T.timeout {
2087 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2088 }
2089 }
2090}
2091
2092/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
2093testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
2094 var octetstring imm_ass := f_rnd_octstring(23);
2095 f_init();
2096 f_init_l1ctl();
2097 f_l1_tune(L1CTL);
2098
2099 /* append 3 last imsi digits so BTS can compute pagng group */
2100 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
2101
2102 timer T := 0.5;
2103 T.start;
2104 alt {
2105 [] L1CTL.receive(t_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
2106 /* TODO: verify paging group */
2107 setverdict(pass);
2108 }
2109 [] L1CTL.receive { repeat; }
2110 [] T.timeout {
2111 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2112 }
2113 }
2114}
2115
2116/* Send RACH from Um side, expect it to show up on PCU socket */
2117testcase TC_pcu_rach_content() runs on test_CT {
2118 f_init();
2119 f_init_l1ctl();
2120 f_l1_tune(L1CTL);
2121
2122 var GsmFrameNumber fn_last := 0;
2123 for (var integer i := 0; i < 1000; i := i+1) {
2124 var OCT1 ra := f_rnd_ra_ps();
2125 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
2126 if (fn == fn_last) {
2127 setverdict(fail, "Two RACH in same FN?!?");
2128 self.stop;
2129 }
2130 fn_last := fn;
2131
2132 timer T := 2.0;
2133 T.start;
2134 alt {
2135 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
2136 T.stop;
2137 }
2138 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
2139 setverdict(fail, "Unexpected RACH IND");
2140 self.stop;
2141 }
2142 [] PCU.receive { repeat; }
2143 [] T.timeout {
2144 setverdict(fail, "Timeout waiting for RACH IND");
2145 self.stop;
2146 }
2147 }
2148 }
2149 setverdict(pass);
2150}
2151
2152private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
2153 var integer strlen := lengthof(str);
2154 for (var integer i := 0; i < len-strlen; i := i+1) {
2155 str := str & pad;
2156 }
2157 return str;
2158}
2159
2160/* Send PAGING via RSL, expect it to shw up on PCU socket */
2161testcase TC_pcu_paging_from_rsl() runs on test_CT {
2162 f_init();
2163
2164 for (var integer i := 0; i < 100; i := i+1) {
2165 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2166 timer T := 3.0;
2167 if (i < 50) {
2168 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2169 } else {
2170 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
2171 }
2172 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2173 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2174 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
2175
2176 /* Send RSL PAGING COMMAND */
2177 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
2178 T.start;
2179 alt {
2180 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
2181 }
2182 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
2183 setverdict(fail, "Unexpected PAGING REQ");
2184 self.stop;
2185 }
2186 [] PCU.receive { repeat; }
2187 [] T.timeout {
2188 setverdict(fail, "Timeout waiting for PAGING REQ");
2189 self.stop;
2190 }
2191 }
2192 }
2193 setverdict(pass);
2194}
2195
2196
Harald Welte68e495b2018-02-25 00:05:57 +01002197/* TODO Areas:
2198
2199* channel activation
2200** with BS_Power / MS_Power, bypassing power control loop
2201** on primary vs. secondary TRX
2202** with encryption from initial activation on
2203** with timing advance from initial activation on
2204* mode modify
2205** encryption
2206** multirate
2207* check DEACTIVATE SACCH
2208* encryption command / intricate logic about tx-only/tx+rx/...
2209** unsupported algorithm
2210* handover detection
2211* MS Power Control
2212* BS Power Control
2213* Physical Context
2214* SACCH info modify
Harald Welte68e495b2018-02-25 00:05:57 +01002215* CCCH Load Indication for PCH and RACH
2216* Delete Indication on AGCH overflow
2217* SMS Broadcast Req / Cmd / CBCH LOad Ind
2218* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01002219* error handling
2220* discriminator error
2221** type error
2222** sequence error
2223** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01002224* PCU interface
2225** TIME_IND from BTS->PCU
2226** DATA_IND from BTS->PCU
2227** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01002228
2229*/
Harald Welte70767382018-02-21 12:16:40 +01002230
2231control {
2232 execute( TC_chan_act_stress() );
2233 execute( TC_chan_act_react() );
2234 execute( TC_chan_deact_not_active() );
2235 execute( TC_chan_act_wrong_nr() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01002236 execute( TC_rach_content() );
2237 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01002238 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01002239 execute( TC_meas_res_sign_tchf() );
2240 execute( TC_meas_res_sign_tchh() );
2241 execute( TC_meas_res_sign_sdcch4() );
2242 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01002243 execute( TC_meas_res_sign_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01002244 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01002245 execute( TC_paging_imsi_80percent() );
2246 execute( TC_paging_tmsi_80percent() );
2247 execute( TC_paging_imsi_200percent() );
2248 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01002249 execute( TC_rsl_protocol_error() );
2250 execute( TC_rsl_mand_ie_error() );
2251 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01002252 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01002253 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01002254 execute( TC_si_sched_2bis() );
2255 execute( TC_si_sched_2ter() );
2256 execute( TC_si_sched_2ter_2bis() );
2257 execute( TC_si_sched_2quater() );
2258 execute( TC_si_sched_13() );
2259 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01002260 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01002261 execute( TC_ipa_crcx_twice_not_active() );
2262 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01002263 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01002264 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01002265
2266 execute( TC_pcu_act_req() );
2267 execute( TC_pcu_act_req_wrong_ts() );
2268 execute( TC_pcu_act_req_wrong_bts() );
2269 execute( TC_pcu_act_req_wrong_trx() );
2270 execute( TC_pcu_deact_req() );
2271 execute( TC_pcu_deact_req_wrong_ts() );
2272 execute( TC_pcu_ver_si13() );
2273 execute( TC_pcu_data_req_wrong_bts() );
2274 execute( TC_pcu_data_req_wrong_trx() );
2275 execute( TC_pcu_data_req_wrong_ts() );
2276 execute( TC_pcu_data_req_ts_inactive() );
2277 execute( TC_pcu_data_req_pdtch() );
2278 execute( TC_pcu_data_req_ptcch() );
2279 execute( TC_pcu_data_req_agch() );
2280 execute( TC_pcu_data_req_imm_ass_pch() );
2281 execute( TC_pcu_rach_content() );
2282 execute( TC_pcu_paging_from_rsl() );
Harald Welte70767382018-02-21 12:16:40 +01002283}
2284
2285
2286}