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