blob: 410dc31c9dd6eeba6ac50e8d8b622faab63733ec [file] [log] [blame]
Harald Welte9fbcf4b2018-12-07 07:56:52 +01001module PCU_Tests_RAW {
2
3/* "RAW" PCU tests: Talk directly to the PCU socket of OsmoPCU on the one hand side (emulating
4 the BTS/BSC side PCU socket server) and the Gb interface on the other hand side. No NS/BSSGP
5 Emulation is used; rather, we simply use the NS_CodecPort to implement both standard and non-
6 standard procedures on the NS and BSSGP level. The goal of these tests is to test exactly
7 those NS and BSSGP implementations on the BSS (PCU) side. */
8
Harald Welte34b5a952019-05-27 11:54:11 +02009/* (C) 2018-2019 Harald Welte <laforge@gnumonks.org>
Vadim Yanitskiy3e1d3182019-09-11 16:53:45 +020010 * (C) 2019 Vadim Yanitskiy <axilirator@gmail.com>
Harald Welte34b5a952019-05-27 11:54:11 +020011 * All rights reserved.
12 *
13 * Released under the terms of GNU General Public License, Version 2 or
14 * (at your option) any later version.
15 *
16 * SPDX-License-Identifier: GPL-2.0-or-later
17 */
18
Harald Welte9fbcf4b2018-12-07 07:56:52 +010019import from General_Types all;
20import from Osmocom_Types all;
Harald Welte7fd25cf2019-03-21 22:14:02 +010021import from GSM_Types all;
22import from GSM_RR_Types all;
23
Pau Espin Pedrol2a45a502019-11-29 12:48:16 +010024import from Osmocom_VTY_Functions all;
25import from TELNETasp_PortType all;
26
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +020027import from RLCMAC_CSN1_Types all;
28import from RLCMAC_Types all;
29
Harald Welte9fbcf4b2018-12-07 07:56:52 +010030import from NS_Types all;
31import from BSSGP_Types all;
32import from Osmocom_Gb_Types all;
33
34import from BSSGP_Emulation all; /* BssgpConfig */
35import from NS_Emulation all; /* NSConfiguration */
36
37import from UD_Types all;
38import from PCUIF_Types all;
39import from PCUIF_CodecPort all;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +020040import from PCUIF_RAW_Components all;
Harald Welte9fbcf4b2018-12-07 07:56:52 +010041import from IPL4asp_Types all;
42import from NS_CodecPort all;
43import from NS_CodecPort_CtrlFunct all;
44import from Native_Functions all;
45import from PCU_Tests all;
46
47modulepar {
48 charstring mp_pcu_sock_path := PCU_SOCK_DEFAULT;
Pau Espin Pedrola3f0a852019-12-02 19:16:26 +010049
50 float X2002 := 0.2; /* Timer -2002, IMM ASSIGN confirm delay */
Harald Welte9fbcf4b2018-12-07 07:56:52 +010051}
52
53type component RAW_NS_CT {
54 /* UDP port towards the bottom (IUT) */
Harald Weltebf768242019-02-21 22:19:21 +010055 port NS_CODEC_PT NSCP[4];
56 var ConnectionId g_ns_conn_id[4] := {-1, -1, -1, -1};
57 var NSConfiguration g_nsconfig[4];
Harald Welte9fbcf4b2018-12-07 07:56:52 +010058 timer g_T_guard;
Harald Welteea3c7e92019-03-01 19:34:55 +010059}
Harald Welte9fbcf4b2018-12-07 07:56:52 +010060
Harald Welteea3c7e92019-03-01 19:34:55 +010061type component RAW_PCU_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +010062 /* PCUIF (we emulate the BTS part) */
63 port PCUIF_CODEC_PT PCU;
64 var ConnectionId g_pcu_conn_id := -1;
65}
66
Harald Welteea3c7e92019-03-01 19:34:55 +010067type component RAW_Test_CT extends RAW_NS_CT, RAW_PCU_CT {
68}
69
Harald Welte9fbcf4b2018-12-07 07:56:52 +010070private altstep as_Tguard() runs on RAW_NS_CT {
71 [] g_T_guard.timeout {
72 setverdict(fail, "Timeout of T_guard");
73 mtc.stop;
74 }
75}
76
Pau Espin Pedrolf787b092019-10-04 18:34:05 +020077/* FIXME: make sure to use parameters from mp_gb_cfg.cell_id in the PCU INFO IND */
78template (value) PCUIF_info_ind ts_PCUIF_INFO_default := {
79 version := PCU_IF_VERSION,
80 flags := c_PCUIF_Flags_default,
81 trx := valueof(ts_PCUIF_InfoTrxs_def),
82 bsic := 7,
83 mcc := 262,
84 mnc := 42,
85 mnc_3_digits := 0,
86 lac := 13135,
87 rac := 0,
88 nsei := mp_nsconfig.nsei,
89 nse_timer := { 3, 3, 3, 3, 30, 3, 10 },
90 cell_timer := { 3, 3, 3, 3, 3, 10, 3, 10, 3, 10, 3 },
91 cell_id := 20960,
92 repeat_time := 5 * 50,
93 repeat_count := 3,
94 bvci := mp_gb_cfg.bvci,
95 t3142 := 20,
96 t3169 := 5,
97 t3191 := 5,
98 t3193_10ms := 160,
99 t3195 := 5,
100 t3101 := 10,
101 t3103 := 4,
102 t3105 := 8,
103 cv_countdown := 15,
104 dl_tbf_ext := 250 * 10, /* ms */
105 ul_tbf_ext := 250 * 10, /* ms */
106 initial_cs := 2,
107 initial_mcs := 6,
108 nsvci := { mp_nsconfig.nsvci, 0 },
109 local_pprt := { mp_nsconfig.remote_udp_port, 0 },
110 remote_port := { mp_nsconfig.local_udp_port, 0 },
111 remote_ip := { f_inet_haddr(mp_nsconfig.local_ip) , '00000000'O }
112}
113
Harald Welteea3c7e92019-03-01 19:34:55 +0100114function f_init_pcuif() runs on RAW_PCU_CT {
Pau Espin Pedrolf787b092019-10-04 18:34:05 +0200115 var PCUIF_info_ind info_ind;
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100116 map(self:PCU, system:PCU);
117
Pau Espin Pedrolf787b092019-10-04 18:34:05 +0200118
119 info_ind := valueof(ts_PCUIF_INFO_default);
120
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100121 /* Connect the Unix Domain Socket */
122 g_pcu_conn_id := f_pcuif_listen(PCU, mp_pcu_sock_path);
123 PCU.receive(UD_connected:?);
124
125 /* Wait for PCU_VERSION and return INFO_IND */
126 PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TXT_IND(0, PCU_VERSION, ?)));
127 /* FIXME: make sure to use parameters from mp_gb_cfg.cell_id in the PCU INFO IND */
Pau Espin Pedrolf787b092019-10-04 18:34:05 +0200128 var template PCUIF_Message info_ind_msg := ts_PCUIF_INFO_IND(0, info_ind);
129 PCU.send(t_SD_PCUIF(g_pcu_conn_id, info_ind_msg));
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100130}
131
Harald Welte0466d162019-03-21 21:30:21 +0100132function f_pcuif_tx(template (value) PCUIF_Message msg) runs on RAW_PCU_CT {
133 PCU.send(t_SD_PCUIF(g_pcu_conn_id, msg));
134}
135
Harald Weltebf768242019-02-21 22:19:21 +0100136function f_init_ns_codec(integer idx := 0, float guard_secs := 60.0) runs on RAW_NS_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100137 var Result res;
Harald Weltebf768242019-02-21 22:19:21 +0100138
139 if (not g_T_guard.running) {
140 g_T_guard.start(guard_secs);
141 activate(as_Tguard());
142 }
143
144 if (not isbound(g_nsconfig) or not isbound(g_nsconfig[idx])) {
145 /* copy most parts from mp_nsconfig */
146 g_nsconfig[idx] := mp_nsconfig;
147 /* adjust those parts different for each NS-VC */
148 g_nsconfig[idx].nsvci := mp_nsconfig.nsvci + idx;
149 g_nsconfig[idx].local_udp_port := mp_nsconfig.local_udp_port + idx;
150 }
151
152 map(self:NSCP[idx], system:NSCP);
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100153 /* Connect the UDP socket */
Harald Weltebf768242019-02-21 22:19:21 +0100154 log("connecting NSCP[", idx, "] to ", g_nsconfig[idx]);
155 res := f_IPL4_connect(NSCP[idx], g_nsconfig[idx].remote_ip, g_nsconfig[idx].remote_udp_port,
156 g_nsconfig[idx].local_ip, g_nsconfig[idx].local_udp_port, 0, { udp := {}});
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100157 if (not ispresent(res.connId)) {
Harald Weltebf768242019-02-21 22:19:21 +0100158 setverdict(fail, "Could not connect NS UDP socket, check your configuration ", g_nsconfig[idx]);
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100159 mtc.stop;
160 }
Harald Weltebf768242019-02-21 22:19:21 +0100161 g_ns_conn_id[idx] := res.connId;
162
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100163}
164
Harald Weltebf768242019-02-21 22:19:21 +0100165function f_ns_exp(template PDU_NS exp_rx, integer idx := 0) runs on RAW_NS_CT return PDU_NS {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100166 var NS_RecvFrom nrf;
167 log("f_ns_exp() expecting ", exp_rx);
168 alt {
Harald Weltebf768242019-02-21 22:19:21 +0100169 [] NSCP[idx].receive(t_NS_RecvFrom(exp_rx)) -> value nrf { }
170 [] NSCP[idx].receive {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100171 setverdict(fail, "Received unexpected NS: ", nrf);
172 mtc.stop;
173 }
174 }
175 return nrf.msg;
176}
177
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100178/* perform outbound NS-ALIVE procedure */
Harald Weltebf768242019-02-21 22:19:21 +0100179function f_outgoing_ns_alive(integer idx := 0) runs on RAW_NS_CT {
180 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE));
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100181 alt {
Harald Weltebf768242019-02-21 22:19:21 +0100182 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE_ACK));
183 [] NSCP[idx].receive { repeat; }
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100184 }
185}
186
Harald Welteecd159e2019-03-16 13:36:07 +0100187/* perform outbound NS-ALIVE procedure */
188function f_outgoing_ns_alive_no_ack(integer idx := 0, float tout := 10.0) runs on RAW_NS_CT {
189 timer T := tout;
190 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE));
191 T.start;
192 alt {
193 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE_ACK)) {
194 setverdict(fail, "Received unexpected NS-ALIVE ACK");
195 }
196 [] NSCP[idx].receive { repeat; }
197 [] T.timeout {
198 setverdict(pass);
199 }
200 }
201}
202
203/* ensure no matching message is received within 'tout' */
204function f_ensure_no_ns(template PDU_NS ns := ?, integer idx := 0, float tout := 3.0)
205runs on RAW_Test_CT {
206 timer T := tout;
207 T.start;
208 alt {
209 [] NSCP[idx].receive(t_NS_RecvFrom(ns)) {
210 setverdict(fail, "NS-ALIVE from unconfigured (possibly initial) endpoint");
211 }
212 [] T.timeout {
213 setverdict(pass);
214 }
215 }
216}
217
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100218/* perform outbound NS-BLOCK procedure */
Harald Weltebf768242019-02-21 22:19:21 +0100219function f_outgoing_ns_block(NsCause cause, integer idx := 0) runs on RAW_NS_CT {
220 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_BLOCK(cause, g_nsconfig[idx].nsvci)));
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100221 alt {
Harald Weltebf768242019-02-21 22:19:21 +0100222 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_BLOCK_ACK(g_nsconfig[idx].nsvci)));
223 [] NSCP[idx].receive { repeat; }
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100224 }
225}
226
227/* receive NS-ALIVE and ACK it */
Harald Weltebf768242019-02-21 22:19:21 +0100228altstep as_rx_alive_tx_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
229 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_ALIVE)) {
230 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_ALIVE_ACK));
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100231 if (not oneshot) { repeat; }
232 }
233}
234
Harald Welte64d07312019-03-20 09:48:39 +0100235/* Transmit BSSGP RESET for given BVCI and expect ACK */
236function f_tx_bvc_reset_rx_ack(BssgpBvci bvci, integer idx := 0, boolean exp_ack := true)
237runs on RAW_NS_CT {
238 var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET(BSSGP_CAUSE_NET_SV_CAP_MOD_GT_ZERO_KBPS, bvci,
239 mp_gb_cfg.cell_id));
240 timer T := 5.0;
241 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))));
242 T.start;
243 alt {
244 [exp_ack] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0,
245 decmatch tr_BVC_RESET_ACK(bvci, ?)))) {
246 setverdict(pass);
247 }
248 [exp_ack] T.timeout {
249 setverdict(fail, "No response to BVC-RESET");
250 }
251 [not exp_ack] T.timeout {
252 setverdict(pass);
253 }
254 [] NSCP[idx].receive { repeat; }
255 }
256}
257
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100258/* Receive a BSSGP RESET for given BVCI and ACK it */
Harald Weltebf768242019-02-21 22:19:21 +0100259altstep as_rx_bvc_reset_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100260 var NS_RecvFrom ns_rf;
261 /* FIXME: nail down received cell_id in match */
Harald Weltebf768242019-02-21 22:19:21 +0100262 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0,
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100263 decmatch tr_BVC_RESET(?, bvci, ?))))
264 -> value ns_rf {
265 var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU);
266 var PDU_BSSGP bssgp_tx := valueof(ts_BVC_RESET_ACK(bvci, mp_gb_cfg.cell_id));
Harald Weltebf768242019-02-21 22:19:21 +0100267 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))));
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100268 if (not oneshot) { repeat; }
269 }
270}
271
272
273/* Receive a BSSGP UNBLOCK for given BVCI and ACK it */
Harald Weltebf768242019-02-21 22:19:21 +0100274altstep as_rx_bvc_unblock_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100275 var NS_RecvFrom ns_rf;
Harald Weltebf768242019-02-21 22:19:21 +0100276 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, 0,
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100277 decmatch t_BVC_UNBLOCK(bvci))))
278 -> value ns_rf {
279 var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU);
280 var PDU_BSSGP bssgp_tx := valueof(t_BVC_UNBLOCK_ACK(bvci));
Harald Weltebf768242019-02-21 22:19:21 +0100281 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, 0, enc_PDU_BSSGP(bssgp_tx))));
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100282 if (not oneshot) { repeat; }
283 }
284}
285
286/* Receive a BSSGP FLOW-CONTROL-BVC and ACK it */
Harald Weltebf768242019-02-21 22:19:21 +0100287altstep as_rx_bvc_fc_tx_ack(BssgpBvci bvci, boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100288 var NS_RecvFrom ns_rf;
Harald Weltebf768242019-02-21 22:19:21 +0100289 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_UNITDATA(t_SduCtrlB, bvci,
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100290 decmatch tr_BVC_FC_BVC)))
291 -> value ns_rf {
292 var PDU_BSSGP bssgp_rx := dec_PDU_BSSGP(ns_rf.msg.pDU_NS_Unitdata.nS_SDU);
293 var OCT1 tag := bssgp_rx.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value;
294 var PDU_BSSGP bssgp_tx := valueof(t_BVC_FC_BVC_ACK(tag));
Harald Weltebf768242019-02-21 22:19:21 +0100295 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_UNITDATA(t_SduCtrlB, bvci, enc_PDU_BSSGP(bssgp_tx))));
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100296 if (not oneshot) { repeat; }
297 }
298}
299
300/**********************************************************************************
301 * Classic Gb/IP bring-up test cases using NS-{RESET,BLOCK,UNBLOCK} and no IP-SNS *
302 **********************************************************************************/
303
304/* Receive a NS-RESET and ACK it */
Harald Weltebf768242019-02-21 22:19:21 +0100305private altstep as_rx_ns_reset_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100306 var NS_RecvFrom ns_rf;
Harald Weltebf768242019-02-21 22:19:21 +0100307 [] NSCP[idx].receive(t_NS_RecvFrom(tr_NS_RESET(NS_CAUSE_OM_INTERVENTION, g_nsconfig[idx].nsvci,
308 g_nsconfig[idx].nsei))) -> value ns_rf {
309 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], ts_NS_RESET_ACK(g_nsconfig[idx].nsvci,
310 g_nsconfig[idx].nsei)));
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100311 if (not oneshot) { repeat; }
312 }
313}
314/* Receive a NS-UNBLOCK and ACK it */
Harald Weltebf768242019-02-21 22:19:21 +0100315private altstep as_rx_ns_unblock_ack(boolean oneshot := false, integer idx := 0) runs on RAW_NS_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100316 var NS_RecvFrom ns_rf;
Harald Weltebf768242019-02-21 22:19:21 +0100317 [] NSCP[idx].receive(t_NS_RecvFrom(t_NS_UNBLOCK)) -> value ns_rf {
318 NSCP[idx].send(t_NS_Send(g_ns_conn_id[idx], t_NS_UNBLOCK_ACK));
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100319 if (not oneshot) { repeat; }
320 }
321}
322
323/* test the NS-RESET procedure */
Harald Welteea3c7e92019-03-01 19:34:55 +0100324testcase TC_ns_reset() runs on RAW_Test_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100325 f_init_ns_codec();
326 f_init_pcuif();
327
328
329 /* Expect inbound NS-RESET procedure */
330 as_rx_ns_reset_ack(oneshot := true);
331 setverdict(pass);
332}
333
334/* ensure NS-RESET are re-transmitted */
Harald Welteea3c7e92019-03-01 19:34:55 +0100335testcase TC_ns_reset_retrans() runs on RAW_Test_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100336 f_init_ns_codec();
337 f_init_pcuif();
338
339 var integer i;
340 for (i := 0; i < 3; i := i+1) {
Harald Weltebf768242019-02-21 22:19:21 +0100341 NSCP[0].receive(t_NS_RecvFrom(tr_NS_RESET(NS_CAUSE_OM_INTERVENTION,
342 g_nsconfig[0].nsvci, g_nsconfig[0].nsei)));
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100343 }
344
345 /* Expect inbound NS-RESET procedure */
346 as_rx_ns_reset_ack(oneshot := true);
347 setverdict(pass);
348}
349
350/* test the inbound NS-ALIVE procedure after NS-RESET */
Harald Welteea3c7e92019-03-01 19:34:55 +0100351testcase TC_ns_alive() runs on RAW_Test_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100352 f_init_ns_codec();
353 f_init_pcuif();
354
355 /* Expect inbound NS-RESET procedure */
356 as_rx_ns_reset_ack(oneshot := true);
357
358 /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */
359 as_rx_alive_tx_ack(oneshot := true);
360 setverdict(pass);
361}
362
363/* Test for NS-RESET after NS-ALIVE timeout */
Harald Welteea3c7e92019-03-01 19:34:55 +0100364testcase TC_ns_alive_timeout_reset() runs on RAW_Test_CT {
Harald Weltebf768242019-02-21 22:19:21 +0100365 f_init_ns_codec(guard_secs := 100.0);
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100366 f_init_pcuif();
367
368 /* Expect inbound NS-RESET procedure */
369 as_rx_ns_reset_ack(oneshot := true);
370
371 /* wait for at least one NS-ALIVE */
Harald Weltebf768242019-02-21 22:19:21 +0100372 NSCP[0].receive(t_NS_RecvFrom(t_NS_ALIVE));
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100373
374 /* wait for NS-RESET to re-appear, ignoring any NS-ALIVE until then */
375 alt {
376 [] as_rx_ns_reset_ack(oneshot := true) { setverdict(pass); }
Harald Weltebf768242019-02-21 22:19:21 +0100377 [] NSCP[0].receive(t_NS_RecvFrom(t_NS_ALIVE)) { repeat; }
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100378 }
379}
380
381/* test for NS-RESET/NS-ALIVE/NS-UNBLOCK */
Harald Welteea3c7e92019-03-01 19:34:55 +0100382testcase TC_ns_unblock() runs on RAW_Test_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100383 f_init_ns_codec();
384 f_init_pcuif();
385
386 /* Expect inbound NS-RESET procedure */
387 as_rx_ns_reset_ack(oneshot := true);
388
389 /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */
390 as_rx_alive_tx_ack(oneshot := true);
391 activate(as_rx_alive_tx_ack());
392
393 as_rx_ns_unblock_ack(oneshot := true);
394 setverdict(pass);
395}
396
397/* test for NS-UNBLOCK re-transmissions */
Harald Welteea3c7e92019-03-01 19:34:55 +0100398testcase TC_ns_unblock_retrans() runs on RAW_Test_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100399 f_init_ns_codec();
400 f_init_pcuif();
401
402 /* Expect inbound NS-RESET procedure */
403 as_rx_ns_reset_ack(oneshot := true);
404
405 /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */
406 as_rx_alive_tx_ack(oneshot := true);
407 activate(as_rx_alive_tx_ack());
408
409 /* wait for first NS-UNBLOCK, don't respond */
Harald Weltebf768242019-02-21 22:19:21 +0100410 NSCP[0].receive(t_NS_RecvFrom(t_NS_UNBLOCK));
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100411
412 /* wait for re-transmission of NS-UNBLOCK */
413 as_rx_ns_unblock_ack(oneshot := true);
414 setverdict(pass);
415}
416
417/* full bring-up of the Gb link for NS and BSSGP layer up to BVC-FC */
Harald Welteea3c7e92019-03-01 19:34:55 +0100418testcase TC_ns_full_bringup() runs on RAW_Test_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100419 f_init_ns_codec();
420 f_init_pcuif();
421
422 /* Expect inbound NS-RESET procedure */
423 as_rx_ns_reset_ack(oneshot := true);
424
425 /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */
426 as_rx_alive_tx_ack(oneshot := true);
427 activate(as_rx_alive_tx_ack());
428
429 as_rx_ns_unblock_ack(oneshot := true);
430
431 f_outgoing_ns_alive();
432
433 /* Expect BVC-RESET for signaling (0) and ptp BVCI */
434 as_rx_bvc_reset_tx_ack(0, oneshot := true);
435 as_rx_bvc_reset_tx_ack(mp_gb_cfg.bvci, oneshot := true);
436 as_rx_bvc_unblock_tx_ack(mp_gb_cfg.bvci, oneshot := true);
437
438 /* wait for one FLOW-CONTROL BVC and then ACK any further in the future */
439 as_rx_bvc_fc_tx_ack(mp_gb_cfg.bvci, oneshot := true);
440 activate(as_rx_bvc_fc_tx_ack(mp_gb_cfg.bvci));
441 setverdict(pass);
442}
443
444/* test outbound (SGSN-originated) NS-BLOCK procedure */
Harald Welteea3c7e92019-03-01 19:34:55 +0100445testcase TC_ns_so_block() runs on RAW_Test_CT {
Harald Welte9fbcf4b2018-12-07 07:56:52 +0100446 f_init_ns_codec();
447 f_init_pcuif();
448
449 /* Expect inbound NS-RESET procedure */
450 as_rx_ns_reset_ack(oneshot := true);
451
452 /* wait for one ALIVE cycle, then ACK any further ALIVE in the background */
453 as_rx_alive_tx_ack(oneshot := true);
454 activate(as_rx_alive_tx_ack());
455
456 as_rx_ns_unblock_ack(oneshot := true);
457
458 f_outgoing_ns_alive();
459
460 f_outgoing_ns_block(NS_CAUSE_EQUIPMENT_FAILURE);
461 setverdict(pass);
462}
463
Pau Espin Pedrol2a45a502019-11-29 12:48:16 +0100464type record lqual_range {
465 /* component reference to the IPA_Client component used for RSL */
466 uint8_t low,
467 uint8_t high
468}
469
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200470type component RAW_PCU_Test_CT extends bssgp_CT {
471 /* Connection to the BTS component (one for now) */
472 port RAW_PCU_MSG_PT BTS;
473 /* Connection to the PCUIF component */
474 port RAW_PCU_MSG_PT PCUIF;
Pau Espin Pedrol2a45a502019-11-29 12:48:16 +0100475 /* VTY connection to the PCU */
476 port TELNETasp_PT PCUVTY;
477
478 /* Uplink CS/MCS thresholds, default from pcu_main.c: */
479 var lqual_range g_cs_lqual_ranges[4] := {{low := 0, high := 6},
480 {low := 5, high := 8},
481 {low := 7, high := 13},
482 {low := 12,high := 35}};
483 var lqual_range g_mcs_lqual_ranges[9] := {{low := 0, high := 6},
484 {low := 5, high := 8},
485 {low := 7, high := 13},
486 {low := 12,high := 15},
487 {low := 14, high := 17},
488 {low := 16, high := 18},
489 {low := 17,high := 20},
490 {low := 19, high := 24},
491 {low := 23,high := 35}};
492 var uint8_t g_cs_initial_dl := 1;
493 var uint8_t g_cs_initial_ul := 1;
494 var uint8_t g_mcs_initial_dl := 1;
495 var uint8_t g_mcs_initial_ul := 1;
496 var uint8_t g_cs_max_dl := 4;
497 var uint8_t g_cs_max_ul := 4;
498 var uint8_t g_mcs_max_dl := 9;
499 var uint8_t g_mcs_max_ul := 9;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200500
501 /* Guard timeout */
502 timer g_T_guard := 60.0;
503};
504
505private altstep as_Tguard_RAW() runs on RAW_PCU_Test_CT {
506 [] g_T_guard.timeout {
507 setverdict(fail, "Timeout of T_guard");
508 mtc.stop;
509 }
510}
511
Pau Espin Pedrol2a45a502019-11-29 12:48:16 +0100512private function f_pcuvty_set_allowed_cs_mcs() runs on RAW_PCU_Test_CT {
513 f_vty_config2(PCUVTY, {"pcu"}, "cs " & int2str(g_cs_initial_dl) & " " & int2str(g_cs_initial_ul));
514 f_vty_config2(PCUVTY, {"pcu"}, "cs max " & int2str(g_cs_max_dl) & " " & int2str(g_cs_max_ul));
515
516 f_vty_config2(PCUVTY, {"pcu"}, "mcs " & int2str(g_mcs_initial_dl) & " " & int2str(g_mcs_initial_ul));
517 f_vty_config2(PCUVTY, {"pcu"}, "mcs max " & int2str(g_mcs_max_dl) & " " & int2str(g_mcs_max_ul));
518}
519
520private function f_pcuvty_set_link_quality_ranges() runs on RAW_PCU_Test_CT {
521 var charstring cmd;
522
523 cmd := "cs link-quality-ranges" &
524 " cs1 " & int2str(g_cs_lqual_ranges[0].high) &
525 " cs2 " & int2str(g_cs_lqual_ranges[1].low) & " " & int2str(g_cs_lqual_ranges[1].high) &
526 " cs3 " & int2str(g_cs_lqual_ranges[2].low) & " " & int2str(g_cs_lqual_ranges[2].high) &
527 " cs4 " & int2str(g_cs_lqual_ranges[3].low);
528 f_vty_config2(PCUVTY, {"pcu"}, cmd);
529
530 cmd := "mcs link-quality-ranges" &
531 " mcs1 " & int2str(g_mcs_lqual_ranges[0].high) &
532 " mcs2 " & int2str(g_mcs_lqual_ranges[1].low) & " " & int2str(g_mcs_lqual_ranges[1].high) &
533 " mcs3 " & int2str(g_mcs_lqual_ranges[2].low) & " " & int2str(g_mcs_lqual_ranges[2].high) &
534 " mcs4 " & int2str(g_mcs_lqual_ranges[3].low) & " " & int2str(g_mcs_lqual_ranges[3].high) &
535 " mcs5 " & int2str(g_mcs_lqual_ranges[4].low) & " " & int2str(g_mcs_lqual_ranges[4].high) &
536 " mcs6 " & int2str(g_mcs_lqual_ranges[5].low) & " " & int2str(g_mcs_lqual_ranges[5].high) &
537 " mcs7 " & int2str(g_mcs_lqual_ranges[6].low) & " " & int2str(g_mcs_lqual_ranges[6].high) &
538 " mcs8 " & int2str(g_mcs_lqual_ranges[7].low) & " " & int2str(g_mcs_lqual_ranges[7].high) &
539 " mcs9 " & int2str(g_mcs_lqual_ranges[8].low);
540 f_vty_config2(PCUVTY, {"pcu"}, cmd);
541}
542
543private function f_init_vty(charstring id) runs on RAW_PCU_Test_CT {
544 map(self:PCUVTY, system:PCUVTY);
545 f_vty_set_prompts(PCUVTY);
546 f_vty_transceive(PCUVTY, "enable");
547}
548
Pau Espin Pedrolf787b092019-10-04 18:34:05 +0200549private function f_init_raw(charstring id, template (value) PCUIF_info_ind info_ind := ts_PCUIF_INFO_default)
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200550runs on RAW_PCU_Test_CT {
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200551 var RAW_PCUIF_CT vc_PCUIF;
552 var RAW_PCU_BTS_CT vc_BTS;
553
554 /* Start the guard timer */
555 g_T_guard.start;
556 activate(as_Tguard_RAW());
557
558 /* Init PCU interface component */
559 vc_PCUIF := RAW_PCUIF_CT.create("PCUIF-" & id);
560 connect(vc_PCUIF:MTC, self:PCUIF);
561 map(vc_PCUIF:PCU, system:PCU);
562
563 /* Create one BTS component (we may want more some day) */
564 vc_BTS := RAW_PCU_BTS_CT.create("BTS-" & id);
565 connect(vc_BTS:PCUIF, vc_PCUIF:BTS);
566 connect(vc_BTS:TC, self:BTS);
567
Pau Espin Pedrol2a45a502019-11-29 12:48:16 +0100568 f_init_vty(id);
569
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200570 vc_PCUIF.start(f_PCUIF_CT_handler(mp_pcu_sock_path));
Pau Espin Pedrolf787b092019-10-04 18:34:05 +0200571 vc_BTS.start(f_BTS_CT_handler(0, valueof(info_ind)));
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200572
573 /* Wait until the BTS is ready (SI13 negotiated) */
574 BTS.receive(tr_RAW_PCU_EV(BTS_EV_SI13_NEGO));
575}
576
Vadim Yanitskiy3e1d3182019-09-11 16:53:45 +0200577/* FIXME: properly encode RA (see TS 24.060, table 11.2.5.2) */
578private function f_establish_tbf(out GsmRrMessage rr_imm_ass, uint8_t bts_nr := 0,
579 uint16_t ra := oct2int('3A'O), uint8_t is_11bit := 0,
580 PCUIF_BurstType burst_type := BURST_TYPE_0,
581 TimingAdvance ta := 0)
582runs on RAW_PCU_Test_CT return boolean {
583 var PCUIF_Message pcu_msg;
584 var GsmRrMessage rr_msg;
585 var uint32_t fn;
586 timer T;
587
588 /* FIXME: ask the BTS component to give us the current TDMA fn */
589 fn := 1337 + ta;
590
591 /* Send RACH.ind */
592 log("Sending RACH.ind on fn=", fn, " with RA=", ra, ", TA=", ta);
Vadim Yanitskiy36558d92019-11-17 02:23:51 +0700593 BTS.send(ts_PCUIF_RACH_IND(bts_nr := bts_nr, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy3e1d3182019-09-11 16:53:45 +0200594 ra := ra, is_11bit := is_11bit,
595 burst_type := burst_type,
596 fn := fn, arfcn := 871,
597 qta := ta * 4));
598
599 /* Expect Immediate (TBF) Assignment on TS0/AGCH */
600 T.start(2.0);
601 alt {
Vadim Yanitskiy36558d92019-11-17 02:23:51 +0700602 [] BTS.receive(tr_PCUIF_DATA_REQ(bts_nr := bts_nr, trx_nr := 0, ts_nr := 0,
Vadim Yanitskiy3e1d3182019-09-11 16:53:45 +0200603 sapi := PCU_IF_SAPI_AGCH, data := ?))
604 -> value pcu_msg {
605 rr_imm_ass := dec_GsmRrMessage(pcu_msg.u.data_req.data);
606 log("Rx Immediate Assignment: ", rr_imm_ass);
607
608 /* Make sure this assignment is for us
609 * TODO: Uplink or Downlink TBF? */
610 if (match(rr_imm_ass, tr_IMM_TBF_ASS(?, ra, fn))) {
611 setverdict(pass);
612 return true;
613 }
614
615 /* Not for us? Wait for more. */
616 repeat;
617 }
618 [] BTS.receive { repeat; }
619 [] T.timeout {
620 setverdict(fail, "Timeout waiting for Immediate Assignment");
621 }
622 }
623
624 return false;
625}
626
Pau Espin Pedrol6c1b4be2019-10-04 19:31:02 +0200627private function f_imm_ass_verify_ul_tbf_ass(GsmRrMessage rr_imm_ass, out PacketUlAssign ul_tbf_ass)
628runs on RAW_PCU_Test_CT return boolean {
629
630 /* Make sure we received an UL TBF Assignment */
631 if (match(rr_imm_ass, tr_IMM_TBF_ASS(dl := false, rest := tr_IaRestOctets_ULAss(?)))) {
632 ul_tbf_ass := rr_imm_ass.payload.imm_ass.rest_octets.hh.pa.uldl.ass.ul;
633 log("Rx Uplink TBF assignment: ", ul_tbf_ass);
634 setverdict(pass);
635 } else {
636 setverdict(fail, "Failed to match UL TBF Assignment");
637 return false;
638 }
639
640 /* Make sure we have got a TBF with Dynamic Block Allocation */
641 if (ul_tbf_ass.dynamic == omit) {
642 setverdict(fail, "Single Block Allocation is not handled by ", testcasename());
643 return false;
644 }
645
646 return true;
647}
648
Pau Espin Pedrol1755fab2019-10-08 11:18:54 +0200649private function f_imm_ass_verify_dl_tbf_ass(GsmRrMessage rr_imm_ass, out PacketDlAssign dl_tbf_ass)
650runs on RAW_PCU_Test_CT return boolean {
651
652 /* Make sure we received a DL TBF Assignment */
653 if (match(rr_imm_ass, tr_IMM_TBF_ASS(dl := true, rest := tr_IaRestOctets_DLAss(?)))) {
654 dl_tbf_ass := rr_imm_ass.payload.imm_ass.rest_octets.hh.pa.uldl.ass.dl;
655 log("Rx Downlink TBF assignment: ", dl_tbf_ass);
656 setverdict(pass);
657 } else {
658 setverdict(fail, "Failed to match DL TBF Assignment");
659 return false;
660 }
661
662 return true;
663}
664
Pau Espin Pedrolc3a77322019-10-03 19:40:08 +0200665/* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */
666private function f_pcuif_tx_data_ind(octetstring data, int16_t lqual_cb := 0)
667runs on RAW_PCU_Test_CT {
668
669 BTS.send(ts_PCUIF_DATA_IND(bts_nr := 0, trx_nr := 0, ts_nr := 7, block_nr := 0,
670 sapi := PCU_IF_SAPI_PDTCH, data := data,
671 fn := 0, arfcn := 871, lqual_cb := lqual_cb));
672 BTS.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_SENT));
673}
674
675/* Enqueue RTS.req, expect DATA.req with UL ACK from the PCU */
676private function f_pcuif_rx_data_req(out PCUIF_Message pcu_msg)
677runs on RAW_PCU_Test_CT {
678 BTS.send(ts_PCUIF_RTS_REQ(bts_nr := 0, trx_nr := 0, ts_nr := 7,
679 sapi := PCU_IF_SAPI_PDTCH, fn := 0,
680 arfcn := 871, block_nr := 0));
681 BTS.receive(tr_PCUIF_DATA_REQ(bts_nr := 0, trx_nr := 0, ts_nr := 7,
682 sapi := PCU_IF_SAPI_PDTCH)) -> value pcu_msg;
683}
684
Pau Espin Pedrol1755fab2019-10-08 11:18:54 +0200685/* Expect an Immediate Assignment (paging) from PCU on PCUIF on specified sapi. */
686private function f_pcuif_rx_pch_imm_tbf_ass(out GsmRrMessage rr_imm_ass)
687runs on RAW_PCU_Test_CT {
688 var PCUIF_Message pcu_msg;
689 var octetstring macblock;
690 BTS.receive(tr_PCUIF_DATA_REQ(bts_nr := 0, trx_nr := 0, ts_nr := 0,
691 sapi := PCU_IF_SAPI_PCH)) -> value pcu_msg;
692 /* First 3 bytes contain paging group: */
693 macblock := substr(pcu_msg.u.data_req.data, 3, pcu_msg.u.data_req.len - 3);
694 rr_imm_ass := dec_GsmRrMessage(macblock);
695 if (not match(rr_imm_ass, tr_IMM_TBF_ASS())) {
696 setverdict(fail, "Failed to match Immediate Assignment: ", rr_imm_ass);
697 mtc.stop;
698 }
699 BTS.send(ts_PCUIF_DATA_CNF(bts_nr := 0, trx_nr := 0, ts_nr := 0, block_nr := 0,
700 fn := 0, arfcn := 871, sapi := PCU_IF_SAPI_PCH, data := macblock));
701}
702
Pau Espin Pedrolc3a77322019-10-03 19:40:08 +0200703private function f_tx_rlcmac_ul_block(template (value) RlcmacUlBlock ul_data, int16_t lqual_cb := 0)
704runs on RAW_PCU_Test_CT {
705 var octetstring data;
706 /* Encode the payload of DATA.ind */
707 data := enc_RlcmacUlBlock(valueof(ul_data));
708 data := f_pad_oct(data, 23, '00'O); /* CS-1 */
709
710 /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */
711 f_pcuif_tx_data_ind(data, lqual_cb);
712}
713
Pau Espin Pedrol596faa42019-10-04 19:31:29 +0200714private function f_tx_rlcmac_ul_n_blocks(PacketUlAssign ul_tbf_ass, integer num_blocks := 1)
715runs on RAW_PCU_Test_CT {
716 var template (value) RlcmacUlBlock ul_data := t_RLCMAC_UL_DATA(
717 tfi := ul_tbf_ass.dynamic.tfi_assignment,
718 cv := num_blocks - 1, /* num UL blocks to be sent (to be overridden in loop) */
719 bsn := 0, /* TODO: what should be here? */
720 blocks := { /* To be generated in loop */ });
721
722 /* HACK: patch missing TLLI; otherwise OsmoPCU rejects DATA.req */
723 ul_data.data.tlli := '00000001'O;
724
725 for (var integer i := 0; i < num_blocks; i := i + 1) {
726 /* Prepare a new UL block (CV, random payload) */
727 ul_data.data.mac_hdr.countdown := (num_blocks - i - 1);
728 ul_data.data.blocks := { valueof(t_RLCMAC_LLCBLOCK(f_rnd_octstring(10))) };
729 f_tx_rlcmac_ul_block(ul_data);
730 }
731}
732
Pau Espin Pedrolc3a77322019-10-03 19:40:08 +0200733private function f_rx_rlcmac_dl_block(out RlcmacDlBlock dl_block)
734runs on RAW_PCU_Test_CT {
735 var PCUIF_Message pcu_msg;
736 f_pcuif_rx_data_req(pcu_msg);
737 dl_block := dec_RlcmacDlBlock(pcu_msg.u.data_req.data);
738}
739
740private function f_rx_rlcmac_dl_block_exp_ack_nack(out RlcmacDlBlock dl_block)
741runs on RAW_PCU_Test_CT {
742 f_rx_rlcmac_dl_block(dl_block);
Pau Espin Pedrol21659632019-12-02 19:12:08 +0100743 if (not match(dl_block, tr_RLCMAC_UL_ACK_NACK(ul_tfi := ?, tlli := ?))) {
Pau Espin Pedrolc3a77322019-10-03 19:40:08 +0200744 setverdict(fail, "Failed to match Packet Uplink ACK / NACK");
745 mtc.stop;
746 }
747}
748
Pau Espin Pedrol596faa42019-10-04 19:31:29 +0200749private function f_rx_rlcmac_dl_block_exp_dummy(out RlcmacDlBlock dl_block)
750runs on RAW_PCU_Test_CT {
751 f_rx_rlcmac_dl_block(dl_block);
752 if (not match(dl_block, tr_RLCMAC_DUMMY_CTRL())) {
753 setverdict(fail, "Failed to match Packet DUMMY DL");
754 mtc.stop;
755 }
756}
757
Pau Espin Pedrola3f0a852019-12-02 19:16:26 +0100758private function f_rx_rlcmac_dl_block_exp_data(out RlcmacDlBlock dl_block, octetstring data)
759runs on RAW_PCU_Test_CT {
760 var template RlcmacDlBlock dl_template := tr_RLCMAC_DATA_RRBP;
761 dl_template.data.blocks := ?;
762 /* TODO: match data correctly: { valueof(t_RLCMAC_LLCBLOCK(data)) }; */
763
764 f_rx_rlcmac_dl_block(dl_block);
765 if (not match(dl_block, dl_template)) {
766 setverdict(fail, "Failed to match Packet data: ", dl_block, " vs ", dl_template);
767 mtc.stop;
768 }
769}
770
Vadim Yanitskiy740ae762019-09-29 16:13:41 +0700771testcase TC_pcuif_suspend() runs on RAW_PCU_Test_CT {
772 var octetstring ra_id := enc_RoutingAreaIdentification(mp_gb_cfg.cell_id.ra_id);
773 var GprsTlli tlli := 'FFFFFFFF'O;
774 timer T;
775
776 /* Initialize NS/BSSGP side */
777 f_init_bssgp();
778
779 /* Initialize the PCU interface abstraction */
780 f_init_raw(testcasename());
781
782 /* Establish BSSGP connection to the PCU */
783 f_bssgp_establish();
784
785 BTS.send(ts_PCUIF_SUSP_REQ(0, tlli, ra_id, 0));
786
787 T.start(2.0);
788 alt {
789 [] BSSGP_SIG[0].receive(tr_BSSGP_SUSPEND(tlli, mp_gb_cfg.cell_id.ra_id)) {
790 setverdict(pass);
791 }
792 [] T.timeout {
793 setverdict(fail, "Timeout waiting for BSSGP SUSPEND");
794 }
795 }
796}
797
Vadim Yanitskiy3e1d3182019-09-11 16:53:45 +0200798/* Test of correct Timing Advance at the time of TBF establishment
799 * (derived from timing offset of the Access Burst). */
800testcase TC_ta_rach_imm_ass() runs on RAW_PCU_Test_CT {
801 var GsmRrMessage rr_msg;
802 var boolean ok;
803
804 /* Initialize the PCU interface abstraction */
805 f_init_raw(testcasename());
806
807 /* We cannot send too many TBF requests in a short time because
808 * at some point the PCU will fail to allocate a new TBF. */
809 for (var TimingAdvance ta := 0; ta < 64; ta := ta + 16) {
810 /* Establish an Uplink TBF (send RACH.ind with current TA) */
811 ok := f_establish_tbf(rr_msg, bts_nr := 0, ta := ta);
812 if (not ok) {
813 setverdict(fail, "Failed to establish an Uplink TBF");
814 mtc.stop;
815 }
816
817 /* Make sure Timing Advance IE matches out expectations */
818 if (match(rr_msg, tr_IMM_TBF_ASS(dl := false, ta := ta))) {
819 setverdict(pass);
820 }
821 }
822}
823
Vadim Yanitskiy1f72b0a2019-10-01 05:58:45 +0700824/* Verify that the PCU generates valid PTCCH/D messages
825 * while neither Uplink nor Downlink TBF is established. */
826testcase TC_ta_ptcch_idle() runs on RAW_PCU_Test_CT {
827 var PTCCHDownlinkMsg ptcch_msg;
828 var PCUIF_Message pcu_msg;
829 timer T;
830
831 /* Initialize the PCU interface abstraction */
832 f_init_raw(testcasename());
833
834 /* Sent an RTS.req for PTCCH/D */
835 BTS.send(ts_PCUIF_RTS_REQ(bts_nr := 0, trx_nr := 0, ts_nr := 7,
836 sapi := PCU_IF_SAPI_PTCCH, fn := 0,
837 arfcn := 871, block_nr := 0));
838 T.start(5.0);
839 alt {
840 [] BTS.receive(tr_PCUIF_DATA_REQ(bts_nr := 0, trx_nr := 0, ts_nr := 7,
841 sapi := PCU_IF_SAPI_PTCCH)) -> value pcu_msg {
842 log("Rx DATA.req message: ", pcu_msg);
843 setverdict(pass);
844 }
845 [] BTS.receive(PCUIF_Message:?) { repeat; }
846 [] T.timeout {
847 setverdict(fail, "Timeout waiting for a PTCCH/D block");
848 mtc.stop;
849 }
850 }
851
852 ptcch_msg := dec_PTCCHDownlinkMsg(pcu_msg.u.data_req.data);
853 log("Decoded PTCCH/D message: ", ptcch_msg);
854
855 /* Make sure the message is encoded correctly
856 * TODO: do we expect all TA values to be equal '1111111'B? */
857 if (not match(ptcch_msg, tr_PTCCHDownlinkMsg)) {
858 setverdict(fail, "Malformed PTCCH/D message");
859 mtc.stop;
860 }
861}
862
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700863/* Test of correct Timing Advance during an active Uplink TBF.
864 *
865 * Unlike the circuit-switched domain, Uplink transmissions on PDCH time-slots
866 * are not continuous and there can be long time gaps between them. This happens
867 * due to a bursty nature of packet data. The actual Timing Advance of a MS may
868 * significantly change between such rare Uplink transmissions, so GPRS introduces
869 * additional mechanisms to control Timing Advance, and thus reduce interference
870 * between neighboring TDMA time-slots.
871 *
872 * At the moment of Uplink TBF establishment, initial Timing Advance is measured
873 * from ToA (Timing of Arrival) of an Access Burst. This is covered by another
874 * test case - TC_ta_rach_imm_ass. In response to that Access Burst the network
875 * sends Immediate Assignment on AGCH, which _may_ contain Timing Advance Index
876 * among with the initial Timing Advance value. And here PTCCH comes to play.
877 *
878 * PTCCH is a unidirectional channel on which the network can instruct a sub-set
879 * of 16 MS (whether TBFs are active or not) to adjust their Timing Advance
880 * continuously. To ensure continuous measurements of the signal propagation
881 * delay, the MSs shall transmit Access Bursts on Uplink (PTCCH/U) on sub-slots
882 * defined by an assigned Timing Advance Index (see 3GPP TS 45.002).
883 *
884 * The purpose of this test case is to verify the assignment of Timing Advance
885 * Index, and the process of Timing Advance notification on PTCCH/D. The MTC
886 * first establishes several Uplink TBFs, but does not transmit any Uplink
887 * blocks on them. During 4 TDMA multi-frame periods the MTC is sending RACH
888 * indications to the PCU, checking the correctness of two received PTCCH/D
889 * messages (period of PTCCH/D is two multi-frames).
890 */
Vadim Yanitskiy20f87002019-10-06 00:51:50 +0700891
892/* List of ToA values for Access Bursts to be sent on PTCCH/U,
893 * each ToA (Timing of Arrival) value is in units of 1/4 of
894 * a symbol (i.e. 1 symbol is 4 QTA units). */
895type record length(16) of int16_t PTCCH_TAI_ToA_MAP;
896const PTCCH_TAI_ToA_MAP ptcch_toa_map_def := {
897 0, 0, 0, 0,
898 0, 0, 0, 0,
899 0, 0, 0, 0,
900 0, 0, 0, 0
901};
902
Vadim Yanitskiy36558d92019-11-17 02:23:51 +0700903private altstep as_ta_ptcch(uint8_t bts_nr := 0, uint8_t trx_nr := 0, uint8_t ts_nr := 7,
Vadim Yanitskiy20f87002019-10-06 00:51:50 +0700904 in PTCCH_TAI_ToA_MAP toa_map := ptcch_toa_map_def)
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700905runs on RAW_PCU_Test_CT {
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700906 var RAW_PCU_Event event;
Vadim Yanitskiy20f87002019-10-06 00:51:50 +0700907 var integer ss;
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700908
909 /* Send Access Bursts on PTCCH/U for every TA Index */
910 [] BTS.receive(tr_RAW_PCU_EV(TDMA_EV_PTCCH_UL_BURST)) -> value event {
Vadim Yanitskiy20f87002019-10-06 00:51:50 +0700911 ss := f_tdma_ptcch_fn2ss(event.data.tdma_fn);
912 if (ss < 0) { mtc.stop; } /* Shall not happen */
913
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700914 log("Sending an Access Burst on PTCCH/U",
Vadim Yanitskiy20f87002019-10-06 00:51:50 +0700915 ", sub-slot=", ss, " (TAI)",
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700916 ", fn=", event.data.tdma_fn,
Vadim Yanitskiy20f87002019-10-06 00:51:50 +0700917 ", ToA=", toa_map[ss], " (QTA)");
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700918 /* TODO: do we care about RA and burst format? */
Vadim Yanitskiy36558d92019-11-17 02:23:51 +0700919 BTS.send(ts_PCUIF_RACH_IND(bts_nr, trx_nr, ts_nr,
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700920 ra := oct2int('3A'O),
921 is_11bit := 0,
922 burst_type := BURST_TYPE_0,
923 fn := event.data.tdma_fn,
924 arfcn := 871,
Vadim Yanitskiy20f87002019-10-06 00:51:50 +0700925 qta := toa_map[ss],
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700926 sapi := PCU_IF_SAPI_PTCCH));
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700927 repeat;
928 }
929}
930
Vadim Yanitskiy20f87002019-10-06 00:51:50 +0700931private function f_TC_ta_ptcch_ul_multi_tbf(in PTCCH_TAI_ToA_MAP ptcch_toa_map,
932 template PTCCHDownlinkMsg t_ta_msg)
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700933runs on RAW_PCU_Test_CT {
934 var PTCCHDownlinkMsg ta_msg;
935 var PCUIF_Message pcu_msg;
936 timer T;
937
938 /* First, send an RTS.req for the upcoming PTCCH/D block */
939 BTS.send(ts_PCUIF_RTS_REQ(bts_nr := 0, trx_nr := 0, ts_nr := 7,
940 sapi := PCU_IF_SAPI_PTCCH, fn := 0,
941 arfcn := 871, block_nr := 0));
942 T.start(2.0);
943 alt {
944 /* Keep sending of Access Bursts during two multi-frames (period of PTCCH/D)
945 * with increasing ToA (Timing of Arrival) values: 0, 7, 14, 28, 35... */
Vadim Yanitskiy36558d92019-11-17 02:23:51 +0700946 [] as_ta_ptcch(bts_nr := 0, trx_nr := 0, ts_nr := 7, toa_map := ptcch_toa_map);
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700947 /* In the end of 2nd multi-frame we should receive a PTCCH/D block */
948 [] BTS.receive(tr_PCUIF_DATA_REQ(bts_nr := 0, trx_nr := 0, ts_nr := 7,
949 sapi := PCU_IF_SAPI_PTCCH)) -> value pcu_msg {
950 ta_msg := dec_PTCCHDownlinkMsg(pcu_msg.u.data_req.data);
951 log("Rx PTCCH/D message: ", ta_msg);
952
953 /* Make sure Timing Advance values match our expectations */
954 if (match(ta_msg, t_ta_msg)) {
955 setverdict(pass);
956 } else {
957 setverdict(fail, "PTCCH/D message does not match: ", t_ta_msg);
958 }
959 }
960 [] BTS.receive { repeat; }
961 [] T.timeout {
962 setverdict(fail, "Timeout waiting for a PTCCH/D block");
963 mtc.stop;
964 }
965 }
966}
967
968testcase TC_ta_ptcch_ul_multi_tbf() runs on RAW_PCU_Test_CT {
969 var template PacketUlAssign t_ul_tbf_ass;
970 var PacketUlAssign ul_tbf_ass[7];
971 var GsmRrMessage rr_msg[7];
972 var boolean ok;
973
974 /* Initialize the PCU interface abstraction */
975 f_init_raw(testcasename());
976
977 /* Enable forwarding of PTCCH/U TDMA events to us */
978 BTS.send(ts_RAW_PCU_CMD(TDMA_CMD_ENABLE_PTCCH_UL_FWD));
979
980 /* Establish 7 Uplink TBFs (USF flag is 3 bits long, '111'B is reserved) */
981 for (var integer i := 0; i < 7; i := i + 1) {
982 ok := f_establish_tbf(rr_msg[i], ta := 0);
983 if (not ok) {
984 setverdict(fail, "Failed to establish an Uplink TBF #", i);
985 mtc.stop;
986 }
987
988 /* Make sure we received an UL TBF Assignment */
989 if (match(rr_msg[i], tr_IMM_TBF_ASS(dl := false, rest := tr_IaRestOctets_ULAss(?)))) {
990 ul_tbf_ass[i] := rr_msg[i].payload.imm_ass.rest_octets.hh.pa.uldl.ass.ul;
991 log("Rx Uplink TBF assignment for #", i, ": ", ul_tbf_ass[i]);
992 } else {
993 setverdict(fail, "Failed to match UL TBF Assignment for #", i);
994 mtc.stop;
995 }
996
997 /* We expect incremental TFI/USF assignment (dynamic allocation) */
998 t_ul_tbf_ass := tr_PacketUlDynAssign(tfi := i, usf := i);
999 if (not match(ul_tbf_ass[i], t_ul_tbf_ass)) {
1000 setverdict(fail, "Failed to match Packet Uplink Assignment for #", i);
1001 mtc.stop;
1002 }
1003
1004 /* We also expect Timing Advance Index to be a part of the assignment */
1005 if (ul_tbf_ass[i].dynamic.ta_index != i) {
1006 setverdict(fail, "Failed to match Timing Advance Index for #", i);
1007 /* Keep going, the current OsmoPCU does not assign TA Index */
1008 }
1009 }
1010
Vadim Yanitskiy20f87002019-10-06 00:51:50 +07001011 /* Prepare a list of ToA values for Access Bursts to be sent on PTCCH/U */
1012 var PTCCH_TAI_ToA_MAP toa_map := ptcch_toa_map_def;
1013 for (var integer i := 0; i < 7; i := i + 1) {
1014 /* ToA in units of 1/4 of a symbol */
1015 toa_map[i] := (i + 1) * 7 * 4;
1016 }
1017
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +07001018 /* Now we have all 7 TBFs established in one-phase access mode,
1019 * however we will not be sending any data on them. Instead, we
1020 * will be sending RACH.ind on PTCCH/U during 4 multi-frame
1021 * periods (TAI 0..8), and then will check two PTCCH/D blocks.
1022 *
1023 * Why not 4 TBFs at once? Because Uplink is delayed by 3 TDMA
1024 * time-slots, so at the moment of scheduling a PTCCH/D block
1025 * the PCU has odd number of PTCCH/U Access Bursts received. */
Vadim Yanitskiy20f87002019-10-06 00:51:50 +07001026 f_TC_ta_ptcch_ul_multi_tbf(toa_map, tr_PTCCHDownlinkMsg(
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +07001027 tai0_ta := 7, tai1_ta := 14, tai2_ta := 21,
1028 /* Other values are not known (yet) */
1029 tai3_ta := ?));
Vadim Yanitskiy20f87002019-10-06 00:51:50 +07001030 f_TC_ta_ptcch_ul_multi_tbf(toa_map, tr_PTCCHDownlinkMsg(
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +07001031 tai0_ta := 7, tai1_ta := 14, tai2_ta := 21,
1032 tai3_ta := 28, tai4_ta := 35, tai5_ta := 42,
Vadim Yanitskiy20f87002019-10-06 00:51:50 +07001033 /* Other values are out of our interest */
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +07001034 tai6_ta := ?));
1035}
1036
Vadim Yanitskiy26cd2442019-11-08 05:39:06 +07001037/* Default link quality adaptation (Coding Scheme) ranges (inclusive).
1038 * OsmoPCU (VTY): cs link-quality-ranges cs1 6 cs2 5 8 cs3 7 13 cs4 12
1039 *
1040 * NOTE: the ranges are intentionally overlapping because OsmoPCU
1041 * does not change CS/MCS on the range borders (5-6, 7-8, 12-13). */
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001042private template integer CS1_lqual_dB_range := (-infinity .. 6);
1043private template integer CS2_lqual_dB_range := (5 .. 8);
1044private template integer CS3_lqual_dB_range := (7 .. 13);
1045private template integer CS4_lqual_dB_range := (12 .. infinity);
1046
1047testcase TC_cs_lqual_ul_tbf() runs on RAW_PCU_Test_CT {
Pau Espin Pedrol6c1b4be2019-10-04 19:31:02 +02001048 var GsmRrMessage rr_imm_ass;
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001049 var PacketUlAssign ul_tbf_ass;
1050 var RlcmacDlBlock dl_block;
1051 var PCUIF_Message pcu_msg;
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001052 var octetstring data;
1053 var boolean ok;
1054
1055 /* Initialize the PCU interface abstraction */
1056 f_init_raw(testcasename());
1057
Pau Espin Pedrol2a45a502019-11-29 12:48:16 +01001058 f_pcuvty_set_allowed_cs_mcs();
1059 f_pcuvty_set_link_quality_ranges();
1060
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001061 /* Establish an Uplink TBF */
Pau Espin Pedrol6c1b4be2019-10-04 19:31:02 +02001062 ok := f_establish_tbf(rr_imm_ass);
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001063 if (not ok) {
Pau Espin Pedrol6c1b4be2019-10-04 19:31:02 +02001064 setverdict(fail, "Failed to establish TBF");
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001065 mtc.stop;
1066 }
1067
Pau Espin Pedrol6c1b4be2019-10-04 19:31:02 +02001068 ok := f_imm_ass_verify_ul_tbf_ass(rr_imm_ass, ul_tbf_ass);
1069 if (not ok) {
1070 setverdict(fail, "Immediate Assignment not an Uplink TBF");
Vadim Yanitskiy6276b6c2019-09-29 19:48:26 +07001071 mtc.stop;
1072 }
1073
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001074 var template (value) RlcmacUlBlock ul_data := t_RLCMAC_UL_DATA(
1075 tfi := ul_tbf_ass.dynamic.tfi_assignment,
Pau Espin Pedrol3eef95c2019-11-29 14:07:24 +01001076 cv := 15, /* 16 UL blocks to be sent (to be overridden in loop) */
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001077 bsn := 0, /* TODO: what should be here? */
1078 blocks := { /* To be generated in loop */ });
1079
1080 /* HACK: patch missing TLLI; otherwise OsmoPCU rejects DATA.req */
1081 ul_data.data.tlli := '00000001'O;
1082
Vadim Yanitskiy26cd2442019-11-08 05:39:06 +07001083 /* The actual / old link quality values. We need to keep track of the old
1084 * (basically previous) link quality value, because OsmoPCU actually
1085 * changes the coding scheme if not only the actual, but also the old
1086 * value leaves the current link quality range (window). */
1087 var integer lqual := 0;
1088 var integer lqual_old;
1089
1090 /* 16 UL blocks (0 .. 15 dB, step = 1 dB) */
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001091 for (var integer i := 0; i < 16; i := i + 1) {
1092 /* Prepare a new UL block (CV, random payload) */
1093 ul_data.data.mac_hdr.countdown := (15 - i);
1094 ul_data.data.blocks := { valueof(t_RLCMAC_LLCBLOCK(f_rnd_octstring(10))) };
1095
Vadim Yanitskiy26cd2442019-11-08 05:39:06 +07001096 /* Update the old / actual link quality */
1097 lqual_old := lqual;
1098 lqual := i;
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001099
1100 /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */
1101 log("Sending DATA.ind with link quality (dB): ", lqual);
Pau Espin Pedrolc3a77322019-10-03 19:40:08 +02001102 f_tx_rlcmac_ul_block(ul_data, lqual * 10);
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001103
1104 /* Enqueue RTS.req, expect DATA.req with UL ACK from the PCU */
Pau Espin Pedrolc3a77322019-10-03 19:40:08 +02001105 f_rx_rlcmac_dl_block_exp_ack_nack(dl_block);
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001106
1107 log("Rx Packet Uplink ACK / NACK with Channel Coding Command: ",
1108 dl_block.ctrl.payload.u.ul_ack_nack.gprs.ch_coding_cmd);
1109
Vadim Yanitskiy26cd2442019-11-08 05:39:06 +07001110 /* Match the received Channel Coding Command. Since we are increasing
1111 * the link quality value on each iteration and not decreasing, there
1112 * is no need to check the both old and current link quality values. */
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001113 var template ChCodingCommand ch_coding;
Vadim Yanitskiy26cd2442019-11-08 05:39:06 +07001114 select (lqual_old) {
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001115 case (CS1_lqual_dB_range) { ch_coding := CH_CODING_CS1; }
1116 case (CS2_lqual_dB_range) { ch_coding := CH_CODING_CS2; }
1117 case (CS3_lqual_dB_range) { ch_coding := CH_CODING_CS3; }
1118 case (CS4_lqual_dB_range) { ch_coding := CH_CODING_CS4; }
1119 }
1120
1121 if (not match(dl_block.ctrl.payload.u.ul_ack_nack.gprs.ch_coding_cmd, ch_coding)) {
1122 setverdict(fail, "Channel Coding does not match our expectations: ", ch_coding);
1123 } else {
1124 setverdict(pass);
1125 }
1126 }
1127}
1128
Pau Espin Pedrol3eef95c2019-11-29 14:07:24 +01001129/* Test the max UL CS set by VTY works fine */
1130testcase TC_cs_initial_ul() runs on RAW_PCU_Test_CT {
1131 var GsmRrMessage rr_imm_ass;
1132 var PacketUlAssign ul_tbf_ass;
1133 var RlcmacDlBlock dl_block;
1134 var boolean ok;
1135 var integer lqual_cb;
1136 var ChCodingCommand last_ch_coding;
1137
1138 /* Initialize the PCU interface abstraction */
1139 f_init_raw(testcasename());
1140
1141 /* Set initial UL CS to 3 */
1142 g_cs_initial_ul := 3;
1143 f_pcuvty_set_allowed_cs_mcs();
1144 f_pcuvty_set_link_quality_ranges();
1145
1146 /* Take lqual (dB->cB) so that we stay in that CS */
1147 lqual_cb := g_cs_lqual_ranges[2].low * 10;
1148
1149 /* Establish an Uplink TBF */
1150 ok := f_establish_tbf(rr_imm_ass);
1151 if (not ok) {
1152 setverdict(fail, "Failed to establish TBF");
1153 mtc.stop;
1154 }
1155
1156 ok := f_imm_ass_verify_ul_tbf_ass(rr_imm_ass, ul_tbf_ass);
1157 if (not ok) {
1158 setverdict(fail, "Immediate Assignment not an Uplink TBF");
1159 mtc.stop;
1160 }
1161
1162 var template (value) RlcmacUlBlock ul_data := t_RLCMAC_UL_DATA(
1163 tfi := ul_tbf_ass.dynamic.tfi_assignment,
1164 cv := 3, /* 8 UL blocks to be sent (to be overridden in loop) */
1165 bsn := 0, /* TODO: what should be here? */
1166 blocks := { /* To be generated in loop */ });
1167
1168 /* HACK: patch missing TLLI; otherwise OsmoPCU rejects DATA.req */
1169 ul_data.data.tlli := '00000001'O;
1170
1171 /* 3 UL blocks, check we are in same initial CS: */
1172 for (var integer i := 0; i < 3; i := i + 1) {
1173 /* Prepare a new UL block (CV, random payload) */
1174 ul_data.data.mac_hdr.countdown := (7 - i);
1175 ul_data.data.blocks := { valueof(t_RLCMAC_LLCBLOCK(f_rnd_octstring(10))) };
1176
1177 /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */
1178 f_tx_rlcmac_ul_block(ul_data, lqual_cb);
1179
1180 /* Enqueue RTS.req, expect DATA.req with UL ACK from the PCU */
1181 f_rx_rlcmac_dl_block_exp_ack_nack(dl_block);
1182 last_ch_coding := dl_block.ctrl.payload.u.ul_ack_nack.gprs.ch_coding_cmd;
1183 }
1184
1185 if (last_ch_coding != CH_CODING_CS3) {
1186 setverdict(fail, "Channel Coding does not match our expectations (CS-3): ", last_ch_coding);
1187 mtc.stop;
1188 }
1189
1190 setverdict(pass);
1191
1192 /* Remaining UL blocks are used to make sure regardless of initial
1193 /* lqual, we can go lower at any time */
1194
1195 /* 5 UL blocks, check we are in same initial CS: */
1196 for (var integer i := 3; i < 8; i := i + 1) {
1197 /* Prepare a new UL block (CV, random payload) */
1198 ul_data.data.mac_hdr.countdown := (7 - i);
1199 ul_data.data.blocks := { valueof(t_RLCMAC_LLCBLOCK(f_rnd_octstring(10))) };
1200
1201 /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */
1202 f_tx_rlcmac_ul_block(ul_data, 0); /* 0 dB, make sure we downgrade CS */
1203
1204 /* Enqueue RTS.req, expect DATA.req with UL ACK from the PCU */
1205 f_rx_rlcmac_dl_block_exp_ack_nack(dl_block);
1206
1207 last_ch_coding := dl_block.ctrl.payload.u.ul_ack_nack.gprs.ch_coding_cmd;
1208 }
1209
1210 if (last_ch_coding != CH_CODING_CS1) {
1211 setverdict(fail, "Channel Coding does not match our expectations (CS-1): ", last_ch_coding);
1212 } else {
1213 setverdict(pass);
1214 }
1215}
1216
1217/* Test the max UL CS set by VTY works fine */
1218testcase TC_cs_max_ul() runs on RAW_PCU_Test_CT {
1219 var GsmRrMessage rr_imm_ass;
1220 var PacketUlAssign ul_tbf_ass;
1221 var RlcmacDlBlock dl_block;
1222 var boolean ok;
1223 var ChCodingCommand last_ch_coding;
1224
1225 /* Initialize the PCU interface abstraction */
1226 f_init_raw(testcasename());
1227
1228 /* Set maximum allowed UL CS to 3 */
1229 g_cs_max_ul := 3;
1230 f_pcuvty_set_allowed_cs_mcs();
1231 f_pcuvty_set_link_quality_ranges();
1232
1233 /* Establish an Uplink TBF */
1234 ok := f_establish_tbf(rr_imm_ass);
1235 if (not ok) {
1236 setverdict(fail, "Failed to establish TBF");
1237 mtc.stop;
1238 }
1239
1240 ok := f_imm_ass_verify_ul_tbf_ass(rr_imm_ass, ul_tbf_ass);
1241 if (not ok) {
1242 setverdict(fail, "Immediate Assignment not an Uplink TBF");
1243 mtc.stop;
1244 }
1245
1246 var template (value) RlcmacUlBlock ul_data := t_RLCMAC_UL_DATA(
1247 tfi := ul_tbf_ass.dynamic.tfi_assignment,
1248 cv := 15, /* 16 UL blocks to be sent (to be overridden in loop) */
1249 bsn := 0, /* TODO: what should be here? */
1250 blocks := { /* To be generated in loop */ });
1251
1252 /* HACK: patch missing TLLI; otherwise OsmoPCU rejects DATA.req */
1253 ul_data.data.tlli := '00000001'O;
1254
1255 /* 16 UL blocks */
1256 for (var integer i := 0; i < 16; i := i + 1) {
1257 /* Prepare a new UL block (CV, random payload) */
1258 ul_data.data.mac_hdr.countdown := (15 - i);
1259 ul_data.data.blocks := { valueof(t_RLCMAC_LLCBLOCK(f_rnd_octstring(10))) };
1260
1261 /* Enqueue DATA.ind (both TDMA frame and block numbers to be patched) */
1262 f_tx_rlcmac_ul_block(ul_data, 40*10); /* 40 dB */
1263
1264 /* Enqueue RTS.req, expect DATA.req with UL ACK from the PCU */
1265 f_rx_rlcmac_dl_block_exp_ack_nack(dl_block);
1266
1267 last_ch_coding := dl_block.ctrl.payload.u.ul_ack_nack.gprs.ch_coding_cmd;
1268 }
1269
1270 if (last_ch_coding != CH_CODING_CS3) {
1271 setverdict(fail, "Channel Coding does not match our expectations (CS-3): ", last_ch_coding);
1272 } else {
1273 setverdict(pass);
1274 }
1275}
1276
Pau Espin Pedrol596faa42019-10-04 19:31:29 +02001277/* Verify PCU drops TBF after some time of inactivity. */
1278testcase TC_t3169() runs on RAW_PCU_Test_CT {
1279 var PCUIF_info_ind info_ind;
1280 var GsmRrMessage rr_imm_ass;
1281 var PacketUlAssign ul_tbf_ass;
1282 var RlcmacDlBlock dl_block;
1283 var PCUIF_Message pcu_msg;
1284 var octetstring data;
1285 var boolean ok;
Pau Espin Pedrolcf47a922019-10-07 15:26:52 +02001286 var OCT4 tlli := '00000001'O;
1287
1288 /* Initialize NS/BSSGP side */
1289 f_init_bssgp();
Pau Espin Pedrol596faa42019-10-04 19:31:29 +02001290
1291 info_ind := valueof(ts_PCUIF_INFO_default);
1292 /* Set timer to 1 sec (default 5) to speedup test: */
1293 info_ind.t3169 := 1;
1294
1295 /* Initialize the PCU interface abstraction */
1296 f_init_raw(testcasename(), info_ind);
1297
Pau Espin Pedrolcf47a922019-10-07 15:26:52 +02001298 /* Establish BSSGP connection to the PCU */
1299 f_bssgp_establish();
1300 f_bssgp_client_llgmm_assign('FFFFFFFF'O, tlli);
1301
Pau Espin Pedrol596faa42019-10-04 19:31:29 +02001302 /* Establish an Uplink TBF */
1303 ok := f_establish_tbf(rr_imm_ass);
1304 if (not ok) {
1305 setverdict(fail, "Failed to establish TBF");
1306 mtc.stop;
1307 }
1308
1309 ok := f_imm_ass_verify_ul_tbf_ass(rr_imm_ass, ul_tbf_ass);
1310 if (not ok) {
1311 setverdict(fail, "Immediate Assignment not an Uplink TBF");
1312 mtc.stop;
1313 }
1314
1315 /* Send one UL block and make sure it is ACKED fine */
1316 f_tx_rlcmac_ul_n_blocks(ul_tbf_ass, 1);
1317 f_rx_rlcmac_dl_block_exp_ack_nack(dl_block);
Pau Espin Pedrolcf47a922019-10-07 15:26:52 +02001318 /* UL block should be received in SGSN */
1319 BSSGP[0].receive(tr_BSSGP_UL_UD(tlli, mp_gb_cfg.cell_id));
Pau Espin Pedrol596faa42019-10-04 19:31:29 +02001320
1321 /* Wait until T3169 fires (plus 1 extra sec to make sure) */
1322 f_sleep(int2float(info_ind.t3169) + 1.0);
1323
1324 /* Send an UL block once again, the TBF should be gone by now so no ACK */
1325 f_tx_rlcmac_ul_n_blocks(ul_tbf_ass, 1);
1326 f_rx_rlcmac_dl_block_exp_dummy(dl_block);
1327}
1328
Pau Espin Pedrol1755fab2019-10-08 11:18:54 +02001329/* Test scenario where MS wants to send some data on PDCH against SGSN and it is
1330 * answered, so TBFs for uplink and later for downlink are created.
1331 */
1332testcase TC_mo_ping_pong() runs on RAW_PCU_Test_CT {
1333 var GsmRrMessage rr_imm_ass;
1334 var PacketUlAssign ul_tbf_ass;
1335 var PacketDlAssign dl_tbf_ass;
1336 var RlcmacDlBlock dl_block;
1337 var PCUIF_Message pcu_msg;
Pau Espin Pedrola3f0a852019-12-02 19:16:26 +01001338 var octetstring data := f_rnd_octstring(10);
Pau Espin Pedrol1755fab2019-10-08 11:18:54 +02001339 var boolean ok;
1340 var OCT4 tlli := '00000001'O;
Pau Espin Pedrola3f0a852019-12-02 19:16:26 +01001341 var AckNackDescription ack_nack_desc;
1342
1343 ack_nack_desc.final_ack := '0'B;
1344 ack_nack_desc.starting_seq_nr := 0;
1345 ack_nack_desc.receive_block_bitmap := '0000000000000000000000000000000000000000000000000000000000000000'B;
1346
Pau Espin Pedrol1755fab2019-10-08 11:18:54 +02001347
1348 /* Initialize NS/BSSGP side */
1349 f_init_bssgp();
1350
1351 /* Initialize the PCU interface abstraction */
1352 f_init_raw(testcasename());
1353
1354 /* Establish BSSGP connection to the PCU */
1355 f_bssgp_establish();
1356 f_bssgp_client_llgmm_assign('FFFFFFFF'O, tlli);
1357
1358 /* Establish an Uplink TBF */
1359 ok := f_establish_tbf(rr_imm_ass);
1360 if (not ok) {
1361 setverdict(fail, "Failed to establish TBF");
1362 mtc.stop;
1363 }
1364 ok := f_imm_ass_verify_ul_tbf_ass(rr_imm_ass, ul_tbf_ass);
1365 if (not ok) {
1366 setverdict(fail, "Immediate Assignment not an Uplink TBF");
1367 mtc.stop;
1368 }
1369
1370 /* Send one UL block and make sure it is ACKED fine */
1371 f_tx_rlcmac_ul_n_blocks(ul_tbf_ass, 1);
1372 f_rx_rlcmac_dl_block_exp_ack_nack(dl_block);
1373
1374 /* UL block should be received in SGSN */
1375 BSSGP[0].receive(tr_BSSGP_UL_UD(tlli, mp_gb_cfg.cell_id));
1376
1377 /* Now SGSN sends some DL data, PCU will page on CCCH (PCH) */
Pau Espin Pedrola3f0a852019-12-02 19:16:26 +01001378 BSSGP[0].send(ts_BSSGP_DL_UD(tlli, data));
Pau Espin Pedrol1755fab2019-10-08 11:18:54 +02001379 f_pcuif_rx_pch_imm_tbf_ass(rr_imm_ass);
1380
1381 ok := f_imm_ass_verify_dl_tbf_ass(rr_imm_ass, dl_tbf_ass);
1382 if (not ok) {
1383 setverdict(fail, "Immediate Assignment not a Downlink TBF");
1384 mtc.stop;
1385 }
1386
Pau Espin Pedrola3f0a852019-12-02 19:16:26 +01001387 /* Wait timer X2002 and DL block is available after CCCH IMM ASS: */
1388 f_sleep(X2002);
1389 f_rx_rlcmac_dl_block_exp_data(dl_block, data);
1390
1391 /* ACK the DL block */
1392 f_tx_rlcmac_ul_block(ts_RLCMAC_DL_ACK_NACK(dl_block.data.mac_hdr.hdr_ext.tfi, ack_nack_desc));
Pau Espin Pedrol1755fab2019-10-08 11:18:54 +02001393}
Harald Welte9fbcf4b2018-12-07 07:56:52 +01001394
1395control {
1396 execute( TC_ns_reset() );
1397 execute( TC_ns_reset_retrans() );
1398 execute( TC_ns_alive() );
1399 execute( TC_ns_alive_timeout_reset() );
1400 execute( TC_ns_unblock() );
1401 execute( TC_ns_unblock_retrans() );
1402 execute( TC_ns_full_bringup() );
1403 execute( TC_ns_so_block() );
Harald Welte7fd25cf2019-03-21 22:14:02 +01001404
1405 execute( TC_pcuif_suspend() );
Vadim Yanitskiy1f72b0a2019-10-01 05:58:45 +07001406 execute( TC_ta_ptcch_idle() );
Vadim Yanitskiy3e1d3182019-09-11 16:53:45 +02001407 execute( TC_ta_rach_imm_ass() );
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +07001408 execute( TC_ta_ptcch_ul_multi_tbf() );
Vadim Yanitskiy0eb26622019-09-14 20:35:28 +02001409 execute( TC_cs_lqual_ul_tbf() );
Pau Espin Pedrol3eef95c2019-11-29 14:07:24 +01001410 execute( TC_cs_initial_ul() );
1411 execute( TC_cs_max_ul() );
Pau Espin Pedrol596faa42019-10-04 19:31:29 +02001412 execute( TC_t3169() );
Pau Espin Pedrol1755fab2019-10-08 11:18:54 +02001413 execute( TC_mo_ping_pong() );
Harald Welte9fbcf4b2018-12-07 07:56:52 +01001414}
1415
1416
1417
1418
1419
1420
1421}