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