blob: 49e5fa1444c1a2723385d2dc96c675029e1650c5 [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;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020014import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010015
16import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010017import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010018import from IPA_Emulation all;
19import from RSL_Emulation all;
20
21import from IPL4asp_Types all;
22import from TRXC_Types all;
23import from TRXC_CodecPort all;
24import from TRXC_CodecPort_CtrlFunct all;
25
Harald Welte883340c2018-02-28 18:59:29 +010026import from PCUIF_Types all;
27import from PCUIF_CodecPort all;
28
Harald Welte7484fc42018-02-24 14:09:45 +010029import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010030import from MobileL3_RRM_Types all;
31import from MobileL3_Types all;
32import from L3_Templates all;
Harald Welte7484fc42018-02-24 14:09:45 +010033
Harald Welte8da48242018-02-27 20:41:32 +010034import from Osmocom_VTY_Functions all;
35import from TELNETasp_PortType all;
36
Harald Welte70767382018-02-21 12:16:40 +010037/* The tests assume a BTS with the following timeslot configuration:
38 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020039 * TS1 : TCH/F
40 * TS2 : TCH/F
41 * TS3 : TCH/F_PDCH (IPA Style)
42 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010043 * TS5 : TCH/H
44 * TS6 : SDCCH/8
45 * TS7 : PDCH
46 */
47
48modulepar {
49 charstring mp_rsl_ip := "127.0.0.2";
50 integer mp_rsl_port := 3003;
51 integer mp_trx0_arfcn := 871;
Harald Weltea4d8f352018-03-01 15:47:20 +010052 charstring mp_bb_trxc_ip := "127.0.0.1";
Harald Welteef3e1c92018-02-28 23:40:14 +010053 integer mp_bb_trxc_port := 6701;
Harald Welte883340c2018-02-28 18:59:29 +010054 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Harald Welted5684392018-03-10 18:22:04 +010055 integer mp_tolerance_rxqual := 1;
56 integer mp_tolerance_rxlev := 3;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020057 charstring mp_ctrl_ip := "127.0.0.1";
58 integer mp_ctrl_port := 4238;
Harald Welte70767382018-02-21 12:16:40 +010059}
60
Harald Welte629cc6b2018-03-11 17:19:05 +010061type record of RslChannelNr ChannelNrs;
62
Harald Welte70767382018-02-21 12:16:40 +010063type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +010064 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +010065 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +010066 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +010067 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +010068 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +010069 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +010070
71 /* L1CTL port (for classic tests) */
72 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +010073
Harald Welte54a2a2d2018-02-26 09:14:05 +010074 /* TRXC port (for classic tests) */
75 port TRXC_CODEC_PT BB_TRXC;
76 var integer g_bb_trxc_conn_id;
77
Harald Welte8da48242018-02-27 20:41:32 +010078 port TELNETasp_PT BTSVTY;
79
Harald Welte883340c2018-02-28 18:59:29 +010080 /* PCU Interface of BTS */
81 port PCUIF_CODEC_PT PCU;
82 var integer g_pcu_conn_id;
83 /* Last PCU INFO IND we received */
84 var PCUIF_Message g_pcu_last_info;
85
Harald Welte48494ca2018-02-25 16:59:50 +010086 /* SI configuration */
87 var SystemInformationConfig si_cfg := {
88 bcch_extended := false,
89 si1_present := false,
90 si2bis_present := false,
91 si2ter_present := false,
92 si2quater_present := false,
93 si7_present := false,
94 si8_present := false,
95 si9_present := false,
96 si13_present := false,
97 si13alt_present := false,
98 si15_present := false,
99 si16_present := false,
100 si17_present := false,
101 si2n_present := false,
102 si21_present := false,
103 si22_present := false
104 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100105
106 /* all logical channels available on the BTS */
107 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100108 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100109}
110
111/* an individual call / channel */
112type component ConnHdlr extends RSL_DchanHdlr {
113 port L1CTL_PT L1CTL;
114
115 port TRXC_CODEC_PT BB_TRXC;
116 var integer g_bb_trxc_conn_id;
117
118 timer g_Tguard;
119 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
120
121 var ConnHdlrPars g_pars;
122 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100123 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200124
125 /* PCU Interface of BTS */
126 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100127}
128
129function f_init_rsl(charstring id) runs on test_CT {
130 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
131 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
132
133 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
134 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
135 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
136
137 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
138 vc_RSL.start(RSL_Emulation.main(false));
139}
140
141type record ConnHdlrPars {
142 RslChannelNr chan_nr,
143 RSL_IE_ChannelMode chan_mode,
144 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100145 ConnL1Pars l1_pars,
146 TestSpecUnion spec optional
147}
148
149/* Test-specific parameters */
150type union TestSpecUnion {
151 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100152}
153
Harald Welte82ccef72018-02-25 16:17:33 +0100154template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100155 max_retrans := RACH_MAX_RETRANS_7,
156 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100157 cell_barr_access := false,
158 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100159 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100160};
161
Harald Weltef10153f2018-02-25 16:34:05 +0100162template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100163 cell_resel_hyst_2dB := 2,
164 ms_txpwr_max_cch := 7,
Harald Weltef10153f2018-02-25 16:34:05 +0100165 acs := '0'B,
166 neci := true,
167 rxlev_access_min := 0
168}
169
170template (value) LocationAreaIdentification ts_LAI_default := {
171 mcc_mnc := '262F42'H,
172 lac := 42
173}
174
Harald Welte7484fc42018-02-24 14:09:45 +0100175/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100176template (value) SystemInformation ts_SI3_default := {
177 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100178 payload := {
179 si3 := {
180 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100181 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100182 ctrl_chan_desc := {
183 msc_r99 := true,
184 att := true,
185 bs_ag_blks_res := 1,
186 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100187 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100188 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
189 spare := '00'B,
190 bs_pa_mfrms := 0, /* 2 multiframes */
191 t3212 := 1 /* 6 minutes */
192 },
Harald Welte82ccef72018-02-25 16:17:33 +0100193 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100194 dn_ind := false,
195 pwrc := false,
196 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100197 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100198 },
Harald Weltef10153f2018-02-25 16:34:05 +0100199 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100200 rach_control := ts_RachCtrl_default,
Harald Welte3778acc2018-03-09 19:32:31 +0100201 rest_octets := '2B2B2B2B'O
Harald Welte7484fc42018-02-24 14:09:45 +0100202 }
203 }
204}
Harald Welte70767382018-02-21 12:16:40 +0100205
Harald Weltef8df4cb2018-03-10 15:15:08 +0100206template (value) SystemInformation ts_SI2_default := {
207 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100208 payload := {
209 si2 := {
210 bcch_freq_list := '00000000000000000000000000000000'O,
211 ncc_permitted := '11111111'B,
212 rach_control := ts_RachCtrl_default
213 }
214 }
215}
216
Harald Weltef8df4cb2018-03-10 15:15:08 +0100217template (value) SystemInformation ts_SI4_default := {
218 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100219 payload := {
220 si4 := {
221 lai := ts_LAI_default,
222 cell_sel_par := ts_CellSelPar_default,
223 rach_control := ts_RachCtrl_default,
224 cbch_chan_desc := omit,
225 cbch_mobile_alloc := omit,
226 rest_octets := ''O
227 }
228 }
229}
230
231function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
232runs on test_CT {
233 log("Setting ", rsl_si_type, ": ", si_enc);
234 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
235}
236
237function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
238runs on test_CT {
239 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
240 log("Setting ", rsl_si_type, ": ", si_dec);
241 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
242}
243
Harald Welte8da48242018-02-27 20:41:32 +0100244private function f_init_vty(charstring id) runs on test_CT {
245 map(self:BTSVTY, system:BTSVTY);
246 f_vty_set_prompts(BTSVTY);
247 f_vty_transceive(BTSVTY, "enable");
248}
249
Harald Welte883340c2018-02-28 18:59:29 +0100250/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200251private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
252 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100253 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200254 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
255 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100256 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200257 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Harald Welted378a252018-03-13 17:02:14 +0100258 setverdict(fail, "Invalid PCU Version/BTS Number received");
259 self.stop;
Harald Welte883340c2018-02-28 18:59:29 +0100260 }
261}
262
Harald Weltef26de0b2018-04-04 20:28:05 +0200263private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
264 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100265 timer T := 2.0;
266 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100267 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200268 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100269 return;
270 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200271 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100272
273 T.start;
274 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200275 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100276 [] T.timeout {
277 setverdict(fail, "Timeout waiting for PCU INFO_IND");
278 self.stop;
279 }
280 }
281}
282
Harald Welte70767382018-02-21 12:16:40 +0100283/* global init function */
Harald Welte68e495b2018-02-25 00:05:57 +0100284function f_init(charstring id := "BTS-Test") runs on test_CT {
Harald Welte629cc6b2018-03-11 17:19:05 +0100285 g_AllChannels := {
286 /* TS 1..4: TCH/F */
287 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
288 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
289 /* TS 5: TCH/H */
290 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
291 /* TS 0: SDCCH/4 */
292 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
293 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
294 /* TS 6: SDCCH/8 */
295 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
296 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
297 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
298 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
299 };
Harald Welte0472ab42018-03-12 15:02:26 +0100300 g_AllChanTypes := {
301 /* TS 1..4: TCH/F */
302 //valueof(ts_RslChanNr_Bm(1)),
303 /* TS 5: TCH/H */
304 //valueof(ts_RslChanNr_Lm(5,1)),
305 /* TS 0: SDCCH/4 */
306 valueof(ts_RslChanNr_SDCCH4(0,2)),
307 /* TS 6: SDCCH/8 */
308 valueof(ts_RslChanNr_SDCCH8(6,4))
309 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100310
Harald Welte70767382018-02-21 12:16:40 +0100311 f_init_rsl(id);
312 RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
Harald Welte2d142592018-02-25 13:19:44 +0100313 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100314 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200315 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100316
317 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100318 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
319 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
320 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
321 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100322
Harald Weltef26de0b2018-04-04 20:28:05 +0200323 map(self:PCU, system:PCU);
324 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100325
Harald Welte84271622018-03-10 17:21:03 +0100326 if (mp_bb_trxc_port != -1) {
327 var TrxcMessage ret;
328 /* start with a default moderate timing offset equalling TA=2 */
329 f_main_trxc_connect();
330 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
331 }
Harald Welte70767382018-02-21 12:16:40 +0100332}
333
Harald Welte294b0a22018-03-10 23:26:48 +0100334function f_shutdown() runs on test_CT {
335 /* shut down all "externally interfaced" components first to avoid unclean shutdown */
336 vc_IPA.stop;
337 vc_RSL.stop;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200338 f_ipa_ctrl_stop();
Harald Welte294b0a22018-03-10 23:26:48 +0100339}
340
Harald Welte68e495b2018-02-25 00:05:57 +0100341/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
342function f_init_l1ctl() runs on test_CT {
343 map(self:L1CTL, system:L1CTL);
344 f_connect_reset(L1CTL);
345}
346
Harald Welte70767382018-02-21 12:16:40 +0100347type function void_fn(charstring id) runs on ConnHdlr;
348
349/* create a new test component */
Harald Weltef26de0b2018-04-04 20:28:05 +0200350function f_start_handler(void_fn fn, ConnHdlrPars pars, boolean pcu_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100351runs on test_CT return ConnHdlr {
352 var charstring id := testcasename();
353 var ConnHdlr vc_conn;
354
355 vc_conn := ConnHdlr.create(id);
356 /* connect to RSL Emulation main component */
357 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
358 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Harald Weltef26de0b2018-04-04 20:28:05 +0200359 if (pcu_comp) {
360 /* the ConnHdlr component wants to talk directly to the PCU, so disconnect
361 * it from the test_CT and connect it to the component. This obviously only
362 * works for one component, i.e. no concurrency */
363 unmap(self:PCU, system:PCU);
364 map(vc_conn:PCU, system:PCU);
365 }
Harald Welte70767382018-02-21 12:16:40 +0100366
367 vc_conn.start(f_handler_init(fn, id, pars));
368 return vc_conn;
369}
370
Harald Welte7484fc42018-02-24 14:09:45 +0100371template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
372 streamId := sid,
373 rsl := rsl
374}
375
376template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
377 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
378 streamId := sid,
379 rsl := rsl
380}
381
Harald Welte70767382018-02-21 12:16:40 +0100382private altstep as_Tguard() runs on ConnHdlr {
383 [] g_Tguard.timeout {
384 setverdict(fail, "Tguard timeout");
385 self.stop;
386 }
387}
388
Harald Welte68e495b2018-02-25 00:05:57 +0100389private function f_l1_tune(L1CTL_PT L1CTL) {
Harald Welte70767382018-02-21 12:16:40 +0100390 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, CCCH_MODE_COMBINED);
391}
392
393private function f_trxc_connect() runs on ConnHdlr {
394 map(self:BB_TRXC, system:BB_TRXC);
395 var Result res;
Harald Weltea4d8f352018-03-01 15:47:20 +0100396 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
397 "", -1, -1, {udp:={}}, {});
Harald Welte70767382018-02-21 12:16:40 +0100398 g_bb_trxc_conn_id := res.connId;
399}
400
401private function f_trxc_fake_rssi(uint8_t rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100402 var TrxcMessage ret;
403 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100404}
405
406private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100407 var TrxcMessage ret;
408 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100409}
410
411/* first function started in ConnHdlr component */
412private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
413runs on ConnHdlr {
414 g_pars := pars;
415 g_chan_nr := pars.chan_nr;
416
417 map(self:L1CTL, system:L1CTL);
418 f_connect_reset(L1CTL);
419
Harald Welte84271622018-03-10 17:21:03 +0100420 if (mp_bb_trxc_port != -1) {
421 f_trxc_connect();
422 }
Harald Welte70767382018-02-21 12:16:40 +0100423
424 g_Tguard.start(pars.t_guard);
425 activate(as_Tguard());
426
427 f_rslem_register(0, pars.chan_nr);
428
429 /* call the user-supplied test case function */
430 fn.apply(id);
431}
432
Harald Welteb1726c92018-03-30 11:56:38 +0200433function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
434 boolean ignore_other := false)
435runs on ConnHdlr return RSL_Message {
436 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100437 timer T := 3.0;
438 RSL.send(tx);
439 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100440 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200441 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100442 T.stop;
443 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100444 }
Harald Welte1eba3742018-02-25 12:48:14 +0100445 [] T.timeout {
446 setverdict(fail, "Timeout expecting " & id);
447 self.stop;
448 }
Harald Welte21240e62018-03-11 21:43:35 +0100449 [not ignore_other] as_l1_sacch();
450 [not ignore_other] as_meas_res();
451 [not ignore_other] as_l1_dcch();
452 [not ignore_other] RSL.receive {
Harald Welte1eba3742018-02-25 12:48:14 +0100453 setverdict(fail, "Unexpected RSL message received");
Harald Welteb1726c92018-03-30 11:56:38 +0200454 self.stop;
Harald Welte70767382018-02-21 12:16:40 +0100455 }
Harald Welte21240e62018-03-11 21:43:35 +0100456 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100457 }
Harald Welteb1726c92018-03-30 11:56:38 +0200458 return rx;
459}
460
461function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
462 boolean ignore_other := false)
463runs on ConnHdlr {
464 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100465}
466
Harald Welte1eba3742018-02-25 12:48:14 +0100467function f_rsl_chan_act(RSL_IE_ChannelMode mode) runs on ConnHdlr {
468 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
469 "RSL CHAN ACT");
470}
471
Harald Welte70767382018-02-21 12:16:40 +0100472function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100473 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100474 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100475}
476
Harald Welte70767382018-02-21 12:16:40 +0100477private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
478 template RSL_IE_ChannelMode chan_mode,
479 float t_guard := 20.0) := {
480 chan_nr := valueof(chan_nr),
481 chan_mode := valueof(chan_mode),
482 t_guard := t_guard,
483 l1_pars := {
484 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100485 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100486 meas_ul := {
487 full := {
488 rxlev := dbm2rxlev(-53),
489 rxqual := 0
490 },
491 sub := {
492 rxlev := dbm2rxlev(-53),
493 rxqual := 0
494 }
495 },
496 timing_offset_256syms := 0,
497 bs_power_level := 0,
498 ms_power_level := 0,
499 ms_actual_ta := 0
Harald Welte0472ab42018-03-12 15:02:26 +0100500 },
501 spec := omit
Harald Welte70767382018-02-21 12:16:40 +0100502}
503
Harald Welte93640c62018-02-25 16:59:33 +0100504/***********************************************************************
505 * Channel Activation / Deactivation
506 ***********************************************************************/
507
Harald Welte70767382018-02-21 12:16:40 +0100508/* Stress test: Do 500 channel activations/deactivations in rapid succession */
509function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
510 for (var integer i := 0; i < 500; i := i+1) {
511 f_rsl_chan_act(g_pars.chan_mode);
512 f_rsl_chan_deact();
513 }
514 setverdict(pass);
515}
516testcase TC_chan_act_stress() runs on test_CT {
517 var ConnHdlr vc_conn;
518 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
519 f_init(testcasename());
520 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
521 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100522 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100523}
524
525/* Test if re-activation of an already active channel fails as expected */
526function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
527 f_rsl_chan_act(g_pars.chan_mode);
528 /* attempt to activate the same lchan again -> expect reject */
529 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
530 alt {
531 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
532 setverdict(fail, "Unexpected CHAN ACT ACK on double activation");
533 }
534 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
535 setverdict(pass);
536 }
537 }
538 f_rsl_chan_deact();
539}
540testcase TC_chan_act_react() runs on test_CT {
541 var ConnHdlr vc_conn;
542 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100543 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100544 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
545 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100546 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100547}
548
549/* Attempt to de-activate a channel that's not active */
550function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
551 timer T := 3.0;
552 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
553 T.start;
554 alt {
555 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
556 setverdict(pass);
557 }
558 [] T.timeout {
559 setverdict(fail, "Timeout expecting RF_CHAN_REL_ACK");
560 }
561 }
562}
563testcase TC_chan_deact_not_active() runs on test_CT {
564 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100565 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100566 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
567 vc_conn.done;
Harald Welte294b0a22018-03-10 23:26:48 +0100568 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100569}
570
571/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
572function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
573 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
574 alt {
575 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
576 setverdict(fail, "Unexpected CHAN ACT ACK");
577 }
578 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
579 setverdict(pass);
580 }
581 }
582}
583private type record WrongChanNrCase {
584 RslChannelNr chan_nr,
585 charstring description
586}
587private type record of WrongChanNrCase WrongChanNrCases;
588private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
589 chan_nr := chan_nr,
590 description := desc
591}
592
593testcase TC_chan_act_wrong_nr() runs on test_CT {
594 var ConnHdlr vc_conn;
595 var ConnHdlrPars pars;
596
Harald Welte294b0a22018-03-10 23:26:48 +0100597 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100598
599 var WrongChanNrCases wrong := {
600 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
601 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
602 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
603 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
604 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
605 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
606 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
607 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
608 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
609 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
610 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
611 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
612 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
613 };
614
615 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
616 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
617 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
618 vc_conn.done;
619 }
Harald Welte294b0a22018-03-10 23:26:48 +0100620 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100621}
622
Harald Welte93640c62018-02-25 16:59:33 +0100623/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100624 * SACCH handling
625 ***********************************************************************/
626
627private function f_exp_sacch(boolean exp) runs on ConnHdlr {
628 timer T_sacch := 3.0;
629 T_sacch.start;
630 alt {
631 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
632 setverdict(fail, "Received SACCH when not expecting it");
633 }
634 [not exp] T_sacch.timeout {
635 setverdict(pass);
636 }
637 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
638 setverdict(pass);
639 }
640 [exp] T_sacch.timeout {
641 setverdict(fail, "Timeout waiting for SACCH on ", g_chan_nr);
642 }
643 [] L1CTL.receive { repeat; }
644 [] RSL.receive { repeat; }
645 }
646}
647
648/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
649private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
650 f_l1_tune(L1CTL);
651 RSL.clear;
652
653 /* activate the logical channel */
654 f_est_dchan();
655 L1CTL.clear;
656
657 /* check that SACCH actually are received as expected */
658 f_exp_sacch(true);
659
660 /* deactivate SACCH on the logical channel */
661 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
662 f_sleep(1.0);
663 L1CTL.clear;
664
665 /* check that no SACCH are received anymore */
666 f_exp_sacch(false);
667
668 /* release the channel */
669 f_rsl_chan_deact();
670 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
671}
672testcase TC_deact_sacch() runs on test_CT {
673 var ConnHdlr vc_conn;
674 var ConnHdlrPars pars;
675 f_init();
676 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
677 //for (var integer i := 0; i < 1; i := i+1) {
678 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
679 log(testcasename(), ": Starting for ", g_AllChannels[i]);
680 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
681 vc_conn.done;
682 }
683 /* TODO: do the above in parallel, rather than sequentially? */
684 f_shutdown();
685}
686
Harald Welte55700662018-03-12 13:15:43 +0100687/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100688private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
689 var L1ctlDlMessage dl;
690 /* check that the specified SI5 value is actually sent */
691 timer T_sacch := 3.0;
692 L1CTL.clear;
693 T_sacch.start;
694 alt {
695 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
696 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
697 if (match(l3, l3_exp)) {
698 setverdict(pass);
699 } else {
700 repeat;
701 }
702 }
703 [] L1CTL.receive { repeat; }
704 [] T_sacch.timeout {
705 setverdict(fail, "Timeout waiting for SACCH ", l3_exp);
706 self.stop;
707 }
708 }
709}
710
Harald Welte55700662018-03-12 13:15:43 +0100711/* verify that given SACCH payload is not present */
712private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
713 var L1ctlDlMessage dl;
714 /* check that the specified SI5 value is actually sent */
715 timer T_sacch := 3.0;
716 L1CTL.clear;
717 T_sacch.start;
718 alt {
719 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
720 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
721 if (match(l3, l3_exp)) {
722 setverdict(fail, "Received unexpected SACCH ", dl);
723 self.stop;
724 } else {
725 repeat;
726 }
727 }
728 [] L1CTL.receive { repeat; }
729 [] T_sacch.timeout {
730 setverdict(pass);
731 }
732 }
733}
734
Harald Welte629cc6b2018-03-11 17:19:05 +0100735/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100736private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
737 /* Set a known default SACCH filling for SI5 */
738 var octetstring si5 := f_rnd_octstring(19);
739 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
740
741 f_l1_tune(L1CTL);
742 RSL.clear;
743
744 /* activate the logical channel */
745 f_est_dchan();
746
747 /* check that the specified SI5 value is actually sent */
748 f_sacch_present(si5);
749
750 /* release the channel */
751 RSL.clear;
752 f_rsl_chan_deact();
753 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
754}
755testcase TC_sacch_filling() runs on test_CT {
756 var ConnHdlr vc_conn;
757 var ConnHdlrPars pars;
758 f_init();
759 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
760 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
761 log(testcasename(), ": Starting for ", g_AllChannels[i]);
762 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
763 vc_conn.done;
764 }
765 /* TODO: do the above in parallel, rather than sequentially? */
766 f_shutdown();
767}
768
Harald Welte629cc6b2018-03-11 17:19:05 +0100769/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100770private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
771 /* Set a known default SACCH filling for SI5 */
772 var octetstring si5 := f_rnd_octstring(19);
773 var octetstring si5_diff := f_rnd_octstring(19);
774 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
775
776 f_l1_tune(L1CTL);
777 RSL.clear;
778
779 log("Activating channel, expecting standard SI5");
780 /* activate the logical channel */
781 f_est_dchan();
782 /* check that the specified SI5 value is actually sent */
783 f_sacch_present(si5);
784
785 /* set channel-specific different SI5 */
786 log("Setting channel specific SACCH INFO, expecting it");
787 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
788 /* check that the specified lchan-specific value is now used */
789 f_sacch_present(si5_diff);
790
791 /* deactivate the channel and re-activate it, this should result in default SI5 */
792 log("De-activating and re-activating channel, expecting standard SI5");
793 f_rsl_chan_deact();
794 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
795 /* Verify that the TRX-wide default SACCH filling is present again */
796 f_sacch_present(si5);
797
798 /* release the channel */
799 RSL.clear;
800 f_rsl_chan_deact();
801 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
802}
803testcase TC_sacch_info_mod() runs on test_CT {
804 var ConnHdlr vc_conn;
805 var ConnHdlrPars pars;
806 f_init();
807 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
808 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
809 log(testcasename(), ": Starting for ", g_AllChannels[i]);
810 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
811 vc_conn.done;
812 }
813 /* TODO: do the above in parallel, rather than sequentially? */
814 f_shutdown();
815}
816
Harald Welte075d84c2018-03-12 13:07:24 +0100817/* Test SACCH scheduling of multiple different SI message types */
818private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
819 var octetstring si5 := f_rnd_octstring(19);
820 var octetstring si5bis := f_rnd_octstring(19);
821 var octetstring si5ter := f_rnd_octstring(19);
822 var octetstring si6 := f_rnd_octstring(19);
823
824 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
825 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
826 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
827 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
828
829 f_l1_tune(L1CTL);
830 RSL.clear;
831
832 /* activate the logical channel */
833 f_est_dchan();
834 L1CTL.clear;
835
836 /* check that SACCH actually are received as expected */
837 f_sacch_present(si5);
838 f_sacch_present(si5bis);
839 f_sacch_present(si5ter);
840 f_sacch_present(si6);
841
842 /* release the channel */
843 f_rsl_chan_deact();
844 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
845}
846testcase TC_sacch_multi() runs on test_CT {
847 var ConnHdlr vc_conn;
848 var ConnHdlrPars pars;
849 f_init();
850 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
851 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
852 log(testcasename(), ": Starting for ", g_AllChannels[i]);
853 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
854 vc_conn.done;
855 }
856 /* TODO: do the above in parallel, rather than sequentially? */
857 f_shutdown();
858}
859
Harald Welte55700662018-03-12 13:15:43 +0100860/* Test if SACH information is modified as expected */
861private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
862 var octetstring si5 := f_rnd_octstring(19);
863 var octetstring si6 := f_rnd_octstring(19);
864
865 /* First, configure both SI5 and SI6 to be transmitted */
866 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
867 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
868
869 f_l1_tune(L1CTL);
870 RSL.clear;
871
872 /* activate the logical channel */
873 f_est_dchan();
874 L1CTL.clear;
875
876 /* check that SACCH actually are received as expected */
877 f_sacch_present(si5);
878 f_sacch_present(si6);
879
880 /* disable SI6 */
881 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
882
883 /* check that SI5 is still transmitted */
884 f_sacch_present(si5);
885 /* check if SI6 is now gone */
886 f_sacch_missing(si6);
887
888 /* release the channel */
889 f_rsl_chan_deact();
890 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
891}
892testcase TC_sacch_multi_chg() runs on test_CT {
893 var ConnHdlr vc_conn;
894 var ConnHdlrPars pars;
895 f_init();
896 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
897 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
898 log(testcasename(), ": Starting for ", g_AllChannels[i]);
899 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
900 vc_conn.done;
901 }
902 /* TODO: do the above in parallel, rather than sequentially? */
903 f_shutdown();
904}
905
Harald Welte075d84c2018-03-12 13:07:24 +0100906/* TODO: Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
907/* TODO: Test for SACCH transmission rules in the context of special CHAN ACT (HO) */
Harald Welte629cc6b2018-03-11 17:19:05 +0100908
909
910/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +0100911 * RACH Handling
912 ***********************************************************************/
913
Harald Welte8c24c2b2018-02-26 08:31:31 +0100914/* like L1SAP_IS_PACKET_RACH */
915private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +0100916 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +0100917 return true;
918 }
919 return false;
920}
921
922/* generate a random RACH for circuit-switched */
923private function f_rnd_ra_cs() return OCT1 {
924 var OCT1 ra;
925 do {
926 ra := f_rnd_octstring(1);
927 } while (ra_is_ps(ra));
928 return ra;
929}
930
Harald Welte883340c2018-02-28 18:59:29 +0100931/* generate a random RACH for packet-switched */
932private function f_rnd_ra_ps() return OCT1 {
933 var OCT1 ra;
934 do {
935 ra := f_rnd_octstring(1);
936 } while (not ra_is_ps(ra));
937 return ra;
938}
939
Harald Welte8c24c2b2018-02-26 08:31:31 +0100940/* Send 1000 RACH requests and check their RA+FN on the RSL side */
941testcase TC_rach_content() runs on test_CT {
942 f_init(testcasename());
943 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +0100944 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +0100945
Harald Welte8c24c2b2018-02-26 08:31:31 +0100946 var GsmFrameNumber fn_last := 0;
947 for (var integer i := 0; i < 1000; i := i+1) {
948 var OCT1 ra := f_rnd_ra_cs();
949 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
950 if (fn == fn_last) {
951 setverdict(fail, "Two RACH in same FN?!?");
952 self.stop;
953 }
954 fn_last := fn;
955
956 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +0100957 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +0100958 alt {
959 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, ?))) {
960 T.stop;
961 }
962 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?))) {
963 setverdict(fail, "Unexpected CHAN RQD");
964 self.stop;
965 }
966 [] RSL_CCHAN.receive { repeat; }
967 [] T.timeout {
968 setverdict(fail, "Timeout waiting for CHAN RQD");
969 self.stop;
970 }
971 }
972 }
973 setverdict(pass);
Harald Welte294b0a22018-03-10 23:26:48 +0100974 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +0100975}
Harald Welte8c24c2b2018-02-26 08:31:31 +0100976
977/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
978testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +0100979 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +0100980 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +0100981 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +0100982 f_l1_tune(L1CTL);
983
984 var GsmFrameNumber fn_last := 0;
985 for (var integer i := 0; i < 1000; i := i+1) {
986 var OCT1 ra := f_rnd_ra_cs();
987 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
988 if (fn == fn_last) {
989 setverdict(fail, "Two RACH in same FN?!?");
990 self.stop;
991 }
992 fn_last := fn;
993 }
994 var integer rsl_chrqd := 0;
995 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +0100996 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +0100997 alt {
998 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
999 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001000 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001001 repeat;
1002 }
1003 [] RSL_CCHAN.receive { repeat; }
1004 [] T.timeout { }
1005 }
1006 if (rsl_chrqd == 1000) {
1007 setverdict(pass);
1008 } else {
1009 setverdict(fail, "Received only ", rsl_chrqd, " out of 1000 RACH");
1010 }
Harald Welte294b0a22018-03-10 23:26:48 +01001011 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001012}
1013
Harald Welte54a2a2d2018-02-26 09:14:05 +01001014private function f_main_trxc_connect() runs on test_CT {
1015 map(self:BB_TRXC, system:BB_TRXC);
1016 var Result res;
Harald Welted3a88a62018-03-01 16:04:52 +01001017 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(BB_TRXC, mp_bb_trxc_ip, mp_bb_trxc_port,
1018 "", -1, -1, {udp:={}}, {});
Harald Welte54a2a2d2018-02-26 09:14:05 +01001019 g_bb_trxc_conn_id := res.connId;
1020}
1021
1022private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001023 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001024 /* tell fake_trx to use a given timing offset for all bursts */
Harald Weltef8df4cb2018-03-10 15:15:08 +01001025 ret := f_TRXC_transceive(BB_TRXC, g_bb_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001026 f_sleep(0.5);
1027
1028 /* Transmit RACH request + wait for confirmation */
1029 var OCT1 ra := f_rnd_ra_cs();
1030 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1031
1032 /* Check for expected result */
1033 timer T := 1.5;
1034 T.start;
1035 alt {
1036 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1037 setverdict(pass);
1038 }
1039 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Harald Welteb3e30942018-03-02 10:33:42 +01001040 setverdict(fail, "RACH passed but was expected to be dropped: ", toffs256);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001041 }
1042 [] RSL_CCHAN.receive { repeat; }
1043 [not expect_pass] T.timeout {
1044 setverdict(pass);
1045 }
1046 [expect_pass] T.timeout {
1047 setverdict(fail, "Timeout waiting for CHAN RQD");
1048 }
1049 }
1050}
1051
1052/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1053testcase TC_rach_max_ta() runs on test_CT {
1054 f_init(testcasename());
1055 f_init_l1ctl();
1056 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001057 f_sleep(1.0);
1058
1059 /* default max-ta is 63 (full range of GSM timing advance */
1060
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001061 /* We allow early arrival up to 2 symbols */
1062 f_rach_toffs(-1*256, true);
1063 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001064 f_rach_toffs(-10*256, false);
1065
1066 /* 0 / 32 / 63 bits is legal / permitted */
1067 f_rach_toffs(0, true);
1068 f_rach_toffs(32*256, true);
1069 f_rach_toffs(63*256, true);
1070
1071 /* more than 63 bits is not legal / permitted */
1072 f_rach_toffs(64*256, false);
1073 f_rach_toffs(127*256, false);
Harald Welte294b0a22018-03-10 23:26:48 +01001074 f_shutdown();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001075}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001076
Harald Welte93640c62018-02-25 16:59:33 +01001077/***********************************************************************
1078 * Measurement Processing / Reporting
1079 ***********************************************************************/
1080
Harald Welte70767382018-02-21 12:16:40 +01001081template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1082 spare := '0'B,
1083 lpd := 0,
1084 sapi := sapi,
1085 c_r := c_r,
1086 ea := true
1087}
1088
Harald Welted879bd92018-03-12 15:01:23 +01001089template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001090 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001091 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001092 len := 0, /* overwritten */
1093 m := false,
1094 el := 1,
1095 payload := pl
1096}
1097
1098/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1099altstep as_l1_sacch() runs on ConnHdlr {
1100 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001101 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001102 log("SACCH received: ", l1_dl.payload.data_ind.payload);
1103 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, 23, 23, 0, 0, omit));
Harald Welted879bd92018-03-12 15:01:23 +01001104 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001105 log("LAPDm: ", lb);
Harald Welted879bd92018-03-12 15:01:23 +01001106 var octetstring pl := '0000'O & enc_LapdmFrameAB(lb);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001107 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_SACCH(0), pl));
Harald Welte70767382018-02-21 12:16:40 +01001108 repeat;
1109 }
1110}
1111
1112altstep as_l1_dcch() runs on ConnHdlr {
1113 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001114 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001115 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1116 var octetstring pl := '010301'O;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001117 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), pl));
Harald Welte70767382018-02-21 12:16:40 +01001118 repeat;
1119 }
1120}
1121
1122type record MeasElem {
1123 uint6_t rxlev,
1124 uint3_t rxqual
1125}
1126
1127type record MeasElemFS {
1128 MeasElem full,
1129 MeasElem sub
1130}
1131
1132type record ConnL1Pars {
1133 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001134 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001135 MeasElemFS meas_ul,
1136 int16_t timing_offset_256syms,
1137 uint5_t bs_power_level,
1138 uint5_t ms_power_level,
1139 uint8_t ms_actual_ta
1140}
1141
1142/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1143private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1144 return 63 + (toffs256s/256);
1145}
1146
Harald Welted5684392018-03-10 18:22:04 +01001147private function f_max(integer a, integer b) return integer {
1148 if (a > b) {
1149 return a;
1150 } else {
1151 return b;
1152 }
1153}
1154
1155private function f_min(integer a, integer b) return integer {
1156 if (a < b) {
1157 return a;
1158 } else {
1159 return b;
1160 }
1161}
1162
1163/* compute negative tolerance val-tolerance, ensure >= min */
1164private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1165 val := val - tolerance;
1166 return f_max(val, min);
1167}
1168
1169/* compute positive tolerance val+tolerance, ensure <= max */
1170private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1171 val := val + tolerance;
1172 return f_min(val, max);
1173}
1174
1175/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1176private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1177return template integer {
1178 var template integer ret;
1179 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1180 return ret;
1181}
1182
1183
Harald Welte70767382018-02-21 12:16:40 +01001184/* build a template for matching measurement results against */
1185private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1186 var ConnL1Pars l1p := g_pars.l1_pars;
1187 var template RSL_IE_UplinkMeas ul_meas := {
1188 len := 3,
1189 rfu := '0'B,
1190 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001191 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001192 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001193 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001194 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001195 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1196 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001197 supp_meas_info := omit
1198 };
Harald Welte685d5982018-02-27 20:42:05 +01001199 if (l1p.toa256_enabled) {
1200 ul_meas.len := 5;
1201 ul_meas.supp_meas_info := int2oct(l1p.timing_offset_256syms, 2);
1202 }
Harald Welte70767382018-02-21 12:16:40 +01001203 /* HACK HACK HACK FIXME HACK HACK HACK see https://osmocom.org/issues/2988 */
1204 ul_meas.rxlev_f_u := ?;
1205 ul_meas.rxlev_s_u := ?;
1206 ul_meas.rxq_f_u := ?;
1207 ul_meas.rxq_s_u := ?;
1208 var template RSL_IE_BS_Power bs_power := {
1209 reserved := 0,
1210 epc := false,
1211 fpc := false,
1212 power_level := l1p.bs_power_level
1213 };
1214 var template RSL_IE_L1Info l1_info := {
1215 ms_power_lvl := l1p.ms_power_level,
1216 fpc := false,
1217 reserved := 0,
1218 actual_ta := l1p.ms_actual_ta
1219 };
1220 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
1221 var template uint8_t t_toffs := (offs-1 .. offs+1); /* some tolerance */
1222 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1223 ?, t_toffs);
1224}
1225
1226/* verify we regularly receive measurement reports with incrementing numbers */
1227altstep as_meas_res() runs on ConnHdlr {
1228 var RSL_Message rsl;
1229 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1230 /* increment counter of next to-be-expected meas rep */
1231 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1232 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001233 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001234 repeat;
1235 }
1236 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001237 /* increment counter of next to-be-expected meas rep */
1238 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1239 if (g_first_meas_res) {
1240 g_first_meas_res := false;
1241 repeat;
1242 } else {
1243 setverdict(fail, "Received unspecific MEAS RES ", rsl);
1244 self.stop;
1245 }
Harald Welte70767382018-02-21 12:16:40 +01001246 }
1247 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
1248 setverdict(fail, "Received unexpected MEAS RES ", rsl);
1249 self.stop;
1250 }
1251 [] g_Tmeas_exp.timeout {
1252 setverdict(fail, "Didn't receive expected measurement result")
1253 self.stop;
1254 }
1255}
1256
1257/* Establish dedicated channel: L1CTL + RSL side */
1258private function f_est_dchan() runs on ConnHdlr {
1259 var GsmFrameNumber fn;
1260 var ImmediateAssignment imm_ass;
1261 var integer ra := 23;
1262
1263 fn := f_L1CTL_RACH(L1CTL, ra);
1264 /* This arrives on CCHAN, so we cannot test for receiving CHAN RQDhere */
1265 //RSL.receive(tr_RSL_CHAN_RQD(int2oct(23,1)));
1266
1267 /* Activate channel on BTS side */
1268 f_rsl_chan_act(g_pars.chan_mode);
1269
1270 /* Send IMM.ASS via CCHAN */
1271 var ChannelDescription ch_desc := {
1272 chan_nr := g_pars.chan_nr,
1273 tsc := 7,
1274 h := false,
1275 arfcn := mp_trx0_arfcn,
1276 maio_hsn := omit
1277 };
1278 var MobileAllocation ma := {
1279 len := 0,
1280 ma := ''B
1281 };
1282 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1283 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1284
1285 /* receive IMM.ASS on MS side */
1286 var ImmediateAssignment ia_um;
1287 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1288 /* enable dedicated mode */
1289 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltefa45e9e2018-03-10 18:59:03 +01001290
1291 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001292}
1293
1294/* establish DChan, verify existance + contents of measurement reports */
1295function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001296 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001297 RSL.clear;
1298
Harald Welte5398d5e2018-03-10 19:00:24 +01001299 if (mp_bb_trxc_port != -1) {
1300 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-100);
1301 f_trxc_fake_rssi(100);
Harald Welte70767382018-02-21 12:16:40 +01001302
Harald Welte5398d5e2018-03-10 19:00:24 +01001303 g_pars.l1_pars.timing_offset_256syms := 512; /* 2 symbols */
1304 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1305 } else {
1306 g_pars.l1_pars.timing_offset_256syms := 0; /* FIXME */
1307 g_pars.l1_pars.meas_ul.full.rxlev := dbm2rxlev(-55); /* FIXME */
1308 }
1309 g_pars.l1_pars.meas_ul.sub.rxlev := g_pars.l1_pars.meas_ul.full.rxlev;
Harald Welte70767382018-02-21 12:16:40 +01001310
1311 f_est_dchan();
1312
1313 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1314 * RSL measurement reports on Abis side */
1315 timer T := 8.0;
1316 T.start;
1317 alt {
1318 [] as_l1_sacch();
1319 [] as_meas_res();
1320 [] as_l1_dcch();
1321 [] L1CTL.receive { repeat; }
1322 [g_Tmeas_exp.running] T.timeout {
1323 /* as_meas_res() would have done setverdict(fail) / self.stop in case
1324 * of any earlier errors, so if we reach this timeout, we're good */
1325 setverdict(pass);
1326 }
1327 [] T.timeout {
1328 setverdict(fail, "No MEAS RES received at all");
1329 }
1330 }
1331 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001332 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001333}
Harald Welte0472ab42018-03-12 15:02:26 +01001334
Harald Welte70767382018-02-21 12:16:40 +01001335testcase TC_meas_res_sign_tchf() runs on test_CT {
1336 var ConnHdlr vc_conn;
1337 var ConnHdlrPars pars;
1338 f_init(testcasename());
1339 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1340 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
1341 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1342 vc_conn.done;
1343 }
Harald Welte294b0a22018-03-10 23:26:48 +01001344 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001345}
1346testcase TC_meas_res_sign_tchh() runs on test_CT {
1347 var ConnHdlr vc_conn;
1348 var ConnHdlrPars pars;
1349 f_init(testcasename());
1350 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1351 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1352 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1353 vc_conn.done;
1354 }
Harald Welte294b0a22018-03-10 23:26:48 +01001355 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001356}
1357testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1358 var ConnHdlr vc_conn;
1359 var ConnHdlrPars pars;
1360 f_init(testcasename());
1361 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1362 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1363 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1364 vc_conn.done;
1365 }
Harald Welte294b0a22018-03-10 23:26:48 +01001366 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001367}
1368testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1369 var ConnHdlr vc_conn;
1370 var ConnHdlrPars pars;
1371 f_init(testcasename());
1372 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1373 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1374 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1375 vc_conn.done;
1376 }
Harald Welte294b0a22018-03-10 23:26:48 +01001377 f_shutdown();
Harald Welte70767382018-02-21 12:16:40 +01001378}
Harald Welte685d5982018-02-27 20:42:05 +01001379testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1380 var ConnHdlr vc_conn;
1381 var ConnHdlrPars pars;
1382 f_init(testcasename());
1383 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1384 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1385 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1386 pars.l1_pars.toa256_enabled := true;
1387 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1388 vc_conn.done;
1389 }
Harald Welte294b0a22018-03-10 23:26:48 +01001390 f_shutdown();
Harald Welte685d5982018-02-27 20:42:05 +01001391}
1392
Harald Welte70767382018-02-21 12:16:40 +01001393
Harald Welte0472ab42018-03-12 15:02:26 +01001394/* Test if a channel without valid uplink bursts generates RSL CONN FAIL IND (TS 48.058 4.10) */
Harald Welte70767382018-02-21 12:16:40 +01001395private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001396 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001397 RSL.clear;
1398
1399 f_est_dchan();
1400 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01001401 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01001402
1403 timer T := 40.0;
1404 T.start;
1405 alt {
1406 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
1407 setverdict(pass)
1408 }
1409 [] RSL.receive { repeat };
1410 [] T.timeout {
1411 setverdict(fail, "No CONN FAIL IND received");
1412 }
1413 }
1414 f_rsl_chan_deact();
1415}
1416testcase TC_conn_fail_crit() runs on test_CT {
1417 var ConnHdlr vc_conn;
1418 var ConnHdlrPars pars;
1419 f_init(testcasename());
1420 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
1421 pars.t_guard := 60.0;
1422 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
1423 vc_conn.done;
1424}
1425
Harald Welte93640c62018-02-25 16:59:33 +01001426/***********************************************************************
1427 * Paging
1428 ***********************************************************************/
1429
Harald Welte68e495b2018-02-25 00:05:57 +01001430function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
1431 if (tmsi == 'FFFFFFFF'O) {
1432 return true;
1433 } else {
1434 return false;
1435 }
1436}
Harald Welte70767382018-02-21 12:16:40 +01001437
Harald Welte68e495b2018-02-25 00:05:57 +01001438altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids)
1439runs on test_CT {
1440 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001441 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01001442 repeat;
1443 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01001444 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01001445 var octetstring without_plen :=
1446 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
1447 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
1448 if (match(rr, tr_PAGING_REQ1)) {
1449 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1450 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1451 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
1452 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1453 }
1454 } else if (match(rr, tr_PAGING_REQ2)) {
1455 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1456 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
1457 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1458 }
1459 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
1460 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1461 }
1462 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
1463 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1464 }
1465 } else if (match(rr, tr_PAGING_REQ3)) {
1466 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
1467 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
1468 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1469 }
1470 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
1471 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1472 }
1473 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
1474 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1475 }
1476 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
1477 num_paging_rcv_ids := num_paging_rcv_ids + 1;
1478 }
1479 }
1480 repeat;
1481 }
1482}
1483
1484type record PagingTestCfg {
1485 boolean combined_ccch,
1486 integer bs_ag_blks_res,
1487 float load_factor,
1488 boolean exp_load_ind,
1489 boolean exp_overload,
1490 boolean use_tmsi
1491}
1492
1493type record PagingTestState {
1494 integer num_paging_sent,
1495 integer num_paging_rcv_msgs,
1496 integer num_paging_rcv_ids,
1497 integer num_overload
1498}
1499
1500/* receive + ignore RSL RF RES IND */
1501altstep as_rsl_res_ind() runs on test_CT {
1502 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
1503 repeat;
1504 }
1505}
1506
1507/* Helper function for paging related testing */
1508private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
1509 f_init(testcasename());
1510 f_init_l1ctl();
1511 f_l1_tune(L1CTL);
1512
1513 var PagingTestState st := {
1514 num_paging_sent := 0,
1515 num_paging_rcv_msgs := 0,
1516 num_paging_rcv_ids := 0,
1517 num_overload := 0
1518 };
1519
1520 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
1521 var float max_pch_imsi_per_sec;
1522 if (cfg.use_tmsi) {
1523 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
1524 } else {
1525 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
1526 }
1527 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
1528 var float interval := 1.0 / pch_blocks_per_sec;
1529 log("pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
1530
1531 for (var integer i := 0; i < float2int(20.0/interval); i := i+1) {
1532 /* build mobile Identity */
1533 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
1534 if (cfg.use_tmsi) {
1535 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
1536 } else {
1537 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
1538 }
1539 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
1540 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
1541
1542 /* Send RSL PAGING COMMAND */
1543 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
1544 st.num_paging_sent := st.num_paging_sent + 1;
1545
1546 /* Wait for interval to next PAGING COMMAND */
1547 timer T_itv := interval;
1548 T_itv.start;
1549 alt {
1550 /* check for presence of CCCH LOAD IND (paging load) */
1551 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1552 st.num_overload := st.num_overload + 1;
1553 repeat;
1554 }
1555 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
1556 setverdict(fail, "Unexpected PCH Overload");
1557 }
1558 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
1559 log("Rx LOAD_IND");
1560 /* FIXME: analyze/verify interval + contents */
1561 repeat;
1562 }
1563 /* check if paging requests arrive on Um side */
1564 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1565 [] L1CTL.receive { repeat; }
1566 [] T_itv.timeout { }
1567 [] as_rsl_res_ind();
1568 }
1569 }
1570
1571 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
1572 timer T_wait := 18.0;
1573 T_wait.start;
1574 alt {
1575 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids);
1576 [] L1CTL.receive { repeat; }
1577 /* 65535 == empty paging queue, we can terminate*/
1578 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
1579 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
1580 [] T_wait.timeout {
1581 setverdict(fail, "Waiting for empty paging queue");
1582 }
1583 [] as_rsl_res_ind();
1584 }
1585
Harald Welte294b0a22018-03-10 23:26:48 +01001586 f_shutdown();
1587
Harald Welte68e495b2018-02-25 00:05:57 +01001588 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
1589 " rcvd_ids=", st.num_paging_rcv_ids);
1590 return st;
1591}
1592
1593/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
1594 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1595 * - that CCCH LOAD IND (PCH) are being generated
1596 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1597testcase TC_paging_imsi_80percent() runs on test_CT {
1598 var PagingTestCfg cfg := {
1599 combined_ccch := true,
1600 bs_ag_blks_res := 1,
1601 load_factor := 0.8,
1602 exp_load_ind := true,
1603 exp_overload := false,
1604 use_tmsi := false
1605 };
1606 var PagingTestState st := f_TC_paging(cfg);
1607 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1608 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1609 st.num_paging_rcv_ids);
1610 } else {
1611 setverdict(pass);
1612 }
1613}
1614
1615/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
1616 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
1617 * - that CCCH LOAD IND (PCH) are being generated
1618 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1619testcase TC_paging_tmsi_80percent() runs on test_CT {
1620 var PagingTestCfg cfg := {
1621 combined_ccch := true,
1622 bs_ag_blks_res := 1,
1623 load_factor := 0.8,
1624 exp_load_ind := true,
1625 exp_overload := false,
1626 use_tmsi := true
1627 };
1628 var PagingTestState st := f_TC_paging(cfg);
1629 if (st.num_paging_sent != st.num_paging_rcv_ids) {
1630 setverdict(fail, "Expected ", st.num_paging_sent, " pagings but have ",
1631 st.num_paging_rcv_ids);
1632 } else {
1633 setverdict(pass);
1634 }
1635}
1636
1637/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
1638 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1639 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1640 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1641testcase TC_paging_imsi_200percent() runs on test_CT {
1642 var PagingTestCfg cfg := {
1643 combined_ccch := true,
1644 bs_ag_blks_res := 1,
1645 load_factor := 2.0,
1646 exp_load_ind := true,
1647 exp_overload := true,
1648 use_tmsi := false
1649 };
1650 var PagingTestState st := f_TC_paging(cfg);
1651 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
1652 * slots and will fully drain that buffer before returning */
1653 var template integer tpl := (st.num_paging_sent*80/100 .. st.num_paging_sent *85/100);
1654 if (not match(st.num_paging_rcv_ids, tpl)) {
1655 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1656 } else {
1657 setverdict(pass);
1658 }
1659}
1660
1661/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
1662 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
1663 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
1664 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
1665testcase TC_paging_tmsi_200percent() runs on test_CT {
1666 var PagingTestCfg cfg := {
1667 combined_ccch := true,
1668 bs_ag_blks_res := 1,
1669 load_factor := 2.0,
1670 exp_load_ind := true,
1671 exp_overload := true,
1672 use_tmsi := true
1673 };
1674 var PagingTestState st := f_TC_paging(cfg);
1675 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
1676 * slots and will fully drain that buffer before returning */
Harald Welte0803cde2018-04-15 21:36:54 +02001677 var template integer tpl := (st.num_paging_sent*66/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01001678 if (not match(st.num_paging_rcv_ids, tpl)) {
1679 setverdict(fail, "Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids);
1680 } else {
1681 setverdict(pass);
1682 }
1683}
1684
1685
Harald Welte93640c62018-02-25 16:59:33 +01001686/***********************************************************************
1687 * Immediate Assignment / AGCH
1688 ***********************************************************************/
1689
Harald Welte68e495b2018-02-25 00:05:57 +01001690testcase TC_imm_ass() runs on test_CT {
1691 f_init(testcasename());
1692 for (var integer i := 0; i < 1000; i := i+1) {
1693 var octetstring ia_enc := f_rnd_octstring(8);
1694 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
1695 f_sleep(0.02);
1696 }
1697 /* FIXME: check if imm.ass arrive on Um side */
1698 /* FIXME: check for DELETE INDICATION */
1699 f_sleep(100.0);
Harald Welte294b0a22018-03-10 23:26:48 +01001700 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01001701}
1702
Harald Welte48494ca2018-02-25 16:59:50 +01001703/***********************************************************************
1704 * BCCH
1705 ***********************************************************************/
1706
1707/* tuple of Frame Number + decoded SI */
1708type record SystemInformationFn {
1709 GsmFrameNumber frame_number,
1710 SystemInformation si
1711}
1712
1713/* an arbitrary-length vector of decoded SI + gsmtap header */
1714type record of SystemInformationFn SystemInformationVector;
1715
1716/* an array of SI-vectors indexed by TC value */
1717type SystemInformationVector SystemInformationVectorPerTc[8];
1718
1719/* determine if a given SI vector contains given SI type at least once */
1720function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1721 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1722 var integer fn_mod51 := arr[i].frame_number mod 51;
1723 if (not bcch_ext and fn_mod51 == 2 or
1724 bcch_ext and fn_mod51 == 6) {
1725 if (arr[i].si.header.message_type == key) {
1726 return true;
1727 }
1728 }
1729 }
1730 return false;
1731}
1732
1733/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
1734function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1735 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
1736 setverdict(fail, "No ", key, " in TC=", tc, "!");
1737 }
1738}
1739
1740/* check if a given SI vector contains given SI type at least once on any TC */
1741function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
1742 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
1743 if (f_si_vecslot_contains(arr[tc], key) or
1744 f_si_vecslot_contains(arr[tc], key, true)) {
1745 return true;
1746 }
1747 }
1748 return false;
1749}
1750
1751/* determine if a given SI vector contains given SI type at least N of M times */
1752function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
1753 var integer count := 0;
1754 if (sizeof(arr) < m) {
1755 setverdict(fail, "Error: Insufficient SI in array");
1756 self.stop;
1757 }
1758 for (var integer i:= 0; i < m; i := i + 1) {
1759 var integer fn_mod51 := arr[i].frame_number mod 51;
1760 if (not bcch_ext and fn_mod51 == 2 or
1761 bcch_ext and fn_mod51 == 6) {
1762 if (arr[i].si.header.message_type == key) {
1763 count := count + 1;
1764 }
1765 }
1766 }
1767 if (count >= n) {
1768 return true;
1769 } else {
1770 return false;
1771 }
1772}
1773
1774/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
1775function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
1776 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
1777 setverdict(fail, "Not ", n, "/", m, " of ", key, " in TC=", tc, "!");
1778 }
1779}
1780
1781/* determine if a given SI vector contains given SI type at least once */
1782function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
1783 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
1784 var integer fn_mod51 := arr[i].frame_number mod 51;
1785 if (not bcch_ext and fn_mod51 == 2 or
1786 bcch_ext and fn_mod51 == 6) {
1787 if (arr[i].si.header.message_type != key) {
1788 return false;
1789 }
1790 }
1791 }
1792 return true;
1793}
1794
1795/* ensure a given TC slot of the SI vector contains only given SI type */
1796function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
1797 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
1798 setverdict(fail, "Not all ", key, " in TC=", tc, "!");
1799 }
1800}
1801
1802/* SI configuration of cell, against which we validate actual SI messages */
1803type set SystemInformationConfig {
1804 boolean bcch_extended,
1805 boolean si1_present,
1806 boolean si2bis_present,
1807 boolean si2ter_present,
1808 boolean si2quater_present,
1809 boolean si7_present,
1810 boolean si8_present,
1811 boolean si9_present,
1812 boolean si13_present,
1813 boolean si13alt_present,
1814 boolean si15_present,
1815 boolean si16_present,
1816 boolean si17_present,
1817 boolean si2n_present,
1818 boolean si21_present,
1819 boolean si22_present
1820}
1821
1822/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
1823function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
1824 var integer i;
1825 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
1826 if (sizeof(si_per_tc[i]) == 0) {
Harald Welte544565a2018-03-02 10:34:08 +01001827 setverdict(fail, "No SI messages for TC=", i);
Harald Welte48494ca2018-02-25 16:59:50 +01001828 }
1829 }
1830 if (cfg.si1_present) {
1831 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
1832 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
1833 * when TC = 0, it can assume that System Information Type 1 is not in use. */
1834 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
1835 /* make sure *ALL* contain SI1 */
1836 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
1837 }
1838 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
1839 /* iii) A SI 2 message will be sent at least every time TC = 1 */
1840 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
1841 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
1842 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
1843 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
1844
1845 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
1846 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
1847 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
1848 * consecutive occurrences of TC = 4. */
1849 if (cfg.si2bis_present and not cfg.si2ter_present) {
1850 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
1851 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
1852 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
1853 } else if (cfg.si2ter_present and cfg.si2bis_present) {
1854 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
1855 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
1856 }
1857
1858 if (cfg.si7_present or cfg.si8_present) {
1859 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
1860 * if System Information type 4 does not contain all information needed for cell
1861 * selection and reselection. */
1862 if (not cfg.bcch_extended) {
1863 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
1864 }
1865 if (cfg.si7_present) {
1866 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
1867 }
1868 if (cfg.si8_present) {
1869 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
1870 }
1871 }
1872
1873 if (cfg.si2quater_present) {
1874 /* iii) System information type 2 quater is sent if needed, as determined by the system
1875 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
1876 * and 2ter are used, otherwise it shall be sent at least once within any of 4
1877 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
1878 * within any of 4 consecutive occurrences of TC = 5. */
1879 if (not (cfg.bcch_extended)) {
1880 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
1881 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
1882 } else {
1883 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
1884 }
1885 } else {
1886 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
1887 }
1888 }
1889 if (cfg.si9_present) {
1890 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
1891 * in system information type 3 as defined in 3GPP TS 44.018. */
1892 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
1893 }
1894 if (cfg.si13_present) {
1895 /* vii) System Information type 13 is only related to the GPRS service. System Information
1896 * Type 13 need only be sent if GPRS support is indicated in one or more of System
1897 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
1898 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
1899 * In the case that the message is sent on the BCCH Norm, it is sent at least once
1900 * within any of 4 consecutive occurrences of TC=4. */
1901 if (not cfg.bcch_extended) {
1902 log("not-bccch-extended");
1903 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
1904 } else {
1905 log("bccch-extended");
1906 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
1907 }
1908 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
1909 setverdict(fail, "Cannot have SI13alt and SI13");
1910 }
1911 }
1912 if (cfg.si16_present or cfg.si17_present) {
1913 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
1914 * should not be sent in a cell where network sharing is used (see rule xv). */
1915 if (cfg.si22_present) {
1916 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
1917 }
1918 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
1919 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
1920 }
1921 if (not cfg.bcch_extended) {
1922 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
1923 }
1924 if (cfg.si16_present) {
1925 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
1926 }
1927 if (cfg.si17_present) {
1928 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
1929 }
1930 }
1931
1932 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
1933 * broadcast information. The frequency with which they are sent is determined by the
1934 * system operator. System Information type 9 identifies the scheduling of System
1935 * Information type 18 and 20 messages. */
1936
1937 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
1938 * Information Type 19 is present, then its scheduling shall be indicated in System
1939 * Information Type 9. */
1940
1941 if (cfg.si15_present) {
1942 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
1943 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
1944 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
1945 * 4 consecutive occurrences of TC = 1. */
1946 if (not cfg.bcch_extended) {
1947 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
1948 } else {
1949 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
1950 }
1951 }
1952 if (cfg.si13alt_present) {
1953 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
1954 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
1955 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
1956 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
1957 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
1958 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
1959 * of TC = 4. */
1960 if (cfg.si13_present) {
1961 testcase.stop("Error: Cannot have SI13alt and SI13");
1962 }
1963 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
1964 setverdict(fail, "Cannot have SI13alt and SI13");
1965 }
1966 if (not cfg.bcch_extended) {
1967 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
1968 } else {
1969 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
1970 }
1971 }
1972 if (cfg.si2n_present) {
1973 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
1974 * as determined by the system operator. In the case that the message is sent on the
1975 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
1976 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
1977 * consecutive occurrences of TC = 4. */
1978 if (not cfg.bcch_extended) {
1979 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
1980 } else {
1981 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
1982 }
1983 }
1984 if (cfg.si21_present) {
1985 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
1986 * determined by the system operator. If Extended Access Barring is in use in the cell
1987 * then this message is sent at least once within any of 4 consecutive occurrences of
1988 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
1989 * cell then this message shall only be sent on BCCH Ext. */
1990 if (not cfg.bcch_extended) {
1991 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
1992 } else {
1993 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
1994 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
1995 setverdict(fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
1996 }
1997 }
1998 }
1999 if (cfg.si22_present) {
2000 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2001 * should not be sent in a cell where SoLSA is used (see rule viii). System
2002 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2003 * =2 and TC=6. */
2004 if (cfg.si16_present or cfg.si17_present) {
2005 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2006 }
2007 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2008 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
2009 setverdict(fail, "Cannot have SI16/SI17 and SI22!");
2010 }
2011 if (not cfg.bcch_extended) {
2012 testcase.stop("Error: SI22 requires BCCH Extd!");
2013 } else {
2014 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2015 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2016 }
2017 }
2018}
2019
2020/* sample Systme Information for specified duration via L1CTL */
2021function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2022 timer T := duration;
2023 var SystemInformationVectorPerTc si_per_tc;
2024 var L1ctlDlMessage l1_dl;
2025
2026 /* initialize all per-TC vectors empty */
2027 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2028 si_per_tc[i] := {};
2029 }
2030
2031 /* flush all previous L1 queued msgs */
2032 pt.clear;
2033
2034 T.start;
2035 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002036 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002037 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2038 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2039 log("Ignoring non-RR SI ", l1_dl);
2040 repeat;
2041 }
2042 var SystemInformationFn sig := {
2043 frame_number := l1_dl.dl_info.frame_nr,
2044 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2045 }
2046 var integer tc := f_gsm_compute_tc(sig.frame_number);
2047 log("SI received at TC=", tc, ": ", sig.si);
2048 /* append to the per-TC bucket */
2049 si_per_tc[tc] := si_per_tc[tc] & { sig };
2050 repeat;
2051 }
2052 [] pt.receive { repeat; }
2053 [] T.timeout { }
2054 }
2055
2056 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2057 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2058 }
2059 log("si_per_tc=", si_per_tc);
2060 return si_per_tc;
2061}
2062
2063/* helper function: Set given SI via RSL + validate scheduling.
2064 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2065function f_TC_si_sched() runs on test_CT {
2066 var SystemInformationVectorPerTc si_per_tc;
2067 f_init_l1ctl();
2068 f_l1_tune(L1CTL);
2069
2070 /* Sample + Validate Scheduling */
2071 si_per_tc := f_l1_sample_si(L1CTL);
2072 f_validate_si_scheduling(si_cfg, si_per_tc);
2073
2074 setverdict(pass);
2075}
2076
2077testcase TC_si_sched_default() runs on test_CT {
2078 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002079 /* 2+3+4 are mandatory and set in f_init() */
2080 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002081 f_shutdown();
Harald Welte0cae4552018-03-09 22:20:26 +01002082}
2083
2084testcase TC_si_sched_1() runs on test_CT {
2085 f_init();
2086 si_cfg.si1_present := true;
2087 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002088 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002089 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002090}
2091
2092testcase TC_si_sched_2bis() runs on test_CT {
2093 f_init();
2094 si_cfg.si2bis_present := true;
2095 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2096 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002097 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002098}
2099
2100testcase TC_si_sched_2ter() runs on test_CT {
2101 f_init();
2102 si_cfg.si2ter_present := true;
2103 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2104 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002105 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002106}
2107
2108testcase TC_si_sched_2ter_2bis() runs on test_CT {
2109 f_init();
2110 si_cfg.si2bis_present := true;
2111 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2112 si_cfg.si2ter_present := true;
2113 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2114 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002115 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002116}
2117
2118testcase TC_si_sched_2quater() runs on test_CT {
2119 f_init();
2120 si_cfg.si2quater_present := true;
2121 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2122 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002123 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002124}
2125
2126testcase TC_si_sched_13() runs on test_CT {
2127 f_init();
2128 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002129 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002130 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002131 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002132}
2133
2134testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
2135 f_init();
2136 si_cfg.si2bis_present := true;
2137 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2138 si_cfg.si2ter_present := true;
2139 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2140 si_cfg.si2quater_present := true;
2141 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
2142 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02002143 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002144 f_TC_si_sched();
Harald Welte294b0a22018-03-10 23:26:48 +01002145 f_shutdown();
Harald Welte48494ca2018-02-25 16:59:50 +01002146}
2147
2148
Harald Welte68e495b2018-02-25 00:05:57 +01002149testcase TC_bcch_info() runs on test_CT {
2150 f_init(testcasename());
2151 /* FIXME: enable / disable individual BCCH info */
2152 //ts_RSL_BCCH_INFO(si_type, info);
2153 /* expect no ERROR REPORT after either of them *
2154 /* negative test: ensure ERROR REPORT on unsupported types */
Harald Welte294b0a22018-03-10 23:26:48 +01002155 f_shutdown();
Harald Welte68e495b2018-02-25 00:05:57 +01002156}
2157
Harald Welte93640c62018-02-25 16:59:33 +01002158/***********************************************************************
2159 * Low-Level Protocol Errors / ERROR REPORT
2160 ***********************************************************************/
2161
Harald Welte01d982c2018-02-25 01:31:40 +01002162private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
2163 timer T := 5.0;
2164 T.start;
2165 alt {
2166 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
2167 setverdict(pass);
2168 }
2169 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
2170 setverdict(fail, "Wrong cause in RSL ERR REP");
2171 }
2172 [] RSL_CCHAN.receive {
2173 repeat;
2174 }
2175 [] T.timeout {
2176 setverdict(fail, "Timeout waiting for RSL ERR REP");
2177 }
2178 }
2179}
2180
2181/* Provoke a protocol error (message too short) and match on ERROR REPORT */
2182testcase TC_rsl_protocol_error() runs on test_CT {
2183 f_init(testcasename());
2184 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2185 rsl.ies := omit;
2186 RSL_CCHAN.send(ts_RSL_UD(rsl));
2187
2188 f_exp_err_rep(RSL_ERR_PROTO);
2189}
2190
2191/* Provoke a mandatory IE error and match on ERROR REPORT */
2192testcase TC_rsl_mand_ie_error() runs on test_CT {
2193 f_init(testcasename());
2194
2195 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2196 rsl.ies := { rsl.ies[0] };
2197 RSL_CCHAN.send(ts_RSL_UD(rsl));
2198
2199 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
2200}
2201
2202/* Provoke an IE content error and match on ERROR REPORT */
2203testcase TC_rsl_ie_content_error() runs on test_CT {
2204 f_init(testcasename());
2205 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
2206 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
2207 RSL_CCHAN.send(ts_RSL_UD(rsl));
2208
2209 f_exp_err_rep(RSL_ERR_IE_CONTENT);
2210}
2211
Harald Welte93640c62018-02-25 16:59:33 +01002212/***********************************************************************
2213 * IPA CRCX/MDCX/DLCS media stream handling
2214 ***********************************************************************/
2215
Harald Weltea871a382018-02-25 02:03:14 +01002216/* Send IPA DLCX to inactive lchan */
2217function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01002218 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2219 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01002220}
2221testcase TC_ipa_dlcx_not_active() runs on test_CT {
2222 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2223 f_init(testcasename());
2224 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
2225 vc_conn.done;
2226}
Harald Welte68e495b2018-02-25 00:05:57 +01002227
Harald Weltea3f1df92018-02-25 12:49:55 +01002228/* Send IPA CRCX twice to inactive lchan */
2229function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
2230 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2231 "IPA CRCX ACK");
2232 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
2233 "IPA CRCX NACK");
2234}
2235testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
2236 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2237 f_init(testcasename());
2238 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
2239 vc_conn.done;
2240}
2241
2242/* Regular sequence of CRCX/MDCX/DLCX */
2243function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2244 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2245 "IPA CRCX ACK");
2246 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2247 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2248 var uint7_t rtp_pt2 := f_rnd_int(127);
2249 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2250 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2251 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2252 "IPA MDCX ACK");
2253 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2254 "IPA DLCX ACK");
2255}
2256testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
2257 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2258 f_init(testcasename());
2259 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
2260 vc_conn.done;
2261}
2262
Harald Welte3ae11da2018-02-25 13:36:06 +01002263/* Sequence of CRCX, 2x MDCX, DLCX */
2264function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
2265 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
2266 "IPA CRCX ACK");
2267 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
2268 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
2269 var uint7_t rtp_pt2 := f_rnd_int(127);
2270 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
2271 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2272 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2273 "IPA MDCX ACK");
2274 /* Second MDCX */
2275 remote_ip := f_rnd_int(c_UINT32_MAX);
2276 remote_port := f_rnd_int(c_UINT16_MAX);
2277 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
2278 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
2279 "IPA MDCX ACK");
2280 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
2281 "IPA DLCX ACK");
2282}
2283testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
2284 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2285 f_init(testcasename());
2286 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
2287 vc_conn.done;
2288}
2289
Harald Welte9912eb52018-02-25 13:30:15 +01002290/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
2291function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
2292 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
2293 "IPA CRCX NACK");
2294}
2295testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
2296 var ConnHdlrPars pars;
2297 var ConnHdlr vc_conn;
2298 f_init(testcasename());
2299
2300 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
2301 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2302 vc_conn.done;
2303
2304 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
2305 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
2306 vc_conn.done;
2307}
2308
Harald Weltea3f1df92018-02-25 12:49:55 +01002309
Harald Welte883340c2018-02-28 18:59:29 +01002310/***********************************************************************
2311 * PCU Socket related tests
2312 ***********************************************************************/
2313
2314private function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
2315runs on test_CT {
2316 timer T := 3.0;
2317
2318 /* we don't expect any RTS.req before PDCH are active */
2319 T.start;
2320 alt {
2321 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
2322 setverdict(fail, "PCU RTS.req before PDCH active?");
2323 self.stop;
2324 }
2325 [] PCU.receive { repeat; }
2326 [] T.timeout { }
2327 }
2328
2329 /* Send PDCH activate request for known PDCH timeslot */
2330 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
2331
2332 /* we now expect RTS.req for this timeslot (only) */
2333 T.start;
2334 alt {
2335 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2336 setverdict(pass);
2337 }
2338 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2339 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2340 setverdict(fail, "Unexpected RTS.req for supposedly failing activation");
2341 self.stop;
2342 }
2343 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
2344 setverdict(fail, "RTS.req for wrong TRX/TS");
2345 self.stop;
2346 }
2347 [] PCU.receive { repeat; }
2348 [exp_success] T.timeout {
2349 setverdict(fail, "Timeout waiting for PCU RTS.req");
2350 }
2351 [not exp_success] T.timeout {
2352 setverdict(pass);
2353 }
2354 }
2355}
2356
2357private function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
2358runs on test_CT {
2359 timer T := 3.0;
2360
2361 /* Send PDCH activate request for known PDCH timeslot */
2362 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
2363
2364 PCU.clear;
2365 /* we now expect no RTS.req for this timeslot */
2366 T.start;
2367 alt {
2368 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
2369 setverdict(fail, "Received unexpected PCU RTS.req");
2370 self.stop;
2371 }
2372 [] PCU.receive { repeat; }
2373 [] T.timeout {
2374 setverdict(pass);
2375 }
2376 }
2377}
2378
2379/* PDCH activation via PCU socket; check for presence of RTS.req */
2380testcase TC_pcu_act_req() runs on test_CT {
2381 f_init();
2382 f_TC_pcu_act_req(0, 0, 7, true);
2383}
2384
2385/* PDCH activation via PCU socket on non-PDCU timeslot */
2386testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
2387 f_init();
2388 f_TC_pcu_act_req(0, 0, 1, false);
2389}
2390
2391/* PDCH activation via PCU socket on wrong BTS */
2392testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
2393 f_init();
2394 f_TC_pcu_act_req(23, 0, 7, false);
2395}
2396
2397/* PDCH activation via PCU socket on wrong TRX */
2398testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
2399 f_init();
2400 f_TC_pcu_act_req(0, 23, 7, false);
2401}
2402
2403/* PDCH deactivation via PCU socket; check for absence of RTS.req */
2404testcase TC_pcu_deact_req() runs on test_CT {
2405 f_init();
2406 /* Activate PDCH */
2407 f_TC_pcu_act_req(0, 0, 7, true);
2408 f_sleep(1.0);
2409 /* and De-Activate again */
2410 f_TC_pcu_deact_req(0, 0, 7);
2411}
2412
2413/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
2414testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
2415 f_init();
2416 f_TC_pcu_deact_req(0, 0, 1);
2417}
2418
2419/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
2420testcase TC_pcu_ver_si13() runs on test_CT {
2421 const octetstring si13 := '00010203040506070909'O;
2422 var PCUIF_send_data sd;
2423 timer T:= 3.0;
2424 f_init();
2425
2426 /* Set SI13 via RSL */
2427 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
2428 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, "BTS_Test v23")));
2429 T.start;
2430 alt {
2431 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
2432 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
2433 setverdict(pass);
2434 } else {
2435 repeat;
2436 }
2437 }
2438 [] PCU.receive { repeat; }
2439 [] T.timeout {
2440 setverdict(fail, "Timeout waiting for SI13");
2441 self.stop;
2442 }
2443 }
2444}
2445
2446private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
2447
2448/* helper function to send a PCU DATA.req */
2449private function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2450 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
2451runs on test_CT
2452{
2453 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
2454 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
2455}
2456
2457/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
2458private function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
2459 PCUIF_Sapi sapi, octetstring data)
2460runs on test_CT
2461{
2462 var PCUIF_send_data sd;
2463
2464 timer T := 3.0;
2465 T.start;
2466 alt {
2467 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
2468 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
2469 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
2470 sd.data.u.rts_req.fn, sapi, data);
2471 }
2472 [] PCU.receive { repeat; }
2473 [] T.timeout {
2474 setverdict(fail, "Timeout waiting for RTS.ind");
2475 }
2476 }
2477}
2478
2479/* Send DATA.req on invalid BTS */
2480testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
2481 f_init();
2482 f_TC_pcu_act_req(0, 0, 7, true);
2483 f_pcu_data_req(23, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2484 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2485 f_sleep(10.0);
2486}
2487
2488/* Send DATA.req on invalid TRX */
2489testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
2490 f_init();
2491 f_TC_pcu_act_req(0, 0, 7, true);
2492 f_pcu_data_req(0, 100, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2493 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2494 f_sleep(10.0);
2495}
2496
2497/* Send DATA.req on invalid timeslot */
2498testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
2499 f_init();
2500 f_TC_pcu_act_req(0, 0, 7, true);
2501 f_pcu_data_req(0, 0, 70, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2502 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2503 f_sleep(10.0);
2504}
2505
2506/* Send DATA.req on timeslot that hasn't been activated */
2507testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
2508 f_init();
2509 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2510 /* FIXME: how to check this wasn't actually sent and didn't crash BTS? */
2511 f_sleep(2.0);
2512}
2513
2514testcase TC_pcu_data_req_pdtch() runs on test_CT {
2515 f_init();
2516 f_TC_pcu_act_req(0, 0, 7, true);
2517 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PDTCH, c_PCU_DATA);
2518 /* FIXME: how to check this was actually sent */
2519 f_sleep(2.0);
2520}
2521
2522testcase TC_pcu_data_req_ptcch() runs on test_CT {
2523 f_init();
2524 f_TC_pcu_act_req(0, 0, 7, true);
2525 f_pcu_wait_rts_and_data_req(0, 0, 7, PCU_IF_SAPI_PTCCH, c_PCU_DATA);
2526 /* FIXME: how to check this was actually sent */
2527 f_sleep(2.0);
2528}
2529
2530/* Send AGCH from PCU; check it appears on Um side */
2531testcase TC_pcu_data_req_agch() runs on test_CT {
2532 timer T := 3.0;
2533 f_init();
2534 f_init_l1ctl();
2535 f_l1_tune(L1CTL);
2536
2537 f_TC_pcu_act_req(0, 0, 7, true);
2538 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
2539
2540 T.start;
2541 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002542 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01002543 setverdict(pass);
2544 }
2545 [] L1CTL.receive { repeat; }
2546 [] T.timeout {
2547 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2548 }
2549 }
2550}
2551
2552/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
2553testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
2554 var octetstring imm_ass := f_rnd_octstring(23);
2555 f_init();
2556 f_init_l1ctl();
2557 f_l1_tune(L1CTL);
2558
2559 /* append 3 last imsi digits so BTS can compute pagng group */
2560 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
2561
2562 timer T := 0.5;
2563 T.start;
2564 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002565 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01002566 /* TODO: verify paging group */
2567 setverdict(pass);
2568 }
2569 [] L1CTL.receive { repeat; }
2570 [] T.timeout {
2571 setverdict(fail, "Timeout waiting for PCU-originated AGCH block on Um");
2572 }
2573 }
2574}
2575
2576/* Send RACH from Um side, expect it to show up on PCU socket */
2577testcase TC_pcu_rach_content() runs on test_CT {
2578 f_init();
2579 f_init_l1ctl();
2580 f_l1_tune(L1CTL);
2581
2582 var GsmFrameNumber fn_last := 0;
2583 for (var integer i := 0; i < 1000; i := i+1) {
2584 var OCT1 ra := f_rnd_ra_ps();
2585 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
2586 if (fn == fn_last) {
2587 setverdict(fail, "Two RACH in same FN?!?");
2588 self.stop;
2589 }
2590 fn_last := fn;
2591
2592 timer T := 2.0;
2593 T.start;
2594 alt {
2595 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
2596 T.stop;
2597 }
2598 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
2599 setverdict(fail, "Unexpected RACH IND");
2600 self.stop;
2601 }
2602 [] PCU.receive { repeat; }
2603 [] T.timeout {
2604 setverdict(fail, "Timeout waiting for RACH IND");
2605 self.stop;
2606 }
2607 }
2608 }
2609 setverdict(pass);
2610}
2611
2612private function f_pad_oct(octetstring str, integer len, OCT1 pad) return octetstring {
2613 var integer strlen := lengthof(str);
2614 for (var integer i := 0; i < len-strlen; i := i+1) {
2615 str := str & pad;
2616 }
2617 return str;
2618}
2619
2620/* Send PAGING via RSL, expect it to shw up on PCU socket */
2621testcase TC_pcu_paging_from_rsl() runs on test_CT {
2622 f_init();
2623
2624 for (var integer i := 0; i < 100; i := i+1) {
2625 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2626 timer T := 3.0;
2627 if (i < 50) {
2628 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2629 } else {
2630 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
2631 }
2632 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2633 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2634 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
2635
2636 /* Send RSL PAGING COMMAND */
2637 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
2638 T.start;
2639 alt {
2640 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
2641 }
2642 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
2643 setverdict(fail, "Unexpected PAGING REQ");
2644 self.stop;
2645 }
2646 [] PCU.receive { repeat; }
2647 [] T.timeout {
2648 setverdict(fail, "Timeout waiting for PAGING REQ");
2649 self.stop;
2650 }
2651 }
2652 }
2653 setverdict(pass);
2654}
2655
Harald Welte3d04ae62018-04-04 20:29:05 +02002656/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02002657 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02002658 ***********************************************************************/
2659
2660private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2661runs on ConnHdlr {
2662 var PCUIF_send_data sd;
2663 /* Expect BTS to immediately acknowledge activation as PDCH */
2664 PCU.clear;
2665 f_rsl_chan_act(g_pars.chan_mode);
2666 /* expect INFO_IND on PCU interface listing TS as PDCH */
2667 alt {
2668 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2669 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
2670 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
2671 self.stop;
2672 }
2673 }
2674 [] PCU.receive { repeat; }
2675 }
2676 /* try to activate this PDCH from the PCU point of view */
2677 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2678 /* FIXME: is there a response? */
2679}
2680
2681private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2682runs on ConnHdlr {
2683 var PCUIF_send_data sd;
2684 /* Send RSL CHAN REL (deactivate) */
2685 PCU.clear;
2686 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2687 /* expect BTS to ask PCU to deactivate the channel */
2688 alt {
2689 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2690 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
2691 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
2692 self.stop;
2693 }
2694 }
2695 [] PCU.receive { repeat; }
2696 }
2697 /* Emulate PCU asking BTS to deactivate PDCH */
2698 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2699 alt {
2700 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
2701 setverdict(pass);
2702 }
2703 [] RSL.receive { repeat; }
2704 }
2705}
2706
2707/* Activate Osmocom-style dynamic PDCH from BSC side */
2708function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
2709 var PCUIF_Message first_info;
2710 var integer ts_nr := g_chan_nr.tn;
2711 var integer trx_nr := 0;
2712 var integer bts_nr := 0;
2713 var integer pcu_conn_id := -1;
2714
2715 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2716
2717 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
2718 f_sleep(3.0);
2719 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
2720 setverdict(pass);
2721}
2722testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
2723 var ConnHdlrPars pars;
2724 var ConnHdlr vc_conn;
2725 f_init(testcasename());
2726
2727 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2728 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
2729 vc_conn.done;
2730}
2731
2732/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
2733function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
2734 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02002735 var integer pcu_conn_id := -1;
2736
2737 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2738
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02002739 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
2740 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
2741 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02002742 setverdict(pass);
2743}
2744testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
2745 var ConnHdlrPars pars;
2746 var ConnHdlr vc_conn;
2747 f_init(testcasename());
2748
2749 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2750 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
2751 vc_conn.done;
2752}
2753
2754/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
2755function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
2756 var PCUIF_Message first_info;
2757 var integer ts_nr := g_chan_nr.tn;
2758 var integer trx_nr := 0;
2759 var integer bts_nr := 0;
2760 var integer pcu_conn_id := -1;
2761
2762 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2763
2764 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02002765 /* Send a second Chan Activ and expect it to be NACKed */
2766 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
2767 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02002768 setverdict(pass);
2769}
2770testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
2771 var ConnHdlrPars pars;
2772 var ConnHdlr vc_conn;
2773 f_init(testcasename());
2774
2775 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2776 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
2777 vc_conn.done;
2778}
2779
2780/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
2781function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
2782 var PCUIF_Message first_info;
2783 var integer ts_nr := g_chan_nr.tn;
2784 var integer trx_nr := 0;
2785 var integer bts_nr := 0;
2786 var integer pcu_conn_id := -1;
2787 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
2788
2789 /* register for the TCH/F channel number */
2790 f_rslem_register(0, chan_nr);
2791
2792 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2793
2794 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
2795 "RSL CHAN ACT");
2796 setverdict(pass);
2797}
2798testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
2799 var ConnHdlrPars pars;
2800 var ConnHdlr vc_conn;
2801 f_init(testcasename());
2802
2803 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2804 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
2805 vc_conn.done;
2806}
2807
2808/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
2809function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
2810 var PCUIF_Message first_info;
2811 var integer ts_nr := g_chan_nr.tn;
2812 var integer trx_nr := 0;
2813 var integer bts_nr := 0;
2814 var integer pcu_conn_id := -1;
2815 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
2816 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
2817
2818 /* register for the TCH/H channel numbers */
2819 f_rslem_register(0, chan_nr[0]);
2820 f_rslem_register(0, chan_nr[1]);
2821
2822 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2823
2824 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
2825 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
2826 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
2827 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
2828 setverdict(pass);
2829}
2830testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
2831 var ConnHdlrPars pars;
2832 var ConnHdlr vc_conn;
2833 f_init(testcasename());
2834
2835 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
2836 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
2837 vc_conn.done;
2838}
2839
Harald Welte9bbbfb52018-04-05 09:33:19 +02002840/***********************************************************************
2841 * IPA Style Dynamic Timeslot Support
2842 ***********************************************************************/
2843
2844private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2845runs on ConnHdlr {
2846 var PCUIF_send_data sd;
2847 /* Expect BTS to immediately acknowledge activation as PDCH */
2848 PCU.clear;
2849 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
2850 /* expect INFO_IND on PCU interface listing TS as PDCH */
2851 alt {
2852 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2853 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
2854 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
2855 self.stop;
2856 }
2857 }
2858 [] PCU.receive { repeat; }
2859 }
2860 /* try to activate this PDCH from the PCU point of view */
2861 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2862 /* FIXME: is there a response? */
2863
2864 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
2865}
2866
2867private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
2868runs on ConnHdlr {
2869 var PCUIF_send_data sd;
2870 /* Send RSL CHAN REL (deactivate) */
2871 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
2872 PCU.clear;
2873 /* expect BTS to ask PCU to deactivate the channel */
2874 alt {
2875 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
2876 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
2877 setverdict(fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
2878 self.stop;
2879 }
2880 }
2881 [] PCU.receive { repeat; }
2882 }
2883 /* Emulate PCU asking BTS to deactivate PDCH */
2884 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
2885 alt {
2886 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
2887 setverdict(pass);
2888 }
2889 [] RSL.receive { repeat; }
2890 }
2891}
2892
2893/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
2894function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
2895 var PCUIF_Message first_info;
2896 var integer ts_nr := g_chan_nr.tn;
2897 var integer trx_nr := 0;
2898 var integer bts_nr := 0;
2899 var integer pcu_conn_id := -1;
2900
2901 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2902
2903 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
2904 f_sleep(3.0);
2905 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
2906
2907 setverdict(pass);
2908
2909}
2910testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
2911 var ConnHdlrPars pars;
2912 var ConnHdlr vc_conn;
2913 f_init();
2914
2915 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
2916 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
2917 vc_conn.done;
2918}
2919
2920/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
2921function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
2922 var PCUIF_Message first_info;
2923 var integer ts_nr := g_chan_nr.tn;
2924 var integer trx_nr := 0;
2925 var integer bts_nr := 0;
2926 var integer pcu_conn_id := -1;
2927
2928 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2929
2930 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
2931 "RSL CHAN ACT");
2932 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
2933 "RF CHAN REL", true);
2934 setverdict(pass);
2935}
2936testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
2937 var ConnHdlrPars pars;
2938 var ConnHdlr vc_conn;
2939 f_init(testcasename());
2940
2941 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
2942 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
2943 vc_conn.done;
2944}
2945
2946/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
2947function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
2948 var PCUIF_Message first_info;
2949 var integer ts_nr := g_chan_nr.tn;
2950 var integer trx_nr := 0;
2951 var integer bts_nr := 0;
2952 var integer pcu_conn_id := -1;
2953
2954 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2955
2956 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
2957 "RSL CHAN ACT");
2958
2959 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
2960 alt {
2961 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
2962 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
2963 setverdict(fail, "Unexpected PDCH ACT ACK");
2964 self.stop;
2965 }
2966 [] RSL.receive { repeat; }
2967 }
2968
2969 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
2970 "RF CHAN REL", true);
2971 setverdict(pass);
2972}
2973testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
2974 var ConnHdlrPars pars;
2975 var ConnHdlr vc_conn;
2976 f_init(testcasename());
2977
2978 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
2979 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
2980 vc_conn.done;
2981}
2982
2983/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
2984function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
2985 var PCUIF_Message first_info;
2986 var integer ts_nr := g_chan_nr.tn;
2987 var integer trx_nr := 0;
2988 var integer bts_nr := 0;
2989 var integer pcu_conn_id := -1;
2990
2991 /* register for the TCH/F channel number */
2992 f_rslem_register(0, g_chan_nr);
2993
2994 f_init_pcu(PCU, id, pcu_conn_id, first_info);
2995
2996 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
2997
2998 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
2999 "RSL CHAN ACT");
3000
3001 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
3002
3003 setverdict(pass);
3004}
3005testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
3006 var ConnHdlrPars pars;
3007 var ConnHdlr vc_conn;
3008 f_init(testcasename());
3009
3010 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
3011 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
3012 vc_conn.done;
3013}
3014
3015
Harald Welte0472ab42018-03-12 15:02:26 +01003016/***********************************************************************
3017 * LAPDm / RLL related
3018 ***********************************************************************/
3019
3020private function f_tx_lapdm(template (value) LapdmFrame l,
3021 template (value) RslLinkId link_id) runs on ConnHdlr {
3022 var octetstring l2 := enc_LapdmFrame(valueof(l));
3023 if (valueof(link_id.c) == SACCH) {
3024 /* prepend dummy L1 header */
3025 l2 := '0000'O & l2;
3026 }
3027 log("encoding ", l, " to ", l2);
3028 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, l2));
3029}
3030
3031type record RllTestCase {
3032 uint3_t sapi,
3033 RslLinkId link_id,
3034 octetstring l3,
3035 boolean exp
3036}
3037type record of RllTestCase RllTestCases;
3038template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
3039 sapi := sapi,
3040 link_id := id,
3041 l3 := l3,
3042 exp := exp
3043}
3044
3045/* execute the same callback function with a set of different parameters (tcs) on a
3046 * variety of logical channels */
3047private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
3048 var ConnHdlrPars pars;
3049 var ConnHdlr vc_conn;
3050 f_init(testcasename());
3051
3052 /* test on each of the channels we have */
3053 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
3054 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
3055
3056 /* test each of the test cases on the current channel */
3057 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
3058 pars.spec.rll := tcs[j];
3059 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
3060 vc_conn := f_start_handler(fn, pars);
3061 vc_conn.done;
3062 }
3063 }
3064
3065 f_shutdown();
3066}
3067
3068/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
3069private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
3070 var RllTestCase tc := g_pars.spec.rll;
3071 timer T := 3.0;
3072
3073 f_l1_tune(L1CTL);
3074 RSL.clear;
3075
3076 /* activate the logical channel */
3077 f_est_dchan();
3078 L1CTL.clear;
3079
3080 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
3081 T.start;
3082 alt {
3083 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
3084 if (tc.exp) {
3085 setverdict(pass);
3086 } else {
3087 setverdict(fail, "Unexpected EST IND with L3 in ", tc);
3088 }
3089 }
3090 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
3091 if (tc.exp) {
3092 setverdict(pass);
3093 } else {
3094 setverdict(fail, "Unexpected EST IND without L3 in ", tc);
3095 }
3096 }
3097 [tc.exp] T.timeout {
3098 setverdict(fail, "Timeout waiting for EST IND");
3099 }
3100 [not tc.exp] T.timeout {
3101 setverdict(pass);
3102 }
3103 }
3104
3105 f_rsl_chan_deact();
3106 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3107 f_rslem_unregister(0, g_chan_nr);
3108}
3109testcase TC_rll_est_ind() runs on test_CT {
3110 var RllTestCases tcs := {
3111 /* normal SAPI0 establishment */
3112 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
3113 /* SAPI 0 requires contention resolution */
3114 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, false)),
3115 /* SAPI 3 doesn't support contention resolution */
3116 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
3117 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
3118 /* normal SAPI3 establishment on main DCCH */
3119 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3120 /* normal SAPI3 establishment on SACCH */
3121 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3122 };
3123 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
3124}
3125
3126/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
3127private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
3128 var RllTestCase tc := g_pars.spec.rll;
3129 var L1ctlDlMessage dl;
3130 timer T := 3.0;
3131
3132 f_l1_tune(L1CTL);
3133 RSL.clear;
3134
3135 /* activate the logical channel */
3136 f_est_dchan();
3137 L1CTL.clear;
3138
3139 /* Send a RSL EST REQ for SAPI3 on main DCCH */
3140 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
3141 T.start;
3142 alt {
3143 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3144 var LapdmFrame lapdm;
3145 var octetstring l2 := dl.payload.data_ind.payload;
3146 if (dl.dl_info.link_id.c == SACCH) {
3147 /* remove L1 header */
3148 l2 := substr(l2, 2, lengthof(l2)-2);
3149 }
3150 lapdm.ab := dec_LapdmFrameAB(l2);
3151 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
3152 setverdict(pass);
3153 } else {
3154 repeat;
3155 }
3156 }
3157 [] L1CTL.receive { repeat; }
3158 [] T.timeout {
3159 setverdict(fail, "Timeout waiting for SABM");
3160 self.stop;
3161 }
3162 }
3163
3164 f_rsl_chan_deact();
3165 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3166 f_rslem_unregister(0, g_chan_nr);
3167}
3168testcase TC_rll_est_req_DCCH_3() runs on test_CT {
3169 var RllTestCases tcs := {
3170 /* normal SAPI3 establishment on main DCCH */
3171 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
3172 };
3173 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3174}
3175testcase TC_rll_est_req_ACCH_3() runs on test_CT {
3176 var RllTestCases tcs := {
3177 /* normal SAPI3 establishment on SACCH */
3178 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3179 }
3180 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
3181}
3182
3183/* altstep to receive a LAPDm frame matching the given template */
3184private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
3185 var L1ctlDlMessage dl;
3186 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
3187 var LapdmFrame lapdm;
3188 var octetstring l2 := dl.payload.data_ind.payload;
3189 if (dl.dl_info.link_id.c == SACCH) {
3190 /* remove L1 header */
3191 l2 := substr(l2, 2, lengthof(l2)-2);
3192 }
3193 if (ischosen(exp.ab)) {
3194 lapdm.ab := dec_LapdmFrameAB(l2);
3195 } else if (ischosen(exp.b4)) {
3196 lapdm.b4 := dec_LapdmFrameB4(l2);
3197 } else if (ischosen(exp.bbis)) {
3198 lapdm.bbis := dec_LapdmFrameBbis(l2);
3199 }
3200 log("Rx LAPDm ", lapdm);
3201 if (match(lapdm, exp)) {
3202 setverdict(pass);
3203 } else {
3204 repeat;
3205 }
3206 }
3207 [] L1CTL.receive { repeat; }
3208}
3209private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
3210 timer T := t;
3211 T.start;
3212 alt {
3213 [] T.timeout {
3214 setverdict(fail, "Timeout waiting for LAPDm ", exp);
3215 self.stop;
3216 }
3217 [] as_l1_exp_lapdm(exp);
3218 }
3219}
3220
3221/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
3222private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
3223 /* send SABM from MS -> BTS */
3224 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
3225 /* expect RLL EST IND on Abis */
3226 alt {
3227 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
3228 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
3229 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
3230 setverdict(fail, "Failing due to RSL_ERROR_IND");
3231 self.stop;
3232 }
3233 [] RSL.receive { repeat; }
3234 }
3235 /* expect UA from BTS -> MS */
3236 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
3237}
3238
3239/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
3240private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
3241 var RllTestCase tc := g_pars.spec.rll;
3242
3243 f_l1_tune(L1CTL);
3244 RSL.clear;
3245
3246 /* activate the logical channel */
3247 f_est_dchan();
3248 L1CTL.clear;
3249
3250 /* first establish the link-layer */
3251 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3252
3253 /* then send the DISC */
3254 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
3255 /* ... and expect the REL IND on the RSL side */
3256 alt {
3257 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
3258 setverdict(pass);
3259 }
3260 }
3261
3262 /* release the channel */
3263 f_rsl_chan_deact();
3264 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3265 f_rslem_unregister(0, g_chan_nr);
3266}
3267testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
3268 var RllTestCases tcs := {
3269 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
3270 };
3271 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3272}
3273
3274testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
3275 var RllTestCases tcs := {
3276 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
3277 };
3278 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3279}
3280testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
3281 var RllTestCases tcs := {
3282 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
3283 };
3284 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3285}
3286testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
3287 var RllTestCases tcs := {
3288 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3289 };
3290 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
3291}
3292
3293/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
3294private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
3295 var RllTestCase tc := g_pars.spec.rll;
3296 f_l1_tune(L1CTL);
3297 RSL.clear;
3298
3299 /* activate the logical channel */
3300 f_est_dchan();
3301 L1CTL.clear;
3302
3303 /* first establish the link-layer */
3304 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
3305
3306 /* then send the REL REQ via RSL */
3307 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
3308 /* ... and expect the DISC on the Um side */
3309 alt {
3310 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MO_CMD, true)) {
3311 /* FIXME: send a UA in resposne to the DISC */
3312 }
3313 }
3314
3315 /* release the channel */
3316 f_rsl_chan_deact();
3317 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3318 f_rslem_unregister(0, g_chan_nr);
3319}
3320testcase TC_rll_rel_req() runs on test_CT {
3321 var RllTestCases tcs := {
3322 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
3323 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
3324 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
3325 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
3326 };
3327 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
3328}
3329
3330/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
3331testcase TC_rll_data_req() runs on test_CT {
3332}
3333
3334/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
3335testcase TC_rll_data_ind() runs on test_CT {
3336}
3337
3338/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
3339private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
3340 var RllTestCase tc := g_pars.spec.rll;
3341
3342 f_l1_tune(L1CTL);
3343 RSL.clear;
3344
3345 f_est_dchan();
3346 L1CTL.clear;
3347
3348 /* Send UNITDATA REQ on RSL side */
3349 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
3350 /* Expect it to arrive on the other side */
3351 if (tc.link_id.c == SACCH) {
3352 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, false, tc.l3));
3353 } else {
3354 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, false, tc.l3));
3355 }
3356
3357 /* release the channel */
3358 f_rsl_chan_deact();
3359 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3360 f_rslem_unregister(0, g_chan_nr);
3361}
3362testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
3363 var octetstring l3 := f_rnd_octstring(15);
3364 var RllTestCases tcs := {
3365 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3366 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3367 };
3368 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3369}
3370testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
3371 var octetstring l3 := f_rnd_octstring(19);
3372 var RllTestCases tcs := {
3373 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3374 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3375 };
3376 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
3377}
3378
3379/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
3380private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
3381 var RllTestCase tc := g_pars.spec.rll;
3382
3383 f_l1_tune(L1CTL);
3384 RSL.clear;
3385
3386 f_est_dchan();
3387 L1CTL.clear;
3388
3389 /* Send LAPDm UI frame. There is no B4 format in uplink! */
3390 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, false, tc.l3), tc.link_id);
3391 /* Expdct RLL UNITDATA IND on RSL side */
3392 alt {
3393 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
3394 setverdict(pass);
3395 }
3396 [] RSL.receive { repeat; }
3397 }
3398
3399 /* release the channel */
3400 f_rsl_chan_deact();
3401 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
3402 f_rslem_unregister(0, g_chan_nr);
3403}
3404testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
3405 var octetstring l3 := f_rnd_octstring(15);
3406 var RllTestCases tcs := {
3407 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
3408 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
3409 };
3410 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3411}
3412testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
3413 var octetstring l3 := f_rnd_octstring(18);
3414 var RllTestCases tcs := {
3415 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
3416 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
3417 };
3418 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
3419}
3420
3421
3422/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
3423/* protocol error as per 44.006 */
3424/* link layer failure (repetition of I-frame N200 times without ACK */
3425/* repetition of SABM or DISC N200 times without ACK */
3426/* receptiom of SABM in multi-frame established state */
3427
3428
3429
3430
Harald Welte883340c2018-02-28 18:59:29 +01003431
Harald Welte68e495b2018-02-25 00:05:57 +01003432/* TODO Areas:
3433
3434* channel activation
3435** with BS_Power / MS_Power, bypassing power control loop
3436** on primary vs. secondary TRX
3437** with encryption from initial activation on
3438** with timing advance from initial activation on
3439* mode modify
3440** encryption
3441** multirate
3442* check DEACTIVATE SACCH
3443* encryption command / intricate logic about tx-only/tx+rx/...
3444** unsupported algorithm
3445* handover detection
3446* MS Power Control
3447* BS Power Control
3448* Physical Context
3449* SACCH info modify
Harald Welte68e495b2018-02-25 00:05:57 +01003450* CCCH Load Indication for PCH and RACH
3451* Delete Indication on AGCH overflow
3452* SMS Broadcast Req / Cmd / CBCH LOad Ind
3453* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01003454* error handling
3455* discriminator error
3456** type error
3457** sequence error
3458** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01003459* PCU interface
3460** TIME_IND from BTS->PCU
3461** DATA_IND from BTS->PCU
3462** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01003463
3464*/
Harald Welte70767382018-02-21 12:16:40 +01003465
3466control {
3467 execute( TC_chan_act_stress() );
3468 execute( TC_chan_act_react() );
3469 execute( TC_chan_deact_not_active() );
3470 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01003471 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01003472 execute( TC_sacch_filling() );
3473 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01003474 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01003475 execute( TC_sacch_multi_chg() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01003476 execute( TC_rach_content() );
3477 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01003478 execute( TC_rach_max_ta() );
Harald Welte70767382018-02-21 12:16:40 +01003479 execute( TC_meas_res_sign_tchf() );
3480 execute( TC_meas_res_sign_tchh() );
3481 execute( TC_meas_res_sign_sdcch4() );
3482 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01003483 execute( TC_meas_res_sign_tchh_toa256() );
Harald Welte70767382018-02-21 12:16:40 +01003484 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01003485 execute( TC_paging_imsi_80percent() );
3486 execute( TC_paging_tmsi_80percent() );
3487 execute( TC_paging_imsi_200percent() );
3488 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01003489 execute( TC_rsl_protocol_error() );
3490 execute( TC_rsl_mand_ie_error() );
3491 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01003492 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01003493 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01003494 execute( TC_si_sched_2bis() );
3495 execute( TC_si_sched_2ter() );
3496 execute( TC_si_sched_2ter_2bis() );
3497 execute( TC_si_sched_2quater() );
3498 execute( TC_si_sched_13() );
3499 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01003500 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01003501 execute( TC_ipa_crcx_twice_not_active() );
3502 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01003503 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01003504 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01003505
3506 execute( TC_pcu_act_req() );
3507 execute( TC_pcu_act_req_wrong_ts() );
3508 execute( TC_pcu_act_req_wrong_bts() );
3509 execute( TC_pcu_act_req_wrong_trx() );
3510 execute( TC_pcu_deact_req() );
3511 execute( TC_pcu_deact_req_wrong_ts() );
3512 execute( TC_pcu_ver_si13() );
3513 execute( TC_pcu_data_req_wrong_bts() );
3514 execute( TC_pcu_data_req_wrong_trx() );
3515 execute( TC_pcu_data_req_wrong_ts() );
3516 execute( TC_pcu_data_req_ts_inactive() );
3517 execute( TC_pcu_data_req_pdtch() );
3518 execute( TC_pcu_data_req_ptcch() );
3519 execute( TC_pcu_data_req_agch() );
3520 execute( TC_pcu_data_req_imm_ass_pch() );
3521 execute( TC_pcu_rach_content() );
3522 execute( TC_pcu_paging_from_rsl() );
Harald Welte3d04ae62018-04-04 20:29:05 +02003523
3524 execute( TC_dyn_osmo_pdch_act_deact() );
3525 execute( TC_dyn_osmo_pdch_unsol_deact() );
3526 execute( TC_dyn_osmo_pdch_double_act() );
3527 execute( TC_dyn_osmo_pdch_tchf_act() );
3528 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02003529 execute( TC_dyn_ipa_pdch_act_deact() );
3530 execute( TC_dyn_ipa_pdch_tchf_act() );
3531 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
3532 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01003533
3534 execute( TC_rll_est_ind() );
3535 execute( TC_rll_est_req_DCCH_3() );
3536 execute( TC_rll_est_req_ACCH_3() );
3537 execute( TC_rll_rel_ind_DCCH_0() );
3538 execute( TC_rll_rel_ind_DCCH_3() );
3539 execute( TC_rll_rel_ind_ACCH_0() );
3540 execute( TC_rll_rel_ind_ACCH_3() );
3541 execute( TC_rll_rel_req() );
3542 execute( TC_rll_unit_data_req_DCCH() );
3543 execute( TC_rll_unit_data_req_ACCH() );
3544 execute( TC_rll_unit_data_ind_DCCH() );
3545 execute( TC_rll_unit_data_ind_ACCH() );
Harald Welte70767382018-02-21 12:16:40 +01003546}
3547
3548
3549}