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