blob: b0a2bcacdd62440c79c29b86e722cf1448eb4cd8 [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
Harald Welte629cc6b2018-03-11 17:19:05 +010055type record of RslChannelNr ChannelNrs;
56
Harald Welte70767382018-02-21 12:16:40 +010057type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +010058 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +010059 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +010060 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +010061 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +010062 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +010063 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +010064
65 /* L1CTL port (for classic tests) */
66 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +010067
Harald Welte54a2a2d2018-02-26 09:14:05 +010068 /* TRXC port (for classic tests) */
69 port TRXC_CODEC_PT BB_TRXC;
70 var integer g_bb_trxc_conn_id;
71
Harald Welte8da48242018-02-27 20:41:32 +010072 port TELNETasp_PT BTSVTY;
73
Harald Welte883340c2018-02-28 18:59:29 +010074 /* PCU Interface of BTS */
75 port PCUIF_CODEC_PT PCU;
76 var integer g_pcu_conn_id;
77 /* Last PCU INFO IND we received */
78 var PCUIF_Message g_pcu_last_info;
79
Harald Welte48494ca2018-02-25 16:59:50 +010080 /* SI configuration */
81 var SystemInformationConfig si_cfg := {
82 bcch_extended := false,
83 si1_present := false,
84 si2bis_present := false,
85 si2ter_present := false,
86 si2quater_present := false,
87 si7_present := false,
88 si8_present := false,
89 si9_present := false,
90 si13_present := false,
91 si13alt_present := false,
92 si15_present := false,
93 si16_present := false,
94 si17_present := false,
95 si2n_present := false,
96 si21_present := false,
97 si22_present := false
98 };
Harald Welte629cc6b2018-03-11 17:19:05 +010099
100 /* all logical channels available on the BTS */
101 var ChannelNrs g_AllChannels;
Harald Welte70767382018-02-21 12:16:40 +0100102}
103
104/* an individual call / channel */
105type component ConnHdlr extends RSL_DchanHdlr {
106 port L1CTL_PT L1CTL;
107
108 port TRXC_CODEC_PT BB_TRXC;
109 var integer g_bb_trxc_conn_id;
110
111 timer g_Tguard;
112 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
113
114 var ConnHdlrPars g_pars;
115 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100116 var boolean g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +0100117}
118
119function f_init_rsl(charstring id) runs on test_CT {
120 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
121 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
122
123 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
124 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
125 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
126
127 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
128 vc_RSL.start(RSL_Emulation.main(false));
129}
130
131type record ConnHdlrPars {
132 RslChannelNr chan_nr,
133 RSL_IE_ChannelMode chan_mode,
134 float t_guard,
135 ConnL1Pars l1_pars
136}
137
Harald Welte82ccef72018-02-25 16:17:33 +0100138template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100139 max_retrans := RACH_MAX_RETRANS_7,
140 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100141 cell_barr_access := false,
142 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100143 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100144};
145
Harald Weltef10153f2018-02-25 16:34:05 +0100146template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100147 cell_resel_hyst_2dB := 2,
148 ms_txpwr_max_cch := 7,
Harald Weltef10153f2018-02-25 16:34:05 +0100149 acs := '0'B,
150 neci := true,
151 rxlev_access_min := 0
152}
153
154template (value) LocationAreaIdentification ts_LAI_default := {
155 mcc_mnc := '262F42'H,
156 lac := 42
157}
158
Harald Welte7484fc42018-02-24 14:09:45 +0100159/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100160template (value) SystemInformation ts_SI3_default := {
161 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100162 payload := {
163 si3 := {
164 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100165 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100166 ctrl_chan_desc := {
167 msc_r99 := true,
168 att := true,
169 bs_ag_blks_res := 1,
170 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100171 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100172 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
173 spare := '00'B,
174 bs_pa_mfrms := 0, /* 2 multiframes */
175 t3212 := 1 /* 6 minutes */
176 },
Harald Welte82ccef72018-02-25 16:17:33 +0100177 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100178 dn_ind := false,
179 pwrc := false,
180 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100181 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100182 },
Harald Weltef10153f2018-02-25 16:34:05 +0100183 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100184 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100185 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100186 }
187 }
188}
Harald Welte70767382018-02-21 12:16:40 +0100189
Harald Weltef8df4cb2018-03-10 15:15:08 +0100190template (value) SystemInformation ts_SI2_default := {
191 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100192 payload := {
193 si2 := {
194 bcch_freq_list := '00000000000000000000000000000000'O,
195 ncc_permitted := '11111111'B,
196 rach_control := ts_RachCtrl_default
197 }
198 }
199}
200
Harald Weltef8df4cb2018-03-10 15:15:08 +0100201template (value) SystemInformation ts_SI4_default := {
202 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100203 payload := {
204 si4 := {
205 lai := ts_LAI_default,
206 cell_sel_par := ts_CellSelPar_default,
207 rach_control := ts_RachCtrl_default,
208 cbch_chan_desc := omit,
209 cbch_mobile_alloc := omit,
210 rest_octets := ''O
211 }
212 }
213}
214
215function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
216runs on test_CT {
217 log("Setting ", rsl_si_type, ": ", si_enc);
218 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
219}
220
221function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
222runs on test_CT {
223 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
224 log("Setting ", rsl_si_type, ": ", si_dec);
225 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
226}
227
Harald Welte8da48242018-02-27 20:41:32 +0100228private function f_init_vty(charstring id) runs on test_CT {
229 map(self:BTSVTY, system:BTSVTY);
230 f_vty_set_prompts(BTSVTY);
231 f_vty_transceive(BTSVTY, "enable");
232}
233
Harald Welte883340c2018-02-28 18:59:29 +0100234/* PCU socket may at any time receive a new INFO.ind */
235private altstep as_pcu_info_ind() runs on test_CT {
236 var PCUIF_send_data sd;
237 [] PCU.receive(t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_INFO_IND)) -> value sd {
238 g_pcu_last_info := sd.data;
239 repeat;
240 }
241}
242
243private function f_init_pcu(charstring id) runs on test_CT {
244 timer T := 2.0;
245 var PCUIF_send_data sd;
246 map(self:PCU, system:PCU);
Harald Welte84271622018-03-10 17:21:03 +0100247 if (mp_pcu_socket == "") {
248 g_pcu_conn_id := -1;
249 return;
250 }
Harald Welte883340c2018-02-28 18:59:29 +0100251 g_pcu_conn_id := f_pcuif_connect(PCU, mp_pcu_socket);
252
253 T.start;
254 alt {
255 [] PCU.receive(t_SD_PCUIF_MSGT(g_pcu_conn_id, PCU_IF_MSG_INFO_IND)) -> value sd {
256 g_pcu_last_info := sd.data;
257 }
258 [] T.timeout {
259 setverdict(fail, "Timeout waiting for PCU INFO_IND");
260 self.stop;
261 }
262 }
263}
264
Harald Welte70767382018-02-21 12:16:40 +0100265/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100266function f_init(charstring id := "BTS-Test") runs on test_CT {
Harald Welte629cc6b2018-03-11 17:19:05 +0100267 g_AllChannels := {
268 /* TS 1..4: TCH/F */
269 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
270 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
271 /* TS 5: TCH/H */
272 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
273 /* TS 0: SDCCH/4 */
274 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
275 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
276 /* TS 6: SDCCH/8 */
277 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
278 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
279 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
280 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
281 };
282
Harald Welte70767382018-02-21 12:16:40 +0100283 f_init_rsl(id);
284 RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
Harald Welte2d142592018-02-25 13:19:44 +0100285 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100286 f_init_vty(id);
Harald Welte7484fc42018-02-24 14:09:45 +0100287
288 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100289 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
290 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
291 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
292 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100293
Harald Welte883340c2018-02-28 18:59:29 +0100294 f_init_pcu(id);
295
Harald Welte84271622018-03-10 17:21:03 +0100296 if (mp_bb_trxc_port != -1) {
297 var TrxcMessage ret;
298 /* start with a default moderate timing offset equalling TA=2 */
299 f_main_trxc_connect();
300 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
301 }
Harald Welte70767382018-02-21 12:16:40 +0100302}
303
Harald Welte294b0a22018-03-10 23:26:48 +0100304function f_shutdown() runs on test_CT {
305 /* shut down all "externally interfaced" components first to avoid unclean shutdown */
306 vc_IPA.stop;
307 vc_RSL.stop;
308}
309
Harald Welte68e495b2018-02-25 00:05:57 +0100310/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
311function f_init_l1ctl() runs on test_CT {
312 map(self:L1CTL, system:L1CTL);
313 f_connect_reset(L1CTL);
314}
315
Harald Welte70767382018-02-21 12:16:40 +0100316type function void_fn(charstring id) runs on ConnHdlr;
317
318/* create a new test component */
319function f_start_handler(void_fn fn, ConnHdlrPars pars)
320runs on test_CT return ConnHdlr {
321 var charstring id := testcasename();
322 var ConnHdlr vc_conn;
323
324 vc_conn := ConnHdlr.create(id);
325 /* connect to RSL Emulation main component */
326 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
327 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
328
329 vc_conn.start(f_handler_init(fn, id, pars));
330 return vc_conn;
331}
332
Harald Welte7484fc42018-02-24 14:09:45 +0100333template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
334 streamId := sid,
335 rsl := rsl
336}
337
338template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
339 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
340 streamId := sid,
341 rsl := rsl
342}
343
Harald Welte70767382018-02-21 12:16:40 +0100344private altstep as_Tguard() runs on ConnHdlr {
345 [] g_Tguard.timeout {
346 setverdict(fail, "Tguard timeout");
347 self.stop;
348 }
349}
350
Harald Welte68e495b2018-02-25 00:05:57 +0100351private function f_l1_tune(L1CTL_PT L1CTL) {
Harald Welte70767382018-02-21 12:16:40 +0100352 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED);
353}
354
355private function f_trxc_connect() runs on ConnHdlr {
356 map(self:BB_TRXC, system:BB_TRXC);
357 var Result res;
Harald Weltea4d8f352018-03-01 15:47:20 +0100358 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
359 "", -1, -1, {udp:={}}, {});
Harald Welte70767382018-02-21 12:16:40 +0100360 g_bb_trxc_conn_id := res.connId;
361}
362
363private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100364 var TrxcMessage ret;
365 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100366}
367
368private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100369 var TrxcMessage ret;
370 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100371}
372
373/* first function started in ConnHdlr component */
374private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
375runs on ConnHdlr {
376 g_pars := pars;
377 g_chan_nr := pars.chan_nr;
378
379 map(self:L1CTL, system:L1CTL);
380 f_connect_reset(L1CTL);
381
Harald Welte84271622018-03-10 17:21:03 +0100382 if (mp_bb_trxc_port != -1) {
383 f_trxc_connect();
384 }
Harald Welte70767382018-02-21 12:16:40 +0100385
386 g_Tguard.start(pars.t_guard);
387 activate(as_Tguard());
388
389 f_rslem_register(0, pars.chan_nr);
390
391 /* call the user-supplied test case function */
392 fn.apply(id);
393}
394
Harald Welte1eba3742018-02-25 12:48:14 +0100395function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id)
396runs on ConnHdlr {
397 timer T := 3.0;
398 RSL.send(tx);
399 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100400 alt {
Harald Welte1eba3742018-02-25 12:48:14 +0100401 [] RSL.receive(exp_rx) {
402 T.stop;
403 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100404 }
Harald Welte1eba3742018-02-25 12:48:14 +0100405 [] T.timeout {
406 setverdict(fail, "Timeout expecting " & id);
407 self.stop;
408 }
Harald Welte3c0a0f82018-03-10 23:01:33 +0100409 [] as_l1_sacch();
410 [] as_meas_res();
411 [] as_l1_dcch();
Harald Welte1eba3742018-02-25 12:48:14 +0100412 [] RSL.receive {
413 setverdict(fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100414 }
415 }
416}
417
Harald Welte1eba3742018-02-25 12:48:14 +0100418function f_rsl_chan_act(RSL_IE_ChannelMode mode) runs on ConnHdlr {
419 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
420 "RSL CHAN ACT");
421}
422
Harald Welte70767382018-02-21 12:16:40 +0100423function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100424 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
425 "RF CHAN REL");
Harald Welte70767382018-02-21 12:16:40 +0100426}
427
Harald Welte70767382018-02-21 12:16:40 +0100428private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
429 template RSL_IE_ChannelMode chan_mode,
430 float t_guard := 20.0) := {
431 chan_nr := valueof(chan_nr),
432 chan_mode := valueof(chan_mode),
433 t_guard := t_guard,
434 l1_pars := {
435 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100436 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100437 meas_ul := {
438 full := {
439 rxlev := dbm2rxlev(-53),
440 rxqual := 0
441 },
442 sub := {
443 rxlev := dbm2rxlev(-53),
444 rxqual := 0
445 }
446 },
447 timing_offset_256syms := 0,
448 bs_power_level := 0,
449 ms_power_level := 0,
450 ms_actual_ta := 0
451 }
452}
453
Harald Welte93640c62018-02-25 16:59:33 +0100454/***********************************************************************
455 * Channel Activation / Deactivation
456 ***********************************************************************/
457
Harald Welte70767382018-02-21 12:16:40 +0100458/* Stress test: Do 500 channel activations/deactivations in rapid succession */
459function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
460 for (var integer i := 0; i < 500; i := i+1) {
461 f_rsl_chan_act(g_pars.chan_mode);
462 f_rsl_chan_deact();
463 }
464 setverdict(pass);
465}
466testcase TC_chan_act_stress() runs on test_CT {
467 var ConnHdlr vc_conn;
468 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
469 f_init(testcasename());
470 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
471 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100472 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100473}
474
475/* Test if re-activation of an already active channel fails as expected */
476function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
477 f_rsl_chan_act(g_pars.chan_mode);
478 /* attempt to activate the same lchan again -> expect reject */
479 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
480 alt {
481 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
482 setverdict(fail, "Unexpected CHAN ACT ACK on double activation");
483 }
484 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
485 setverdict(pass);
486 }
487 }
488 f_rsl_chan_deact();
489}
490testcase TC_chan_act_react() runs on test_CT {
491 var ConnHdlr vc_conn;
492 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100493 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100494 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
495 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100496 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100497}
498
499/* Attempt to de-activate a channel that's not active */
500function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
501 timer T := 3.0;
502 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
503 T.start;
504 alt {
505 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
506 setverdict(pass);
507 }
508 [] T.timeout {
509 setverdict(fail, "Timeout expecting RF_CHAN_REL_ACK");
510 }
511 }
512}
513testcase TC_chan_deact_not_active() runs on test_CT {
514 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100515 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100516 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
517 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100518 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100519}
520
521/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
522function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
523 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
524 alt {
525 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
526 setverdict(fail, "Unexpected CHAN ACT ACK");
527 }
528 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
529 setverdict(pass);
530 }
531 }
532}
533private type record WrongChanNrCase {
534 RslChannelNr chan_nr,
535 charstring description
536}
537private type record of WrongChanNrCase WrongChanNrCases;
538private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
539 chan_nr := chan_nr,
540 description := desc
541}
542
543testcase TC_chan_act_wrong_nr() runs on test_CT {
544 var ConnHdlr vc_conn;
545 var ConnHdlrPars pars;
546
Harald Welte294b0a22018-03-10 23:26:48 +0100547 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100548
549 var WrongChanNrCases wrong := {
550 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
551 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
552 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
553 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
554 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
555 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
556 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
557 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
558 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
559 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
560 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
561 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
562 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
563 };
564
565 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
566 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
567 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
568 vc_conn.done;
569 }
Harald Welte294b0a22018-03-10 23:26:48 +0100570 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100571}
572
Harald Welte93640c62018-02-25 16:59:33 +0100573/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100574 * SACCH handling
575 ***********************************************************************/
576
577private function f_exp_sacch(boolean exp) runs on ConnHdlr {
578 timer T_sacch := 3.0;
579 T_sacch.start;
580 alt {
581 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
582 setverdict(fail, "Received SACCH when not expecting it");
583 }
584 [not exp] T_sacch.timeout {
585 setverdict(pass);
586 }
587 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
588 setverdict(pass);
589 }
590 [exp] T_sacch.timeout {
591 setverdict(fail, "Timeout waiting for SACCH on ", g_chan_nr);
592 }
593 [] L1CTL.receive { repeat; }
594 [] RSL.receive { repeat; }
595 }
596}
597
598/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
599private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
600 f_l1_tune(L1CTL);
601 RSL.clear;
602
603 /* activate the logical channel */
604 f_est_dchan();
605 L1CTL.clear;
606
607 /* check that SACCH actually are received as expected */
608 f_exp_sacch(true);
609
610 /* deactivate SACCH on the logical channel */
611 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
612 f_sleep(1.0);
613 L1CTL.clear;
614
615 /* check that no SACCH are received anymore */
616 f_exp_sacch(false);
617
618 /* release the channel */
619 f_rsl_chan_deact();
620 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
621}
622testcase TC_deact_sacch() runs on test_CT {
623 var ConnHdlr vc_conn;
624 var ConnHdlrPars pars;
625 f_init();
626 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
627 //for (var integer i := 0; i < 1; i := i+1) {
628 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
629 log(testcasename(), ": Starting for ", g_AllChannels[i]);
630 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
631 vc_conn.done;
632 }
633 /* TODO: do the above in parallel, rather than sequentially? */
634 f_shutdown();
635}
636
637/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
638/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
639/* Test for SACCH transmission rules in the context of special CHAN ACT (HO) */
640
641
642/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +0100643 * RACH Handling
644 ***********************************************************************/
645
Harald Welte8c24c2b2018-02-26 08:31:31 +0100646/* like L1SAP_IS_PACKET_RACH */
647private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +0100648 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +0100649 return true;
650 }
651 return false;
652}
653
654/* generate a random RACH for circuit-switched */
655private function f_rnd_ra_cs() return OCT1 {
656 var OCT1 ra;
657 do {
658 ra := f_rnd_octstring(1);
659 } while (ra_is_ps(ra));
660 return ra;
661}
662
Harald Welte883340c2018-02-28 18:59:29 +0100663/* generate a random RACH for packet-switched */
664private function f_rnd_ra_ps() return OCT1 {
665 var OCT1 ra;
666 do {
667 ra := f_rnd_octstring(1);
668 } while (not ra_is_ps(ra));
669 return ra;
670}
671
Harald Welte8c24c2b2018-02-26 08:31:31 +0100672/* Send 1000 RACH requests and check their RA+FN on the RSL side */
673testcase TC_rach_content() runs on test_CT {
674 f_init(testcasename());
675 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +0100676 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100677
Harald Welte8c24c2b2018-02-26 08:31:31 +0100678 var GsmFrameNumber fn_last := 0;
679 for (var integer i := 0; i < 1000; i := i+1) {
680 var OCT1 ra := f_rnd_ra_cs();
681 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
682 if (fn == fn_last) {
683 setverdict(fail, "Two RACH in same FN?!?");
684 self.stop;
685 }
686 fn_last := fn;
687
688 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +0100689 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +0100690 alt {
691 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
692 T.stop;
693 }
694 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
695 setverdict(fail, "Unexpected CHAN RQD");
696 self.stop;
697 }
698 [] RSL_CCHAN.receive { repeat; }
699 [] T.timeout {
700 setverdict(fail, "Timeout waiting for CHAN RQD");
701 self.stop;
702 }
703 }
704 }
705 setverdict(pass);
Harald Welte294b0a22018-03-10 23:26:48 +0100706 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100707}
Harald Welte8c24c2b2018-02-26 08:31:31 +0100708
709/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
710testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +0100711 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +0100712 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +0100713 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +0100714 f_l1_tune(L1CTL);
715
716 var GsmFrameNumber fn_last := 0;
717 for (var integer i := 0; i < 1000; i := i+1) {
718 var OCT1 ra := f_rnd_ra_cs();
719 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
720 if (fn == fn_last) {
721 setverdict(fail, "Two RACH in same FN?!?");
722 self.stop;
723 }
724 fn_last := fn;
725 }
726 var integer rsl_chrqd := 0;
727 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +0100728 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +0100729 alt {
730 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
731 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +0100732 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +0100733 repeat;
734 }
735 [] RSL_CCHAN.receive { repeat; }
736 [] T.timeout { }
737 }
738 if (rsl_chrqd == 1000) {
739 setverdict(pass);
740 } else {
741 setverdict(fail, "Received only ", rsl_chrqd, " out of 1000 RACH");
742 }
Harald Welte294b0a22018-03-10 23:26:48 +0100743 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100744}
745
Harald Welte54a2a2d2018-02-26 09:14:05 +0100746private function f_main_trxc_connect() runs on test_CT {
747 map(self:BB_TRXC, system:BB_TRXC);
748 var Result res;
Harald Welted3a88a62018-03-01 16:04:52 +0100749 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
750 "", -1, -1, {udp:={}}, {});
Harald Welte54a2a2d2018-02-26 09:14:05 +0100751 g_bb_trxc_conn_id := res.connId;
752}
753
754private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100755 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100756 /* tell fake_trx to use a given timing offset for all bursts */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100757 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +0100758 f_sleep(0.5);
759
760 /* Transmit RACH request + wait for confirmation */
761 var OCT1 ra := f_rnd_ra_cs();
762 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
763
764 /* Check for expected result */
765 timer T := 1.5;
766 T.start;
767 alt {
768 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
769 setverdict(pass);
770 }
771 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welteb3e30942018-03-02 10:33:42 +0100772 setverdict(fail, "RACH passed but was expected to be dropped: ", toffs256);
Harald Welte54a2a2d2018-02-26 09:14:05 +0100773 }
774 [] RSL_CCHAN.receive { repeat; }
775 [not expect_pass] T.timeout {
776 setverdict(pass);
777 }
778 [expect_pass] T.timeout {
779 setverdict(fail, "Timeout waiting for CHAN RQD");
780 }
781 }
782}
783
784/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
785testcase TC_rach_max_ta() runs on test_CT {
786 f_init(testcasename());
787 f_init_l1ctl();
788 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +0100789 f_sleep(1.0);
790
791 /* default max-ta is 63 (full range of GSM timing advance */
792
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +0700793 /* We allow early arrival up to 2 symbols */
794 f_rach_toffs(-1*256, true);
795 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +0100796 f_rach_toffs(-10*256, false);
797
798 /* 0 / 32 / 63 bits is legal / permitted */
799 f_rach_toffs(0, true);
800 f_rach_toffs(32*256, true);
801 f_rach_toffs(63*256, true);
802
803 /* more than 63 bits is not legal / permitted */
804 f_rach_toffs(64*256, false);
805 f_rach_toffs(127*256, false);
Harald Welte294b0a22018-03-10 23:26:48 +0100806 f_shutdown();
Harald Welte54a2a2d2018-02-26 09:14:05 +0100807}
Harald Welte8c24c2b2018-02-26 08:31:31 +0100808
Harald Welte93640c62018-02-25 16:59:33 +0100809/***********************************************************************
810 * Measurement Processing / Reporting
811 ***********************************************************************/
812
Harald Welte70767382018-02-21 12:16:40 +0100813template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
814 spare := '0'B,
815 lpd := 0,
816 sapi := sapi,
817 c_r := c_r,
818 ea := true
819}
820
821template LapdmFrameB ts_LAPDm_B(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
822 addr := ts_LapdmAddr(sapi, c_r),
823 ctrl := t_LapdmCtrlUI(p),
824 len := 0, /* overwritten */
825 m := false,
826 el := 1,
827 payload := pl
828}
829
830/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
831altstep as_l1_sacch() runs on ConnHdlr {
832 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +0100833 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +0100834 log("SACCH received: ", l1_dl.payload.data_ind.payload);
835 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, 23, 23, 0, 0, omit));
836 var LapdmFrameB lb := valueof(ts_LAPDm_B(0, false, false, enc_GsmRrL3Message(meas_rep)));
837 log("LAPDm: ", lb);
838 var octetstring pl := '0000'O & enc_LapdmFrameB(lb);
Harald Weltef8df4cb2018-03-10 15:15:08 +0100839 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_SACCH(0), pl));
Harald Welte70767382018-02-21 12:16:40 +0100840 repeat;
841 }
842}
843
844altstep as_l1_dcch() runs on ConnHdlr {
845 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +0100846 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +0100847 log("DCCH received: ", l1_dl.payload.data_ind.payload);
848 var octetstring pl := '010301'O;
Harald Weltef8df4cb2018-03-10 15:15:08 +0100849 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), pl));
Harald Welte70767382018-02-21 12:16:40 +0100850 repeat;
851 }
852}
853
854type record MeasElem {
855 uint6_t rxlev,
856 uint3_t rxqual
857}
858
859type record MeasElemFS {
860 MeasElem full,
861 MeasElem sub
862}
863
864type record ConnL1Pars {
865 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +0100866 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +0100867 MeasElemFS meas_ul,
868 int16_t timing_offset_256syms,
869 uint5_t bs_power_level,
870 uint5_t ms_power_level,
871 uint8_t ms_actual_ta
872}
873
874/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
875private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
876 return 63 + (toffs256s/256);
877}
878
Harald Welted5684392018-03-10 18:22:04 +0100879private function f_max(integer a, integer b) return integer {
880 if (a > b) {
881 return a;
882 } else {
883 return b;
884 }
885}
886
887private function f_min(integer a, integer b) return integer {
888 if (a < b) {
889 return a;
890 } else {
891 return b;
892 }
893}
894
895/* compute negative tolerance val-tolerance, ensure >= min */
896private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
897 val := val - tolerance;
898 return f_max(val, min);
899}
900
901/* compute positive tolerance val+tolerance, ensure <= max */
902private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
903 val := val + tolerance;
904 return f_min(val, max);
905}
906
907/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
908private function f_tolerance(integer val, integer min, integer max, integer tolerance)
909return template integer {
910 var template integer ret;
911 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
912 return ret;
913}
914
915
Harald Welte70767382018-02-21 12:16:40 +0100916/* build a template for matching measurement results against */
917private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
918 var ConnL1Pars l1p := g_pars.l1_pars;
919 var template RSL_IE_UplinkMeas ul_meas := {
920 len := 3,
921 rfu := '0'B,
922 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +0100923 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +0100924 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +0100925 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +0100926 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +0100927 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
928 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +0100929 supp_meas_info := omit
930 };
Harald Welte685d5982018-02-27 20:42:05 +0100931 if (l1p.toa256_enabled) {
932 ul_meas.len := 5;
933 ul_meas.supp_meas_info := int2oct(l1p.timing_offset_256syms, 2);
934 }
Harald Welte70767382018-02-21 12:16:40 +0100935 /* HACK HACK HACK FIXME HACK HACK HACK see https://osmocom.org/issues/2988 */
936 ul_meas.rxlev_f_u := ?;
937 ul_meas.rxlev_s_u := ?;
938 ul_meas.rxq_f_u := ?;
939 ul_meas.rxq_s_u := ?;
940 var template RSL_IE_BS_Power bs_power := {
941 reserved := 0,
942 epc := false,
943 fpc := false,
944 power_level := l1p.bs_power_level
945 };
946 var template RSL_IE_L1Info l1_info := {
947 ms_power_lvl := l1p.ms_power_level,
948 fpc := false,
949 reserved := 0,
950 actual_ta := l1p.ms_actual_ta
951 };
952 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
953 var template uint8_t t_toffs := (offs-1 .. offs+1); /* some tolerance */
954 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
955 ?, t_toffs);
956}
957
958/* verify we regularly receive measurement reports with incrementing numbers */
959altstep as_meas_res() runs on ConnHdlr {
960 var RSL_Message rsl;
961 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
962 /* increment counter of next to-be-expected meas rep */
963 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
964 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +0100965 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +0100966 repeat;
967 }
968 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +0100969 /* increment counter of next to-be-expected meas rep */
970 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
971 if (g_first_meas_res) {
972 g_first_meas_res := false;
973 repeat;
974 } else {
975 setverdict(fail, "Received unspecific MEAS RES ", rsl);
976 self.stop;
977 }
Harald Welte70767382018-02-21 12:16:40 +0100978 }
979 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
980 setverdict(fail, "Received unexpected MEAS RES ", rsl);
981 self.stop;
982 }
983 [] g_Tmeas_exp.timeout {
984 setverdict(fail, "Didn't receive expected measurement result")
985 self.stop;
986 }
987}
988
989/* Establish dedicated channel: L1CTL + RSL side */
990private function f_est_dchan() runs on ConnHdlr {
991 var GsmFrameNumber fn;
992 var ImmediateAssignment imm_ass;
993 var integer ra := 23;
994
995 fn := f_L1CTL_RACH(L1CTL, ra);
996 /* This arrives on CCHAN, so we cannot test for receiving CHAN RQDhere */
997 //RSL.receive(tr_RSL_CHAN_RQD(int2oct(23,1)));
998
999 /* Activate channel on BTS side */
1000 f_rsl_chan_act(g_pars.chan_mode);
1001
1002 /* Send IMM.ASS via CCHAN */
1003 var ChannelDescription ch_desc := {
1004 chan_nr := g_pars.chan_nr,
1005 tsc := 7,
1006 h := false,
1007 arfcn := mp_trx0_arfcn,
1008 maio_hsn := omit
1009 };
1010 var MobileAllocation ma := {
1011 len := 0,
1012 ma := ''B
1013 };
1014 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1015 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1016
1017 /* receive IMM.ASS on MS side */
1018 var ImmediateAssignment ia_um;
1019 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1020 /* enable dedicated mode */
1021 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltefa45e9e2018-03-10 18:59:03 +01001022
1023 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001024}
1025
1026/* establish DChan, verify existance + contents of measurement reports */
1027function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001028 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001029 RSL.clear;
1030
Harald Welte5398d5e2018-03-10 19:00:24 +01001031 if (mp_bb_trxc_port != -1) {
1032 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-100);
1033 f_trxc_fake_rssi(100);
Harald Welte70767382018-02-21 12:16:40 +01001034
Harald Welte5398d5e2018-03-10 19:00:24 +01001035 g_pars.l1_pars.timing_offset_256syms := 512; /* 2 symbols */
1036 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1037 } else {
1038 g_pars.l1_pars.timing_offset_256syms := 0; /* FIXME */
1039 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-55); /* FIXME */
1040 }
1041 g_pars.l1_pars.meas_ul.sub.rxlev := g_pars.l1_pars.meas_ul.full.rxlev;
Harald Welte70767382018-02-21 12:16:40 +01001042
1043 f_est_dchan();
1044
1045 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1046 * RSL measurement reports on Abis side */
1047 timer T := 8.0;
1048 T.start;
1049 alt {
1050 [] as_l1_sacch();
1051 [] as_meas_res();
1052 [] as_l1_dcch();
1053 [] L1CTL.receive { repeat; }
1054 [g_Tmeas_exp.running] T.timeout {
1055 /* as_meas_res() would have done setverdict(fail) / self.stop in case
1056 * of any earlier errors, so if we reach this timeout, we're good */
1057 setverdict(pass);
1058 }
1059 [] T.timeout {
1060 setverdict(fail, "No MEAS RES received at all");
1061 }
1062 }
1063 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001064 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001065}
1066testcase TC_meas_res_sign_tchf() runs on test_CT {
1067 var ConnHdlr vc_conn;
1068 var ConnHdlrPars pars;
1069 f_init(testcasename());
1070 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1071 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1072 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1073 vc_conn.done;
1074 }
Harald Welte294b0a22018-03-10 23:26:48 +01001075 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001076}
1077testcase TC_meas_res_sign_tchh() runs on test_CT {
1078 var ConnHdlr vc_conn;
1079 var ConnHdlrPars pars;
1080 f_init(testcasename());
1081 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1082 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1083 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1084 vc_conn.done;
1085 }
Harald Welte294b0a22018-03-10 23:26:48 +01001086 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001087}
1088testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1089 var ConnHdlr vc_conn;
1090 var ConnHdlrPars pars;
1091 f_init(testcasename());
1092 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1093 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1094 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1095 vc_conn.done;
1096 }
Harald Welte294b0a22018-03-10 23:26:48 +01001097 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001098}
1099testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1100 var ConnHdlr vc_conn;
1101 var ConnHdlrPars pars;
1102 f_init(testcasename());
1103 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1104 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1105 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1106 vc_conn.done;
1107 }
Harald Welte294b0a22018-03-10 23:26:48 +01001108 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001109}
Harald Welte685d5982018-02-27 20:42:05 +01001110testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1111 var ConnHdlr vc_conn;
1112 var ConnHdlrPars pars;
1113 f_init(testcasename());
1114 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1115 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1116 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1117 pars.l1_pars.toa256_enabled := true;
1118 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1119 vc_conn.done;
1120 }
Harald Welte294b0a22018-03-10 23:26:48 +01001121 f_shutdown();
Harald Welte685d5982018-02-27 20:42:05 +01001122}
1123
Harald Welte70767382018-02-21 12:16:40 +01001124
1125/* Test if a channel without valid uplink bursts generates RSL CONN FAIL IND */
1126private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001127 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001128 RSL.clear;
1129
1130 f_est_dchan();
1131 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001132 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001133
1134 timer T := 40.0;
1135 T.start;
1136 alt {
1137 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
1138 setverdict(pass)
1139 }
1140 [] RSL.receive { repeat };
1141 [] T.timeout {
1142 setverdict(fail, "No CONN FAIL IND received");
1143 }
1144 }
1145 f_rsl_chan_deact();
1146}
1147testcase TC_conn_fail_crit() runs on test_CT {
1148 var ConnHdlr vc_conn;
1149 var ConnHdlrPars pars;
1150 f_init(testcasename());
1151 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
1152 pars.t_guard := 60.0;
1153 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
1154 vc_conn.done;
1155}
1156
Harald Welte93640c62018-02-25 16:59:33 +01001157/***********************************************************************
1158 * Paging
1159 ***********************************************************************/
1160
Harald Welte68e495b2018-02-25 00:05:57 +01001161function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
1162 if (tmsi == 'FFFFFFFF'O) {
1163 return true;
1164 } else {
1165 return false;
1166 }
1167}
Harald Welte70767382018-02-21 12:16:40 +01001168
Harald Welte68e495b2018-02-25 00:05:57 +01001169altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids)
1170runs on test_CT {
1171 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001172 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01001173 repeat;
1174 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01001175 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01001176 var octetstring without_plen :=
1177 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
1178 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
1179 if (match(rr, tr_PAGING_REQ1)) {
1180 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1181 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1182 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
1183 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1184 }
1185 } else if (match(rr, tr_PAGING_REQ2)) {
1186 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1187 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
1188 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1189 }
1190 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
1191 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1192 }
1193 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
1194 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1195 }
1196 } else if (match(rr, tr_PAGING_REQ3)) {
1197 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1198 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
1199 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1200 }
1201 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
1202 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1203 }
1204 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
1205 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1206 }
1207 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
1208 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1209 }
1210 }
1211 repeat;
1212 }
1213}
1214
1215type record PagingTestCfg {
1216 boolean combined_ccch,
1217 integer bs_ag_blks_res,
1218 float load_factor,
1219 boolean exp_load_ind,
1220 boolean exp_overload,
1221 boolean use_tmsi
1222}
1223
1224type record PagingTestState {
1225 integer num_paging_sent,
1226 integer num_paging_rcv_msgs,
1227 integer num_paging_rcv_ids,
1228 integer num_overload
1229}
1230
1231/* receive + ignore RSL RF RES IND */
1232altstep as_rsl_res_ind() runs on test_CT {
1233 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
1234 repeat;
1235 }
1236}
1237
1238/* Helper function for paging related testing */
1239private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
1240 f_init(testcasename());
1241 f_init_l1ctl();
1242 f_l1_tune(L1CTL);
1243
1244 var PagingTestState st := {
1245 num_paging_sent := 0,
1246 num_paging_rcv_msgs := 0,
1247 num_paging_rcv_ids := 0,
1248 num_overload := 0
1249 };
1250
1251 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
1252 var float max_pch_imsi_per_sec;
1253 if (cfg.use_tmsi) {
1254 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
1255 } else {
1256 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
1257 }
1258 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
1259 var float interval := 1.0 / pch_blocks_per_sec;
1260 log("pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
1261
1262 for (var integer i := 0; i < float2int(20.0/interval); i := i+1) {
1263 /* build mobile Identity */
1264 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
1265 if (cfg.use_tmsi) {
1266 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
1267 } else {
1268 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
1269 }
1270 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
1271 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
1272
1273 /* Send RSL PAGING COMMAND */
1274 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
1275 st.num_paging_sent := st.num_paging_sent + 1;
1276
1277 /* Wait for interval to next PAGING COMMAND */
1278 timer T_itv := interval;
1279 T_itv.start;
1280 alt {
1281 /* check for presence of CCCH LOAD IND (paging load) */
1282 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1283 st.num_overload := st.num_overload + 1;
1284 repeat;
1285 }
1286 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1287 setverdict(fail, "Unexpected PCH Overload");
1288 }
1289 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
1290 log("Rx LOAD_IND");
1291 /* FIXME: analyze/verify interval + contents */
1292 repeat;
1293 }
1294 /* check if paging requests arrive on Um side */
1295 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1296 [] L1CTL.receive { repeat; }
1297 [] T_itv.timeout { }
1298 [] as_rsl_res_ind();
1299 }
1300 }
1301
1302 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
1303 timer T_wait := 18.0;
1304 T_wait.start;
1305 alt {
1306 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1307 [] L1CTL.receive { repeat; }
1308 /* 65535 == empty paging queue, we can terminate*/
1309 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
1310 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
1311 [] T_wait.timeout {
1312 setverdict(fail, "Waiting for empty paging queue");
1313 }
1314 [] as_rsl_res_ind();
1315 }
1316
Harald Welte294b0a22018-03-10 23:26:48 +01001317 f_shutdown();
1318
Harald Welte68e495b2018-02-25 00:05:57 +01001319 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
1320 " rcvd_ids=", st.num_paging_rcv_ids);
1321 return st;
1322}
1323
1324/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
1325 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1326 * - that CCCH LOAD IND (PCH) are being generated
1327 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1328testcase TC_paging_imsi_80percent() runs on test_CT {
1329 var PagingTestCfg cfg := {
1330 combined_ccch := true,
1331 bs_ag_blks_res := 1,
1332 load_factor := 0.8,
1333 exp_load_ind := true,
1334 exp_overload := false,
1335 use_tmsi := false
1336 };
1337 var PagingTestState st := f_TC_paging(cfg);
1338 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1339 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1340 st.num_paging_rcv_ids);
1341 } else {
1342 setverdict(pass);
1343 }
1344}
1345
1346/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
1347 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1348 * - that CCCH LOAD IND (PCH) are being generated
1349 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1350testcase TC_paging_tmsi_80percent() runs on test_CT {
1351 var PagingTestCfg cfg := {
1352 combined_ccch := true,
1353 bs_ag_blks_res := 1,
1354 load_factor := 0.8,
1355 exp_load_ind := true,
1356 exp_overload := false,
1357 use_tmsi := true
1358 };
1359 var PagingTestState st := f_TC_paging(cfg);
1360 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1361 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1362 st.num_paging_rcv_ids);
1363 } else {
1364 setverdict(pass);
1365 }
1366}
1367
1368/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
1369 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1370 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1371 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1372testcase TC_paging_imsi_200percent() runs on test_CT {
1373 var PagingTestCfg cfg := {
1374 combined_ccch := true,
1375 bs_ag_blks_res := 1,
1376 load_factor := 2.0,
1377 exp_load_ind := true,
1378 exp_overload := true,
1379 use_tmsi := false
1380 };
1381 var PagingTestState st := f_TC_paging(cfg);
1382 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
1383 * slots and will fully drain that buffer before returning */
1384 var template integer tpl := (st.num_paging_sent*80/100 .. st.num_paging_sent *85/100);
1385 if (not match(st.num_paging_rcv_ids, tpl)) {
1386 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1387 } else {
1388 setverdict(pass);
1389 }
1390}
1391
1392/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
1393 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1394 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1395 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1396testcase TC_paging_tmsi_200percent() runs on test_CT {
1397 var PagingTestCfg cfg := {
1398 combined_ccch := true,
1399 bs_ag_blks_res := 1,
1400 load_factor := 2.0,
1401 exp_load_ind := true,
1402 exp_overload := true,
1403 use_tmsi := true
1404 };
1405 var PagingTestState st := f_TC_paging(cfg);
1406 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
1407 * slots and will fully drain that buffer before returning */
1408 var template integer tpl := (st.num_paging_sent*68/100 .. st.num_paging_sent *72/100);
1409 if (not match(st.num_paging_rcv_ids, tpl)) {
1410 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1411 } else {
1412 setverdict(pass);
1413 }
1414}
1415
1416
Harald Welte93640c62018-02-25 16:59:33 +01001417/***********************************************************************
1418 * Immediate Assignment / AGCH
1419 ***********************************************************************/
1420
Harald Welte68e495b2018-02-25 00:05:57 +01001421testcase TC_imm_ass() runs on test_CT {
1422 f_init(testcasename());
1423 for (var integer i := 0; i < 1000; i := i+1) {
1424 var octetstring ia_enc := f_rnd_octstring(8);
1425 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
1426 f_sleep(0.02);
1427 }
1428 /* FIXME: check if imm.ass arrive on Um side */
1429 /* FIXME: check for DELETE INDICATION */
1430 f_sleep(100.0);
Harald Welte294b0a22018-03-10 23:26:48 +01001431 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01001432}
1433
Harald Welte48494ca2018-02-25 16:59:50 +01001434/***********************************************************************
1435 * BCCH
1436 ***********************************************************************/
1437
1438/* tuple of Frame Number + decoded SI */
1439type record SystemInformationFn {
1440 GsmFrameNumber frame_number,
1441 SystemInformation si
1442}
1443
1444/* an arbitrary-length vector of decoded SI + gsmtap header */
1445type record of SystemInformationFn SystemInformationVector;
1446
1447/* an array of SI-vectors indexed by TC value */
1448type SystemInformationVector SystemInformationVectorPerTc[8];
1449
1450/* determine if a given SI vector contains given SI type at least once */
1451function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1452 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1453 var integer fn_mod51 := arr[i].frame_number mod 51;
1454 if (not bcch_ext and fn_mod51 == 2 or
1455 bcch_ext and fn_mod51 == 6) {
1456 if (arr[i].si.header.message_type == key) {
1457 return true;
1458 }
1459 }
1460 }
1461 return false;
1462}
1463
1464/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
1465function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1466 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
1467 setverdict(fail, "No ", key, " in TC=", tc, "!");
1468 }
1469}
1470
1471/* check if a given SI vector contains given SI type at least once on any TC */
1472function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
1473 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
1474 if (f_si_vecslot_contains(arr[tc], key) or
1475 f_si_vecslot_contains(arr[tc], key, true)) {
1476 return true;
1477 }
1478 }
1479 return false;
1480}
1481
1482/* determine if a given SI vector contains given SI type at least N of M times */
1483function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
1484 var integer count := 0;
1485 if (sizeof(arr) < m) {
1486 setverdict(fail, "Error: Insufficient SI in array");
1487 self.stop;
1488 }
1489 for (var integer i:= 0; i < m; i := i + 1) {
1490 var integer fn_mod51 := arr[i].frame_number mod 51;
1491 if (not bcch_ext and fn_mod51 == 2 or
1492 bcch_ext and fn_mod51 == 6) {
1493 if (arr[i].si.header.message_type == key) {
1494 count := count + 1;
1495 }
1496 }
1497 }
1498 if (count >= n) {
1499 return true;
1500 } else {
1501 return false;
1502 }
1503}
1504
1505/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
1506function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
1507 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
1508 setverdict(fail, "Not ", n, "/", m, " of ", key, " in TC=", tc, "!");
1509 }
1510}
1511
1512/* determine if a given SI vector contains given SI type at least once */
1513function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1514 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1515 var integer fn_mod51 := arr[i].frame_number mod 51;
1516 if (not bcch_ext and fn_mod51 == 2 or
1517 bcch_ext and fn_mod51 == 6) {
1518 if (arr[i].si.header.message_type != key) {
1519 return false;
1520 }
1521 }
1522 }
1523 return true;
1524}
1525
1526/* ensure a given TC slot of the SI vector contains only given SI type */
1527function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1528 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
1529 setverdict(fail, "Not all ", key, " in TC=", tc, "!");
1530 }
1531}
1532
1533/* SI configuration of cell, against which we validate actual SI messages */
1534type set SystemInformationConfig {
1535 boolean bcch_extended,
1536 boolean si1_present,
1537 boolean si2bis_present,
1538 boolean si2ter_present,
1539 boolean si2quater_present,
1540 boolean si7_present,
1541 boolean si8_present,
1542 boolean si9_present,
1543 boolean si13_present,
1544 boolean si13alt_present,
1545 boolean si15_present,
1546 boolean si16_present,
1547 boolean si17_present,
1548 boolean si2n_present,
1549 boolean si21_present,
1550 boolean si22_present
1551}
1552
1553/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
1554function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
1555 var integer i;
1556 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
1557 if (sizeof(si_per_tc[i]) == 0) {
Harald Welte544565a2018-03-02 10:34:08 +01001558 setverdict(fail, "No SI messages for TC=", i);
Harald Welte48494ca2018-02-25 16:59:50 +01001559 }
1560 }
1561 if (cfg.si1_present) {
1562 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
1563 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
1564 * when TC = 0, it can assume that System Information Type 1 is not in use. */
1565 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
1566 /* make sure *ALL* contain SI1 */
1567 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
1568 }
1569 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
1570 /* iii) A SI 2 message will be sent at least every time TC = 1 */
1571 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
1572 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
1573 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
1574 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
1575
1576 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
1577 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
1578 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
1579 * consecutive occurrences of TC = 4. */
1580 if (cfg.si2bis_present and not cfg.si2ter_present) {
1581 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
1582 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
1583 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
1584 } else if (cfg.si2ter_present and cfg.si2bis_present) {
1585 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
1586 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
1587 }
1588
1589 if (cfg.si7_present or cfg.si8_present) {
1590 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
1591 * if System Information type 4 does not contain all information needed for cell
1592 * selection and reselection. */
1593 if (not cfg.bcch_extended) {
1594 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
1595 }
1596 if (cfg.si7_present) {
1597 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
1598 }
1599 if (cfg.si8_present) {
1600 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
1601 }
1602 }
1603
1604 if (cfg.si2quater_present) {
1605 /* iii) System information type 2 quater is sent if needed, as determined by the system
1606 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
1607 * and 2ter are used, otherwise it shall be sent at least once within any of 4
1608 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
1609 * within any of 4 consecutive occurrences of TC = 5. */
1610 if (not (cfg.bcch_extended)) {
1611 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
1612 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
1613 } else {
1614 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
1615 }
1616 } else {
1617 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
1618 }
1619 }
1620 if (cfg.si9_present) {
1621 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
1622 * in system information type 3 as defined in 3GPP TS 44.018. */
1623 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
1624 }
1625 if (cfg.si13_present) {
1626 /* vii) System Information type 13 is only related to the GPRS service. System Information
1627 * Type 13 need only be sent if GPRS support is indicated in one or more of System
1628 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
1629 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
1630 * In the case that the message is sent on the BCCH Norm, it is sent at least once
1631 * within any of 4 consecutive occurrences of TC=4. */
1632 if (not cfg.bcch_extended) {
1633 log("not-bccch-extended");
1634 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
1635 } else {
1636 log("bccch-extended");
1637 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
1638 }
1639 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
1640 setverdict(fail, "Cannot have SI13alt and SI13");
1641 }
1642 }
1643 if (cfg.si16_present or cfg.si17_present) {
1644 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
1645 * should not be sent in a cell where network sharing is used (see rule xv). */
1646 if (cfg.si22_present) {
1647 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
1648 }
1649 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
1650 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
1651 }
1652 if (not cfg.bcch_extended) {
1653 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
1654 }
1655 if (cfg.si16_present) {
1656 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
1657 }
1658 if (cfg.si17_present) {
1659 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
1660 }
1661 }
1662
1663 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
1664 * broadcast information. The frequency with which they are sent is determined by the
1665 * system operator. System Information type 9 identifies the scheduling of System
1666 * Information type 18 and 20 messages. */
1667
1668 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
1669 * Information Type 19 is present, then its scheduling shall be indicated in System
1670 * Information Type 9. */
1671
1672 if (cfg.si15_present) {
1673 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
1674 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
1675 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
1676 * 4 consecutive occurrences of TC = 1. */
1677 if (not cfg.bcch_extended) {
1678 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
1679 } else {
1680 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
1681 }
1682 }
1683 if (cfg.si13alt_present) {
1684 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
1685 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
1686 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
1687 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
1688 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
1689 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
1690 * of TC = 4. */
1691 if (cfg.si13_present) {
1692 testcase.stop("Error: Cannot have SI13alt and SI13");
1693 }
1694 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
1695 setverdict(fail, "Cannot have SI13alt and SI13");
1696 }
1697 if (not cfg.bcch_extended) {
1698 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
1699 } else {
1700 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
1701 }
1702 }
1703 if (cfg.si2n_present) {
1704 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
1705 * as determined by the system operator. In the case that the message is sent on the
1706 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
1707 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
1708 * consecutive occurrences of TC = 4. */
1709 if (not cfg.bcch_extended) {
1710 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
1711 } else {
1712 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
1713 }
1714 }
1715 if (cfg.si21_present) {
1716 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
1717 * determined by the system operator. If Extended Access Barring is in use in the cell
1718 * then this message is sent at least once within any of 4 consecutive occurrences of
1719 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
1720 * cell then this message shall only be sent on BCCH Ext. */
1721 if (not cfg.bcch_extended) {
1722 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
1723 } else {
1724 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
1725 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
1726 setverdict(fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
1727 }
1728 }
1729 }
1730 if (cfg.si22_present) {
1731 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
1732 * should not be sent in a cell where SoLSA is used (see rule viii). System
1733 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
1734 * =2 and TC=6. */
1735 if (cfg.si16_present or cfg.si17_present) {
1736 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
1737 }
1738 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
1739 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
1740 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
1741 }
1742 if (not cfg.bcch_extended) {
1743 testcase.stop("Error: SI22 requires BCCH Extd!");
1744 } else {
1745 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
1746 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
1747 }
1748 }
1749}
1750
1751/* sample Systme Information for specified duration via L1CTL */
1752function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
1753 timer T := duration;
1754 var SystemInformationVectorPerTc si_per_tc;
1755 var L1ctlDlMessage l1_dl;
1756
1757 /* initialize all per-TC vectors empty */
1758 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
1759 si_per_tc[i] := {};
1760 }
1761
1762 /* flush all previous L1 queued msgs */
1763 pt.clear;
1764
1765 T.start;
1766 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001767 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01001768 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
1769 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
1770 log("Ignoring non-RR SI ", l1_dl);
1771 repeat;
1772 }
1773 var SystemInformationFn sig := {
1774 frame_number := l1_dl.dl_info.frame_nr,
1775 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
1776 }
1777 var integer tc := f_gsm_compute_tc(sig.frame_number);
1778 log("SI received at TC=", tc, ": ", sig.si);
1779 /* append to the per-TC bucket */
1780 si_per_tc[tc] := si_per_tc[tc] & { sig };
1781 repeat;
1782 }
1783 [] pt.receive { repeat; }
1784 [] T.timeout { }
1785 }
1786
1787 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
1788 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
1789 }
1790 log("si_per_tc=", si_per_tc);
1791 return si_per_tc;
1792}
1793
1794/* helper function: Set given SI via RSL + validate scheduling.
1795 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
1796function f_TC_si_sched() runs on test_CT {
1797 var SystemInformationVectorPerTc si_per_tc;
1798 f_init_l1ctl();
1799 f_l1_tune(L1CTL);
1800
1801 /* Sample + Validate Scheduling */
1802 si_per_tc := f_l1_sample_si(L1CTL);
1803 f_validate_si_scheduling(si_cfg, si_per_tc);
1804
1805 setverdict(pass);
1806}
1807
1808testcase TC_si_sched_default() runs on test_CT {
1809 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01001810 /* 2+3+4 are mandatory and set in f_init() */
1811 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01001812 f_shutdown();
Harald Welte0cae4552018-03-09 22:20:26 +01001813}
1814
1815testcase TC_si_sched_1() runs on test_CT {
1816 f_init();
1817 si_cfg.si1_present := true;
1818 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01001819 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01001820 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01001821}
1822
1823testcase TC_si_sched_2bis() runs on test_CT {
1824 f_init();
1825 si_cfg.si2bis_present := true;
1826 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
1827 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01001828 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01001829}
1830
1831testcase TC_si_sched_2ter() runs on test_CT {
1832 f_init();
1833 si_cfg.si2ter_present := true;
1834 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
1835 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01001836 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01001837}
1838
1839testcase TC_si_sched_2ter_2bis() runs on test_CT {
1840 f_init();
1841 si_cfg.si2bis_present := true;
1842 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
1843 si_cfg.si2ter_present := true;
1844 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
1845 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01001846 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01001847}
1848
1849testcase TC_si_sched_2quater() runs on test_CT {
1850 f_init();
1851 si_cfg.si2quater_present := true;
1852 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
1853 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01001854 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01001855}
1856
1857testcase TC_si_sched_13() runs on test_CT {
1858 f_init();
1859 si_cfg.si13_present := true;
1860 //f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, fixme);
1861 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01001862 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01001863}
1864
1865testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
1866 f_init();
1867 si_cfg.si2bis_present := true;
1868 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
1869 si_cfg.si2ter_present := true;
1870 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
1871 si_cfg.si2quater_present := true;
1872 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
1873 si_cfg.si13_present := true;
1874 //f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, fixme);
1875 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01001876 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01001877}
1878
1879
Harald Welte68e495b2018-02-25 00:05:57 +01001880testcase TC_bcch_info() runs on test_CT {
1881 f_init(testcasename());
1882 /* FIXME: enable / disable individual BCCH info */
1883 //ts_RSL_BCCH_INFO(si_type, info);
1884 /* expect no ERROR REPORT after either of them *
1885 /* negative test: ensure ERROR REPORT on unsupported types */
Harald Welte294b0a22018-03-10 23:26:48 +01001886 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01001887}
1888
Harald Welte93640c62018-02-25 16:59:33 +01001889/***********************************************************************
1890 * Low-Level Protocol Errors / ERROR REPORT
1891 ***********************************************************************/
1892
Harald Welte01d982c2018-02-25 01:31:40 +01001893private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
1894 timer T := 5.0;
1895 T.start;
1896 alt {
1897 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
1898 setverdict(pass);
1899 }
1900 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
1901 setverdict(fail, "Wrong cause in RSL ERR REP");
1902 }
1903 [] RSL_CCHAN.receive {
1904 repeat;
1905 }
1906 [] T.timeout {
1907 setverdict(fail, "Timeout waiting for RSL ERR REP");
1908 }
1909 }
1910}
1911
1912/* Provoke a protocol error (message too short) and match on ERROR REPORT */
1913testcase TC_rsl_protocol_error() runs on test_CT {
1914 f_init(testcasename());
1915 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
1916 rsl.ies := omit;
1917 RSL_CCHAN.send(ts_RSL_UD(rsl));
1918
1919 f_exp_err_rep(RSL_ERR_PROTO);
1920}
1921
1922/* Provoke a mandatory IE error and match on ERROR REPORT */
1923testcase TC_rsl_mand_ie_error() runs on test_CT {
1924 f_init(testcasename());
1925
1926 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
1927 rsl.ies := { rsl.ies[0] };
1928 RSL_CCHAN.send(ts_RSL_UD(rsl));
1929
1930 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
1931}
1932
1933/* Provoke an IE content error and match on ERROR REPORT */
1934testcase TC_rsl_ie_content_error() runs on test_CT {
1935 f_init(testcasename());
1936 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
1937 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
1938 RSL_CCHAN.send(ts_RSL_UD(rsl));
1939
1940 f_exp_err_rep(RSL_ERR_IE_CONTENT);
1941}
1942
Harald Welte93640c62018-02-25 16:59:33 +01001943/***********************************************************************
1944 * IPA CRCX/MDCX/DLCS media stream handling
1945 ***********************************************************************/
1946
Harald Weltea871a382018-02-25 02:03:14 +01001947/* Send IPA DLCX to inactive lchan */
1948function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01001949 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
1950 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01001951}
1952testcase TC_ipa_dlcx_not_active() runs on test_CT {
1953 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1954 f_init(testcasename());
1955 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
1956 vc_conn.done;
1957}
Harald Welte68e495b2018-02-25 00:05:57 +01001958
Harald Weltea3f1df92018-02-25 12:49:55 +01001959/* Send IPA CRCX twice to inactive lchan */
1960function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
1961 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
1962 "IPA CRCX ACK");
1963 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
1964 "IPA CRCX NACK");
1965}
1966testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
1967 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1968 f_init(testcasename());
1969 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
1970 vc_conn.done;
1971}
1972
1973/* Regular sequence of CRCX/MDCX/DLCX */
1974function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
1975 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
1976 "IPA CRCX ACK");
1977 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
1978 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
1979 var uint7_t rtp_pt2 := f_rnd_int(127);
1980 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
1981 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
1982 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
1983 "IPA MDCX ACK");
1984 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
1985 "IPA DLCX ACK");
1986}
1987testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
1988 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
1989 f_init(testcasename());
1990 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
1991 vc_conn.done;
1992}
1993
Harald Welte3ae11da2018-02-25 13:36:06 +01001994/* Sequence of CRCX, 2x MDCX, DLCX */
1995function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
1996 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
1997 "IPA CRCX ACK");
1998 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
1999 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2000 var uint7_t rtp_pt2 := f_rnd_int(127);
2001 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2002 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2003 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2004 "IPA MDCX ACK");
2005 /* Second MDCX */
2006 remote_ip := f_rnd_int(c_UINT32_MAX);
2007 remote_port := f_rnd_int(c_UINT16_MAX);
2008 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2009 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2010 "IPA MDCX ACK");
2011 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2012 "IPA DLCX ACK");
2013}
2014testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
2015 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2016 f_init(testcasename());
2017 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
2018 vc_conn.done;
2019}
2020
Harald Welte9912eb52018-02-25 13:30:15 +01002021/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
2022function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
2023 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
2024 "IPA CRCX NACK");
2025}
2026testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
2027 var ConnHdlrPars pars;
2028 var ConnHdlr vc_conn;
2029 f_init(testcasename());
2030
2031 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
2032 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2033 vc_conn.done;
2034
2035 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
2036 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2037 vc_conn.done;
2038}
2039
Harald Weltea3f1df92018-02-25 12:49:55 +01002040
Harald Welte883340c2018-02-28 18:59:29 +01002041/***********************************************************************
2042 * PCU Socket related tests
2043 ***********************************************************************/
2044
2045private function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
2046runs on test_CT {
2047 timer T := 3.0;
2048
2049 /* we don't expect any RTS.req before PDCH are active */
2050 T.start;
2051 alt {
2052 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
2053 setverdict(fail, "PCU RTS.req before PDCH active?");
2054 self.stop;
2055 }
2056 [] PCU.receive { repeat; }
2057 [] T.timeout { }
2058 }
2059
2060 /* Send PDCH activate request for known PDCH timeslot */
2061 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
2062
2063 /* we now expect RTS.req for this timeslot (only) */
2064 T.start;
2065 alt {
2066 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2067 setverdict(pass);
2068 }
2069 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2070 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2071 setverdict(fail, "Unexpected RTS.req for supposedly failing activation");
2072 self.stop;
2073 }
2074 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
2075 setverdict(fail, "RTS.req for wrong TRX/TS");
2076 self.stop;
2077 }
2078 [] PCU.receive { repeat; }
2079 [exp_success] T.timeout {
2080 setverdict(fail, "Timeout waiting for PCU RTS.req");
2081 }
2082 [not exp_success] T.timeout {
2083 setverdict(pass);
2084 }
2085 }
2086}
2087
2088private function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
2089runs on test_CT {
2090 timer T := 3.0;
2091
2092 /* Send PDCH activate request for known PDCH timeslot */
2093 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
2094
2095 PCU.clear;
2096 /* we now expect no RTS.req for this timeslot */
2097 T.start;
2098 alt {
2099 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2100 setverdict(fail, "Received unexpected PCU RTS.req");
2101 self.stop;
2102 }
2103 [] PCU.receive { repeat; }
2104 [] T.timeout {
2105 setverdict(pass);
2106 }
2107 }
2108}
2109
2110/* PDCH activation via PCU socket; check for presence of RTS.req */
2111testcase TC_pcu_act_req() runs on test_CT {
2112 f_init();
2113 f_TC_pcu_act_req(0, 0, 7, true);
2114}
2115
2116/* PDCH activation via PCU socket on non-PDCU timeslot */
2117testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
2118 f_init();
2119 f_TC_pcu_act_req(0, 0, 1, false);
2120}
2121
2122/* PDCH activation via PCU socket on wrong BTS */
2123testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
2124 f_init();
2125 f_TC_pcu_act_req(23, 0, 7, false);
2126}
2127
2128/* PDCH activation via PCU socket on wrong TRX */
2129testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
2130 f_init();
2131 f_TC_pcu_act_req(0, 23, 7, false);
2132}
2133
2134/* PDCH deactivation via PCU socket; check for absence of RTS.req */
2135testcase TC_pcu_deact_req() runs on test_CT {
2136 f_init();
2137 /* Activate PDCH */
2138 f_TC_pcu_act_req(0, 0, 7, true);
2139 f_sleep(1.0);
2140 /* and De-Activate again */
2141 f_TC_pcu_deact_req(0, 0, 7);
2142}
2143
2144/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
2145testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
2146 f_init();
2147 f_TC_pcu_deact_req(0, 0, 1);
2148}
2149
2150/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
2151testcase TC_pcu_ver_si13() runs on test_CT {
2152 const octetstring si13 := '00010203040506070909'O;
2153 var PCUIF_send_data sd;
2154 timer T:= 3.0;
2155 f_init();
2156
2157 /* Set SI13 via RSL */
2158 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
2159 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, "BTS_Test v23")));
2160 T.start;
2161 alt {
2162 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
2163 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
2164 setverdict(pass);
2165 } else {
2166 repeat;
2167 }
2168 }
2169 [] PCU.receive { repeat; }
2170 [] T.timeout {
2171 setverdict(fail, "Timeout waiting for SI13");
2172 self.stop;
2173 }
2174 }
2175}
2176
2177private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
2178
2179/* helper function to send a PCU DATA.req */
2180private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2181 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
2182runs on test_CT
2183{
2184 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
2185 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
2186}
2187
2188/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
2189private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2190 PCUIF_Sapi sapi, octetstring data)
2191runs on test_CT
2192{
2193 var PCUIF_send_data sd;
2194
2195 timer T := 3.0;
2196 T.start;
2197 alt {
2198 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2199 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2200 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2201 sd.data.u.rts_req.fn, sapi, data);
2202 }
2203 [] PCU.receive { repeat; }
2204 [] T.timeout {
2205 setverdict(fail, "Timeout waiting for RTS.ind");
2206 }
2207 }
2208}
2209
2210/* Send DATA.req on invalid BTS */
2211testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
2212 f_init();
2213 f_TC_pcu_act_req(0, 0, 7, true);
2214 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2215 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2216 f_sleep(10.0);
2217}
2218
2219/* Send DATA.req on invalid TRX */
2220testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
2221 f_init();
2222 f_TC_pcu_act_req(0, 0, 7, true);
2223 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2224 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2225 f_sleep(10.0);
2226}
2227
2228/* Send DATA.req on invalid timeslot */
2229testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
2230 f_init();
2231 f_TC_pcu_act_req(0, 0, 7, true);
2232 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2233 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2234 f_sleep(10.0);
2235}
2236
2237/* Send DATA.req on timeslot that hasn't been activated */
2238testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
2239 f_init();
2240 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2241 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2242 f_sleep(2.0);
2243}
2244
2245testcase TC_pcu_data_req_pdtch() runs on test_CT {
2246 f_init();
2247 f_TC_pcu_act_req(0, 0, 7, true);
2248 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2249 /* FIXME: how to check this was actually sent */
2250 f_sleep(2.0);
2251}
2252
2253testcase TC_pcu_data_req_ptcch() runs on test_CT {
2254 f_init();
2255 f_TC_pcu_act_req(0, 0, 7, true);
2256 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
2257 /* FIXME: how to check this was actually sent */
2258 f_sleep(2.0);
2259}
2260
2261/* Send AGCH from PCU; check it appears on Um side */
2262testcase TC_pcu_data_req_agch() runs on test_CT {
2263 timer T := 3.0;
2264 f_init();
2265 f_init_l1ctl();
2266 f_l1_tune(L1CTL);
2267
2268 f_TC_pcu_act_req(0, 0, 7, true);
2269 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
2270
2271 T.start;
2272 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002273 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01002274 setverdict(pass);
2275 }
2276 [] L1CTL.receive { repeat; }
2277 [] T.timeout {
2278 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2279 }
2280 }
2281}
2282
2283/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
2284testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
2285 var octetstring imm_ass := f_rnd_octstring(23);
2286 f_init();
2287 f_init_l1ctl();
2288 f_l1_tune(L1CTL);
2289
2290 /* append 3 last imsi digits so BTS can compute pagng group */
2291 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
2292
2293 timer T := 0.5;
2294 T.start;
2295 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002296 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01002297 /* TODO: verify paging group */
2298 setverdict(pass);
2299 }
2300 [] L1CTL.receive { repeat; }
2301 [] T.timeout {
2302 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2303 }
2304 }
2305}
2306
2307/* Send RACH from Um side, expect it to show up on PCU socket */
2308testcase TC_pcu_rach_content() runs on test_CT {
2309 f_init();
2310 f_init_l1ctl();
2311 f_l1_tune(L1CTL);
2312
2313 var GsmFrameNumber fn_last := 0;
2314 for (var integer i := 0; i < 1000; i := i+1) {
2315 var OCT1 ra := f_rnd_ra_ps();
2316 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
2317 if (fn == fn_last) {
2318 setverdict(fail, "Two RACH in same FN?!?");
2319 self.stop;
2320 }
2321 fn_last := fn;
2322
2323 timer T := 2.0;
2324 T.start;
2325 alt {
2326 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
2327 T.stop;
2328 }
2329 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
2330 setverdict(fail, "Unexpected RACH IND");
2331 self.stop;
2332 }
2333 [] PCU.receive { repeat; }
2334 [] T.timeout {
2335 setverdict(fail, "Timeout waiting for RACH IND");
2336 self.stop;
2337 }
2338 }
2339 }
2340 setverdict(pass);
2341}
2342
2343private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
2344 var integer strlen := lengthof(str);
2345 for (var integer i := 0; i < len-strlen; i := i+1) {
2346 str := str & pad;
2347 }
2348 return str;
2349}
2350
2351/* Send PAGING via RSL, expect it to shw up on PCU socket */
2352testcase TC_pcu_paging_from_rsl() runs on test_CT {
2353 f_init();
2354
2355 for (var integer i := 0; i < 100; i := i+1) {
2356 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2357 timer T := 3.0;
2358 if (i < 50) {
2359 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2360 } else {
2361 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
2362 }
2363 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2364 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2365 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
2366
2367 /* Send RSL PAGING COMMAND */
2368 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
2369 T.start;
2370 alt {
2371 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
2372 }
2373 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
2374 setverdict(fail, "Unexpected PAGING REQ");
2375 self.stop;
2376 }
2377 [] PCU.receive { repeat; }
2378 [] T.timeout {
2379 setverdict(fail, "Timeout waiting for PAGING REQ");
2380 self.stop;
2381 }
2382 }
2383 }
2384 setverdict(pass);
2385}
2386
2387
Harald Welte68e495b2018-02-25 00:05:57 +01002388/* TODO Areas:
2389
2390* channel activation
2391** with BS_Power / MS_Power, bypassing power control loop
2392** on primary vs. secondary TRX
2393** with encryption from initial activation on
2394** with timing advance from initial activation on
2395* mode modify
2396** encryption
2397** multirate
2398* check DEACTIVATE SACCH
2399* encryption command / intricate logic about tx-only/tx+rx/...
2400** unsupported algorithm
2401* handover detection
2402* MS Power Control
2403* BS Power Control
2404* Physical Context
2405* SACCH info modify
Harald Welte68e495b2018-02-25 00:05:57 +01002406* CCCH Load Indication for PCH and RACH
2407* Delete Indication on AGCH overflow
2408* SMS Broadcast Req / Cmd / CBCH LOad Ind
2409* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01002410* error handling
2411* discriminator error
2412** type error
2413** sequence error
2414** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01002415* PCU interface
2416** TIME_IND from BTS->PCU
2417** DATA_IND from BTS->PCU
2418** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01002419
2420*/
Harald Welte70767382018-02-21 12:16:40 +01002421
2422control {
2423 execute( TC_chan_act_stress() );
2424 execute( TC_chan_act_react() );
2425 execute( TC_chan_deact_not_active() );
2426 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01002427 execute( TC_deact_sacch() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01002428 execute( TC_rach_content() );
2429 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01002430 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01002431 execute( TC_meas_res_sign_tchf() );
2432 execute( TC_meas_res_sign_tchh() );
2433 execute( TC_meas_res_sign_sdcch4() );
2434 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01002435 execute( TC_meas_res_sign_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01002436 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01002437 execute( TC_paging_imsi_80percent() );
2438 execute( TC_paging_tmsi_80percent() );
2439 execute( TC_paging_imsi_200percent() );
2440 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01002441 execute( TC_rsl_protocol_error() );
2442 execute( TC_rsl_mand_ie_error() );
2443 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01002444 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01002445 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01002446 execute( TC_si_sched_2bis() );
2447 execute( TC_si_sched_2ter() );
2448 execute( TC_si_sched_2ter_2bis() );
2449 execute( TC_si_sched_2quater() );
2450 execute( TC_si_sched_13() );
2451 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01002452 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01002453 execute( TC_ipa_crcx_twice_not_active() );
2454 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01002455 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01002456 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01002457
2458 execute( TC_pcu_act_req() );
2459 execute( TC_pcu_act_req_wrong_ts() );
2460 execute( TC_pcu_act_req_wrong_bts() );
2461 execute( TC_pcu_act_req_wrong_trx() );
2462 execute( TC_pcu_deact_req() );
2463 execute( TC_pcu_deact_req_wrong_ts() );
2464 execute( TC_pcu_ver_si13() );
2465 execute( TC_pcu_data_req_wrong_bts() );
2466 execute( TC_pcu_data_req_wrong_trx() );
2467 execute( TC_pcu_data_req_wrong_ts() );
2468 execute( TC_pcu_data_req_ts_inactive() );
2469 execute( TC_pcu_data_req_pdtch() );
2470 execute( TC_pcu_data_req_ptcch() );
2471 execute( TC_pcu_data_req_agch() );
2472 execute( TC_pcu_data_req_imm_ass_pch() );
2473 execute( TC_pcu_rach_content() );
2474 execute( TC_pcu_paging_from_rsl() );
Harald Welte70767382018-02-21 12:16:40 +01002475}
2476
2477
2478}