blob: 030da0514cdc7f7d874e83de352fee284ae92fa8 [file] [log] [blame]
Pau Espin Pedrol8dd59fb2020-04-29 15:08:16 +02001module PCUIF_Components {
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +02002
3/*
4 * Components for (RAW) PCU test cases.
5 *
6 * (C) 2019 Vadim Yanitskiy <axilirator@gmail.com>
7 *
8 * All rights reserved.
9 *
10 * Released under the terms of GNU General Public License, Version 2 or
11 * (at your option) any later version.
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 */
15
16import from IPL4asp_Types all;
17import from UD_Types all;
18
19import from PCUIF_Types all;
20import from PCUIF_CodecPort all;
21
Pau Espin Pedrolcf5c33e2021-01-19 18:56:55 +010022import from Osmocom_Types all;
23import from RLCMAC_Types all;
24import from GSM_RR_Types all;
25
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +020026/* Component communication diagram:
27 *
28 * +-----+ +----------+ +---------+
29 * | MTC +---------------+ PCUIF_CT +------+ OsmoPCU |
30 * +--+--+ +----+-----+ +---------+
31 * | |
32 * | |
33 * | |
34 * | +-----------+ | +---------------+
35 * +----+ BTS_CT #1 +------+ | ClckGen_CT #1 |
36 * | +-----+-----+ | +-------+-------+
37 * | | | |
38 * | +---------------------------+
39 * | |
40 * | +-----------+ | +---------------+
41 * +----+ BTS_CT #2 +------+ | ClckGen_CT #2 |
42 * | +-----+-----+ | +-------+-------+
43 * | | | |
44 * | +---------------------------+
45 * | |
46 * | +-----------+ | +---------------+
47 * +----+ BTS_CT #N +------+ | ClckGen_CT #N |
48 * +-----+-----+ +-------+-------+
49 * | |
50 * +---------------------------+
51 */
52
53/* Events are used by the components to indicate that something
54 * has happened, e.g. we have got a connection from the PCU. */
55type enumerated RAW_PCU_EventType {
56 /* Events related to RAW_PCUIF_CT */
57 PCU_EV_DISCONNECT, /*!< OsmoPCU has disconnected */
58 PCU_EV_CONNECT, /*!< OsmoPCU is now connected */
59
60 /* Events related to RAW_PCU_BTS_CT */
61 BTS_EV_SI13_NEGO, /*!< SI13 negotiation complete */
62
63 /* TDMA clock related events (TDMA frame-number in parameters) */
64 TDMA_EV_PDTCH_BLOCK_BEG, /*!< 1/4 bursts of a PDTCH block on both Uplink and Downlink */
65 TDMA_EV_PDTCH_BLOCK_END, /*!< 4/4 bursts of a PDTCH block on both Uplink and Downlink */
66 TDMA_EV_PTCCH_DL_BLOCK, /*!< 4/4 bursts of a PTCCH block on Downlink */
67 TDMA_EV_PTCCH_UL_BURST, /*!< One Access Burst on PTCCH/U */
68
69 TDMA_EV_PDTCH_BLOCK_SENT /*!< A PDTCH block has been sent to the PCU */
70};
71
72/* Union of all possible parameters of the events */
73type union RAW_PCU_EventParam {
74 integer tdma_fn
75};
76
77type record RAW_PCU_Event {
78 RAW_PCU_EventType event,
79 /* TODO: can we use 'anytype' here? */
80 RAW_PCU_EventParam data optional
81};
82
83template (value) RAW_PCU_Event ts_RAW_PCU_EV(RAW_PCU_EventType event) := {
84 event := event,
85 data := omit
86}
87template RAW_PCU_Event tr_RAW_PCU_EV(template RAW_PCU_EventType event := ?,
88 template RAW_PCU_EventParam data := *) := {
89 event := event,
90 data := data
91}
92
93template (value) RAW_PCU_Event ts_RAW_PCU_CLCK_EV(RAW_PCU_EventType event, integer fn) := {
94 event := event,
95 data := { tdma_fn := fn }
96}
97template RAW_PCU_Event tr_RAW_PCU_CLCK_EV := {
98 event := (TDMA_EV_PDTCH_BLOCK_BEG, TDMA_EV_PDTCH_BLOCK_END,
99 TDMA_EV_PTCCH_DL_BLOCK, TDMA_EV_PTCCH_UL_BURST,
100 TDMA_EV_PDTCH_BLOCK_SENT),
101 data := { tdma_fn := ? }
102}
103
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700104/* Commands are mostly used by the MTC to configure the components
105 * at run-time, e.g. to enable or disable some optional features. */
106type enumerated RAW_PCU_CommandType {
Vadim Yanitskiy91f8a092020-05-06 21:41:05 +0700107 GENERAL_CMD_SHUTDOWN, /*!< Shut down component and all its child components */
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700108 TDMA_CMD_ENABLE_PTCCH_UL_FWD /*!< Enable forwarding of TDMA_EV_PTCCH_UL_BURST to the MTC */
109};
110
111type record RAW_PCU_Command {
112 RAW_PCU_CommandType cmd,
113 anytype data optional
114};
115
116template (value) RAW_PCU_Command ts_RAW_PCU_CMD(RAW_PCU_CommandType cmd) := {
117 cmd := cmd,
118 data := omit
119}
120template RAW_PCU_Command tr_RAW_PCU_CMD(template RAW_PCU_CommandType cmd := ?,
121 template anytype data := *) := {
122 cmd := cmd,
123 data := data
124}
125
Pau Espin Pedrolcf5c33e2021-01-19 18:56:55 +0100126/* PCUIF req_data containing decoded rlcmac/rr, for users to be able to match
127 * directly on receive()
128 */
129type record BTS_PDTCH_Block {
130 uint8_t bts_nr,
131 PCUIF_data raw,
Pau Espin Pedrolcf2ada52021-09-22 14:11:44 +0200132 RlcmacDlBlock dl_block optional
Pau Espin Pedrolcf5c33e2021-01-19 18:56:55 +0100133};
134type record BTS_PTCCH_Block {
135 uint8_t bts_nr,
136 PCUIF_data raw,
Pau Espin Pedrolcf2ada52021-09-22 14:11:44 +0200137 PTCCHDownlinkMsg dl_block optional
Pau Espin Pedrolcf5c33e2021-01-19 18:56:55 +0100138};
139type record BTS_CCCH_Block {
140 uint8_t bts_nr,
141 PCUIF_data raw,
142 GsmRrMessage rr_msg
143};
144template BTS_PDTCH_Block tr_PCUIF_DATA_PDTCH(template uint8_t bts_nr,
145 template PCUIF_data raw,
146 template RlcmacDlBlock dl_block := ?) := {
147 bts_nr := bts_nr,
148 raw := raw,
149 dl_block := dl_block
150};
151template BTS_PTCCH_Block tr_PCUIF_DATA_PTCCH(template uint8_t bts_nr,
152 template PCUIF_data raw,
153 template PTCCHDownlinkMsg dl_block := ?) := {
154 bts_nr := bts_nr,
155 raw := raw,
156 dl_block := dl_block
157};
158template BTS_CCCH_Block tr_PCUIF_DATA_RR(template uint8_t bts_nr,
159 template PCUIF_data raw,
160 template GsmRrMessage rr_msg := ?) := {
161 bts_nr := bts_nr,
162 raw := raw,
163 rr_msg := rr_msg
164};
165
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200166/* Generic port for messages and events */
167type port RAW_PCU_MSG_PT message {
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700168 inout RAW_PCU_Command;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200169 inout RAW_PCU_Event;
170 inout PCUIF_Message;
Pau Espin Pedrolcf5c33e2021-01-19 18:56:55 +0100171 inout BTS_PDTCH_Block;
172 inout BTS_PTCCH_Block;
173 inout BTS_CCCH_Block;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200174} with { extension "internal" };
175
176/* TDMA frame clock generator */
177type component RAW_PCU_ClckGen_CT {
178 /* One TDMA frame is 4.615 ms long */
179 timer T_TDMAClock := 4.615 / 1000.0;
180 port RAW_PCU_MSG_PT CLCK;
181 var integer fn := 0;
182}
183
Vadim Yanitskiy20f87002019-10-06 00:51:50 +0700184/* Derive PTCCH/U sub-slot from a given TDMA frame-number */
185function f_tdma_ptcch_fn2ss(integer fn) return integer
186{
187 var integer ss := -1;
188
189 /* See 3GPP TS 45.002, table 6 */
190 select (fn mod 416) {
191 case (12) { ss := 0; }
192 case (38) { ss := 1; }
193 case (64) { ss := 2; }
194 case (90) { ss := 3; }
195
196 case (116) { ss := 4; }
197 case (142) { ss := 5; }
198 case (168) { ss := 6; }
199 case (194) { ss := 7; }
200
201 case (220) { ss := 8; }
202 case (246) { ss := 9; }
203 case (272) { ss := 10; }
204 case (298) { ss := 11; }
205
206 case (324) { ss := 12; }
207 case (350) { ss := 13; }
208 case (376) { ss := 14; }
209 case (402) { ss := 15; }
210 }
211
212 return ss;
213}
214
Pau Espin Pedroled9ca972021-03-11 20:53:21 +0100215function f_ClckGen_CT_handler(integer start_fn := 0)
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200216runs on RAW_PCU_ClckGen_CT {
217 var integer fn104, fn52, fn13;
218
Pau Espin Pedroled9ca972021-03-11 20:53:21 +0100219 fn := start_fn;
220
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200221 while (true) {
222 fn104 := fn mod 104;
223 fn52 := fn mod 52;
224 fn13 := fn mod 13;
225
226 if (fn13 == 0 or fn13 == 4 or fn13 == 8) {
227 /* 1/4 bursts of a PDTCH block on both Uplink and Downlink */
228 CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_BEG, fn));
229 } else if (fn13 == 3 or fn13 == 7 or fn13 == 11) {
230 /* 4/4 bursts of a PDTCH block on both Uplink and Downlink */
231 CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_END, fn));
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200232 } else if (fn52 == 12 or fn52 == 38) {
Vadim Yanitskiyb58b7302019-10-06 01:01:48 +0700233 /* 4/4 bursts of a PTCCH (Timing Advance Control) block on Downlink */
234 if (fn104 == 90) {
235 CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PTCCH_DL_BLOCK, fn));
236 }
237 /* One Access Burst on PTCCH/U (goes 3 time-slots after PTCCH/D) */
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200238 CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PTCCH_UL_BURST, fn));
239 }
240
241 /* TDMA hyperframe period is (2048 * 51 * 26) frames */
242 fn := (fn + 1) mod (2048 * 51 * 26);
243
244 /* (Re)start TDMA clock timer and wait */
245 T_TDMAClock.start;
246 T_TDMAClock.timeout;
247 }
248}
249
250type record of PCUIF_Message PCUIF_MsgQueue;
251
252/* Enqueue a given message to the end of a given queue */
253private function f_PCUIF_MsgQueue_enqueue(inout PCUIF_MsgQueue queue,
254 in PCUIF_Message msg)
255{
256 queue := queue & { msg };
257}
258
259/* Dequeue the first message of a given queue */
260private function f_PCUIF_MsgQueue_dequeue(inout PCUIF_MsgQueue queue,
261 out PCUIF_Message msg)
262{
263 var integer len := lengthof(queue);
264
265 if (len == 0) {
266 setverdict(fail, "Failed to dequeue a message: the queue is empty!");
267 mtc.stop;
268 }
269
270 /* Store the first message */
271 msg := queue[0];
272
273 /* Remove the first message from queue */
274 if (len > 1) {
275 queue := substr(queue, 1, len - 1);
276 } else {
277 queue := { };
278 }
279}
280
Pau Espin Pedrol65bab9e2019-12-04 21:05:10 +0100281/* Get first message from queue. true if non-empty, false otherwise */
282private function f_PCUIF_MsgQueue_first(inout PCUIF_MsgQueue queue,
283 out PCUIF_Message msg) return boolean
284{
285 if (lengthof(queue) == 0) {
286 return false;
287 }
288
289 msg := queue[0];
290 return true;
291}
292
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200293/* Multiple base stations can be connected to the PCU. This component
294 * represents one BTS with an associated TDMA clock generator. */
295type component RAW_PCU_BTS_CT {
296 /* TDMA clock generator */
297 var RAW_PCU_ClckGen_CT vc_CLCK_GEN;
298 port RAW_PCU_MSG_PT CLCK;
299
300 /* Queues of PCUIF messages to be sent
301 * TODO: we may have multiple PDCH time-slots */
302 var PCUIF_MsgQueue pdtch_data_queue := { };
303 var PCUIF_MsgQueue pdtch_rts_queue := { };
304 var PCUIF_MsgQueue ptcch_rts_queue := { };
305
306 /* Connection towards the PCU interface */
307 port RAW_PCU_MSG_PT PCUIF;
308 /* Connection towards the test case */
309 port RAW_PCU_MSG_PT TC;
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700310
311 /* Whether to forward PTCCH/U burst events to the TC */
312 var boolean cfg_ptcch_burst_fwd := false;
Pau Espin Pedrol873686f2021-03-05 14:57:58 +0100313
314 var PCUIF_info_ind g_info_ind;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200315}
316
Pau Espin Pedrol65bab9e2019-12-04 21:05:10 +0100317/* Queue received messages from Test Case, they will eventually be scheduled and
318 * sent according to their FN. FN value of 0 has the special meaning of "schedule
319 * as soon as possible". */
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200320private altstep as_BTS_CT_MsgQueue(integer bts_nr)
321runs on RAW_PCU_BTS_CT {
322 var PCUIF_Message pcu_msg;
323
324 /* Enqueue DATA.ind and RTS.req messages */
325 [] TC.receive(tr_PCUIF_MSG(PCU_IF_MSG_DATA_IND, bts_nr)) -> value pcu_msg {
Pau Espin Pedrolaa457072021-04-19 18:06:16 +0200326 if (pcu_msg.u.data_ind.sapi == PCU_IF_SAPI_BCCH) {
327 PCUIF.send(pcu_msg); /* Forward directly ASAP */
328 } else {
329 f_PCUIF_MsgQueue_enqueue(pdtch_data_queue, pcu_msg);
330 }
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200331 repeat;
332 }
333 [] TC.receive(tr_PCUIF_RTS_REQ(bts_nr, sapi := PCU_IF_SAPI_PDTCH)) -> value pcu_msg {
334 f_PCUIF_MsgQueue_enqueue(pdtch_rts_queue, pcu_msg);
335 repeat;
336 }
337 [] TC.receive(tr_PCUIF_RTS_REQ(bts_nr, sapi := PCU_IF_SAPI_PTCCH)) -> value pcu_msg {
338 f_PCUIF_MsgQueue_enqueue(ptcch_rts_queue, pcu_msg);
339 repeat;
340 }
341 /* Forward other messages directly to the PCU */
342 [] TC.receive(tr_PCUIF_MSG(?, bts_nr)) -> value pcu_msg {
343 PCUIF.send(pcu_msg);
344 repeat;
345 }
346}
347
Pau Espin Pedroled9ca972021-03-11 20:53:21 +0100348/* Submit empty data on any available TS, to set up initial TDMA clock */
349private function f_tx_first_data_ind(integer bts_nr, PCUIF_info_ind info_ind, integer start_fn)
350runs on RAW_PCU_BTS_CT
351{
352 var PCUIF_Message pcu_msg;
Pau Espin Pedroled9ca972021-03-11 20:53:21 +0100353
354 /* Find an active TS: */
355 for (var uint8_t ts_nr := 0; ts_nr < 8; ts_nr := ts_nr + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +0100356 for (var integer trx_nr := 0; trx_nr < lengthof(g_info_ind.trx); trx_nr := trx_nr + 1) {
357 if (g_info_ind.trx[trx_nr].pdch_mask[ts_nr] == '0'B) {
Pau Espin Pedroled9ca972021-03-11 20:53:21 +0100358 continue; /* TRX+TS not activated */
359 }
360
361 /* Send empty DATA.ind to set up FN */
362 pcu_msg := valueof(ts_PCUIF_DATA_IND(bts_nr, trx_nr, ts_nr, 0 /* FIXME */,
363 PCU_IF_SAPI_PDTCH, ''O, start_fn,
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +0100364 g_info_ind.trx[trx_nr].arfcn,
Pau Espin Pedroled9ca972021-03-11 20:53:21 +0100365 rssi := -80, ber10k := 0,
366 ta_offs_qbits := 0, lqual_cb := 10));
367 PCUIF.send(pcu_msg);
368 return;
369 }
370 }
371}
372
Pau Espin Pedrol9fc065a2021-05-11 17:05:39 +0200373private function fn2macblock(uint32_t fn) return uint8_t
374{
375 return (fn mod 52) / 4;
376}
377
Pau Espin Pedrol873686f2021-03-05 14:57:58 +0100378/* Get first message from queue. true if non-empty, false otherwise */
379private function f_tx_data_ind_fn(integer bts_nr, integer fn)
380runs on RAW_PCU_BTS_CT
381{
382 var PCUIF_Message pcu_msg;
383 var boolean has_msg, use_msg;
Pau Espin Pedrol873686f2021-03-05 14:57:58 +0100384
385 for (var uint8_t ts_nr := 0; ts_nr < 8; ts_nr := ts_nr + 1) {
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +0100386 for (var integer trx_nr := 0; trx_nr < lengthof(g_info_ind.trx); trx_nr := trx_nr + 1) {
Pau Espin Pedrol873686f2021-03-05 14:57:58 +0100387 //var charstring prefix := "BTS=" & int2str(bts_nr) & ",TRX=" & int2str(trx_nr) & ",TS=" & int2str(ts_nr) & ",FN=" & int2str(fn) & ": ";
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +0100388 if (g_info_ind.trx[trx_nr].pdch_mask[ts_nr] == '0'B) {
Pau Espin Pedrol873686f2021-03-05 14:57:58 +0100389 //log(prefix, "disabled");
390 continue; /* TRX+TS not activated */
391 }
392
393 /* Check if we reached time to serve the first DATA.ind message in the queue: */
394 has_msg := f_PCUIF_MsgQueue_first(pdtch_data_queue, pcu_msg) and
395 pcu_msg.u.data_ind.trx_nr == trx_nr and
396 pcu_msg.u.data_ind.ts_nr == ts_nr;
397 use_msg := has_msg and (pcu_msg.u.data_ind.fn == 0 or pcu_msg.u.data_ind.fn == fn);
398 if (use_msg) {
399 /* Dequeue a DATA.ind message */
400 f_PCUIF_MsgQueue_dequeue(pdtch_data_queue, pcu_msg);
401 /* Patch TDMA frame / block number */
402 pcu_msg.u.data_ind.fn := fn;
Pau Espin Pedrol9fc065a2021-05-11 17:05:39 +0200403 pcu_msg.u.data_ind.block_nr := fn2macblock(fn);
Pau Espin Pedrol873686f2021-03-05 14:57:58 +0100404 //log(prefix, "DATA.ind");
405 } else if (has_msg and pcu_msg.u.data_ind.fn < fn) {
406 setverdict(fail, "We are late scheduling the block! ", pcu_msg.u.data_ind.fn, " < ", fn);
407 mtc.stop;
408 } else {
409 /* NOPE.ind: */
410 pcu_msg := valueof(ts_PCUIF_DATA_IND(bts_nr, trx_nr, ts_nr, 0 /* FIXME */,
411 PCU_IF_SAPI_PDTCH, ''O, fn,
Vadim Yanitskiy1da1fef2021-03-23 04:28:18 +0100412 g_info_ind.trx[trx_nr].arfcn,
Pau Espin Pedrol873686f2021-03-05 14:57:58 +0100413 rssi := -80, ber10k := 0,
414 ta_offs_qbits := 0, lqual_cb := 10));
415 //log(prefix, "DATA.ind (len=0)");
416 }
417
Pau Espin Pedrol4c23aea2021-11-16 19:14:00 +0100418 PCUIF.send(pcu_msg); /* Send to the PCU and notify the TC */
419 if (use_msg) {
420 TC.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_SENT, fn));
Pau Espin Pedrol873686f2021-03-05 14:57:58 +0100421 }
422 }
423 }
424}
425
Pau Espin Pedrol65bab9e2019-12-04 21:05:10 +0100426/* Handle schedule events and manage actions: Send msgs over PCUIF to PCU,
427 * advertise Test Case about sent messages, etc. */
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200428private altstep as_BTS_CT_TDMASched(integer bts_nr)
429runs on RAW_PCU_BTS_CT {
430 var PCUIF_Message pcu_msg;
431 var RAW_PCU_Event event;
Pau Espin Pedrol60727252019-12-04 21:40:25 +0100432 var integer ev_begin_fn;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200433
434 [] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_BEG)) -> value event {
435 /* If the RTS queue for PDTCH is not empty, send a message */
436 if (lengthof(pdtch_rts_queue) > 0) {
437 f_PCUIF_MsgQueue_dequeue(pdtch_rts_queue, pcu_msg);
438
439 /* Patch TDMA frame / block number and send */
440 pcu_msg.u.rts_req.fn := event.data.tdma_fn;
Pau Espin Pedrol9fc065a2021-05-11 17:05:39 +0200441 pcu_msg.u.rts_req.block_nr := fn2macblock(event.data.tdma_fn);
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200442 PCUIF.send(pcu_msg);
443 }
444
445 /* We don't really need to send every frame to OsmoPCU, because
446 * it omits frame numbers not starting at a MAC block. */
447 PCUIF.send(ts_PCUIF_TIME_IND(bts_nr, event.data.tdma_fn));
448 repeat;
449 }
Pau Espin Pedrol873686f2021-03-05 14:57:58 +0100450 [] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_END)) -> value event {
Pau Espin Pedrol60727252019-12-04 21:40:25 +0100451 /* FN matching the beginning of current block: */
452 ev_begin_fn := event.data.tdma_fn - 3;
Pau Espin Pedrol873686f2021-03-05 14:57:58 +0100453 f_tx_data_ind_fn(bts_nr, ev_begin_fn);
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200454 repeat;
455 }
456 [lengthof(ptcch_rts_queue) > 0] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PTCCH_DL_BLOCK)) -> value event {
Pau Espin Pedrol60727252019-12-04 21:40:25 +0100457 /* FN matching the beginning of current block (PTCCH is interleaved over 4 non-consecutive bursts): */
458 ev_begin_fn := event.data.tdma_fn - 78;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200459 /* Dequeue an RTS.req message for PTCCH */
460 f_PCUIF_MsgQueue_dequeue(ptcch_rts_queue, pcu_msg);
461
462 /* Patch TDMA frame / block number and send */
Pau Espin Pedrol60727252019-12-04 21:40:25 +0100463 pcu_msg.u.rts_req.fn := ev_begin_fn;
Pau Espin Pedrol9fc065a2021-05-11 17:05:39 +0200464 pcu_msg.u.rts_req.block_nr := fn2macblock(ev_begin_fn);
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200465 PCUIF.send(pcu_msg);
466 repeat;
467 }
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700468 /* Optional forwarding of PTCCH/U burst indications to the test case */
469 [cfg_ptcch_burst_fwd] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PTCCH_UL_BURST)) -> value event {
470 TC.send(event);
471 repeat;
472 }
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200473 /* Ignore other clock events (and guard against an empty queue) */
474 [] CLCK.receive(tr_RAW_PCU_CLCK_EV) { repeat; }
475}
476
Pau Espin Pedrolcf5c33e2021-01-19 18:56:55 +0100477function f_BTS_CT_handler(integer bts_nr, PCUIF_info_ind info_ind, boolean decode_data_req := false)
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200478runs on RAW_PCU_BTS_CT {
479 var PCUIF_Message pcu_msg;
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700480 var RAW_PCU_Command cmd;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200481 var RAW_PCU_Event event;
Pau Espin Pedrolcf5c33e2021-01-19 18:56:55 +0100482 var BTS_PDTCH_Block pcu_msg_pdtch;
483 var BTS_PTCCH_Block pcu_msg_ptcch;
484 var BTS_CCCH_Block pcu_msg_rr;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200485
Pau Espin Pedrol873686f2021-03-05 14:57:58 +0100486 g_info_ind := info_ind;
487
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200488 /* Init TDMA clock generator (so we can stop and start it) */
489 vc_CLCK_GEN := RAW_PCU_ClckGen_CT.create("ClckGen-" & int2str(bts_nr)) alive;
490 connect(vc_CLCK_GEN:CLCK, self:CLCK);
491
492 /* Wait until the PCU is connected */
493 PCUIF.receive(tr_RAW_PCU_EV(PCU_EV_CONNECT));
494
Pau Espin Pedrolcf5c33e2021-01-19 18:56:55 +0100495 var template PCUIF_Sapi tr_ccch_sapi := (PCU_IF_SAPI_PCH, PCU_IF_SAPI_AGCH);
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200496 alt {
497 /* Wait for TXT.ind (PCU_VERSION) and respond with INFO.ind (SI13) */
498 [] PCUIF.receive(tr_PCUIF_TXT_IND(bts_nr, PCU_VERSION, ?)) -> value pcu_msg {
499 log("Rx TXT.ind from the PCU, version is ", pcu_msg.u.txt_ind.text);
500
501 /* Send System Information 13 to the PCU */
502 PCUIF.send(PCUIF_Message:{
503 msg_type := PCU_IF_MSG_INFO_IND,
504 bts_nr := bts_nr,
505 spare := '0000'O,
506 u := { info_ind := info_ind }
507 });
508
Pau Espin Pedrolc62ebac2021-03-12 15:07:06 +0100509 const integer start_fn := 0;
Pau Espin Pedrol4c23aea2021-11-16 19:14:00 +0100510 f_tx_first_data_ind(bts_nr, info_ind, start_fn);
Pau Espin Pedroled9ca972021-03-11 20:53:21 +0100511
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200512 /* Notify the test case that we're done with SI13 */
513 TC.send(ts_RAW_PCU_EV(BTS_EV_SI13_NEGO));
514
515 /* Start feeding clock to the PCU */
Pau Espin Pedroled9ca972021-03-11 20:53:21 +0100516 vc_CLCK_GEN.start(f_ClckGen_CT_handler(start_fn));
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200517 repeat;
518 }
Pau Espin Pedrold16bb272019-12-02 12:57:03 +0100519 /* PCU -> TS becomes active */
520 [] PCUIF.receive(tr_PCUIF_ACT_REQ(bts_nr, ?, ?)) -> value pcu_msg {
521 log("Rx ACT.req from the PCU: TRX" & int2str(pcu_msg.u.act_req.trx_nr) &
522 "/TS" & int2str(pcu_msg.u.act_req.ts_nr));
523 repeat;
524 }
525 /* PCU -> TS becomes inactive */
526 [] PCUIF.receive(tr_PCUIF_DEACT_REQ(bts_nr, ?, ?)) -> value pcu_msg {
527 log("Rx DEACT.req from the PCU: TRX" & int2str(pcu_msg.u.act_req.trx_nr) &
528 "/TS" & int2str(pcu_msg.u.act_req.ts_nr));
529 repeat;
530 }
Pau Espin Pedrolcf5c33e2021-01-19 18:56:55 +0100531 [decode_data_req] PCUIF.receive(tr_PCUIF_DATA_REQ(bts_nr, ?, ?, sapi := tr_ccch_sapi)) -> value pcu_msg {
532 var octetstring data;
533 /* On PCH the payload is prefixed with paging group (3 octets): skip it.
534 * TODO: add an additional template parameter, so we can match it. */
535 if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_PCH) {
536 data := substr(pcu_msg.u.data_req.data, 3, pcu_msg.u.data_req.len - 3);
537 } else if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_AGCH) {
538 data := pcu_msg.u.data_req.data;
539 }
540 pcu_msg_rr.bts_nr := bts_nr;
541 pcu_msg_rr.raw := pcu_msg.u.data_req;
542 pcu_msg_rr.rr_msg := dec_GsmRrMessage(data);
543 TC.send(pcu_msg_rr);
544 repeat;
545 }
546 [decode_data_req] PCUIF.receive(tr_PCUIF_DATA_REQ(bts_nr, ?, ?, sapi := PCU_IF_SAPI_PDTCH)) -> value pcu_msg {
547 pcu_msg_pdtch.bts_nr := bts_nr;
548 pcu_msg_pdtch.raw := pcu_msg.u.data_req;
Pau Espin Pedrolcf2ada52021-09-22 14:11:44 +0200549 if (pcu_msg_pdtch.raw.len != 0) {
550 pcu_msg_pdtch.dl_block := dec_RlcmacDlBlock(pcu_msg_pdtch.raw.data);
551 } else {
552 pcu_msg_pdtch.dl_block := omit;
553 }
Pau Espin Pedrolcf5c33e2021-01-19 18:56:55 +0100554 TC.send(pcu_msg_pdtch);
555 repeat;
556 }
557 [decode_data_req] PCUIF.receive(tr_PCUIF_DATA_REQ(bts_nr, ?, ?, sapi := PCU_IF_SAPI_PTCCH)) -> value pcu_msg {
558 pcu_msg_ptcch.bts_nr := bts_nr;
559 pcu_msg_ptcch.raw := pcu_msg.u.data_req;
Pau Espin Pedrolcf2ada52021-09-22 14:11:44 +0200560 if (pcu_msg_ptcch.raw.len != 0) {
561 pcu_msg_ptcch.dl_block := dec_PTCCHDownlinkMsg(pcu_msg_ptcch.raw.data);
562 } else {
563 pcu_msg_ptcch.dl_block := omit;
564 }
Pau Espin Pedrolcf5c33e2021-01-19 18:56:55 +0100565 TC.send(pcu_msg_ptcch);
566 repeat;
567 }
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200568 /* PCU -> test case forwarding (filter by the BTS number) */
569 [] PCUIF.receive(tr_PCUIF_MSG(?, bts_nr)) -> value pcu_msg {
570 TC.send(pcu_msg);
571 repeat;
572 }
573
574 /* TC -> [Queue] -> PCU forwarding */
575 [] as_BTS_CT_MsgQueue(bts_nr);
576 /* TDMA scheduler (clock and queue handling) */
577 [] as_BTS_CT_TDMASched(bts_nr);
578
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700579 /* Command handling */
Vadim Yanitskiy91f8a092020-05-06 21:41:05 +0700580 [] TC.receive(tr_RAW_PCU_CMD(GENERAL_CMD_SHUTDOWN)) {
581 log("Shutting down virtual BTS #", bts_nr, "...");
582 vc_CLCK_GEN.stop;
583 break;
584 }
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700585 [] TC.receive(tr_RAW_PCU_CMD(TDMA_CMD_ENABLE_PTCCH_UL_FWD)) {
586 log("Enabling forwarding of PTCCH/U TDMA events to the TC");
587 cfg_ptcch_burst_fwd := true;
588 repeat;
589 }
590 [] TC.receive(tr_RAW_PCU_CMD) -> value cmd {
591 log("Ignore unhandled command: ", cmd);
592 repeat;
593 }
594
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200595 /* TODO: handle events (e.g. disconnection) from the PCU interface */
596 [] PCUIF.receive(tr_RAW_PCU_EV) -> value event {
597 log("Ignore unhandled event: ", event);
598 repeat;
599 }
600 }
601}
602
603/* PCU interface (UNIX domain socket) handler */
604type component RAW_PCUIF_CT {
605 var ConnectionId g_pcu_conn_id := -1;
606 var boolean g_pcu_connected := false;
607 port PCUIF_CODEC_PT PCU;
608
609 /* Connection towards BTS component(s) */
610 port RAW_PCU_MSG_PT BTS;
611 /* Connection to the MTC (test case) */
612 port RAW_PCU_MSG_PT MTC;
613};
614
615/* All received messages and events from OsmoPCU can be additionally sent
616 * directly to the MTC component. Pass direct := true to enable this mode. */
617function f_PCUIF_CT_handler(charstring pcu_sock_path, boolean direct := false)
618runs on RAW_PCUIF_CT {
619 var PCUIF_send_data pcu_sd_msg;
620 var PCUIF_Message pcu_msg;
621 timer T_Conn := 10.0;
622
623 log("Init PCU interface on '" & pcu_sock_path & "', waiting for connection...");
624 g_pcu_conn_id := f_pcuif_listen(PCU, pcu_sock_path);
625
626 /* Wait for connection */
627 T_Conn.start;
628 alt {
629 [not g_pcu_connected] PCU.receive(UD_connected:?) {
630 log("OsmoPCU is now connected");
631 /* Duplicate this event to the MTC if requested */
632 if (direct) { MTC.send(ts_RAW_PCU_EV(PCU_EV_CONNECT)); }
633 BTS.send(ts_RAW_PCU_EV(PCU_EV_CONNECT));
634 g_pcu_connected := true;
635 setverdict(pass);
636 T_Conn.stop;
637 repeat;
638 }
639 /* PCU -> BTS / MTC message forwarding */
640 [g_pcu_connected] PCU.receive(PCUIF_send_data:?) -> value pcu_sd_msg {
641 /* Send to the BTSes if at least one is connected */
642 if (BTS.checkstate("Connected")) { BTS.send(pcu_sd_msg.data); }
643 /* Duplicate this message to the MTC if requested */
644 if (direct) { MTC.send(pcu_sd_msg.data); }
645 repeat;
646 }
647 /* MTC -> PCU message forwarding */
648 [g_pcu_connected] MTC.receive(PCUIF_Message:?) -> value pcu_msg {
649 PCU.send(t_SD_PCUIF(g_pcu_conn_id, pcu_msg));
650 repeat;
651 }
652 /* BTS -> PCU message forwarding */
653 [g_pcu_connected] BTS.receive(PCUIF_Message:?) -> value pcu_msg {
654 PCU.send(t_SD_PCUIF(g_pcu_conn_id, pcu_msg));
655 repeat;
656 }
657 [not g_pcu_connected] MTC.receive(PCUIF_Message:?) -> value pcu_msg {
658 log("PCU is not connected, dropping ", pcu_msg);
659 repeat;
660 }
661 [not g_pcu_connected] BTS.receive(PCUIF_Message:?) -> value pcu_msg {
662 log("PCU is not connected, dropping ", pcu_msg);
663 repeat;
664 }
665 /* TODO: handle disconnect and reconnect of the PCU */
666 [] PCU.receive {
667 log("Unhandled message on PCU interface");
668 repeat;
669 }
670 [not g_pcu_connected] T_Conn.timeout {
671 setverdict(fail, "Timeout waiting for PCU connection");
672 mtc.stop;
673 }
674 }
675}
676
677}