Pau Espin Pedrol | 8dd59fb | 2020-04-29 15:08:16 +0200 | [diff] [blame] | 1 | module PCUIF_Components { |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 2 | |
| 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 | |
| 16 | import from IPL4asp_Types all; |
| 17 | import from UD_Types all; |
| 18 | |
| 19 | import from PCUIF_Types all; |
| 20 | import from PCUIF_CodecPort all; |
| 21 | |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 22 | import from Osmocom_Types all; |
| 23 | import from RLCMAC_Types all; |
| 24 | import from GSM_RR_Types all; |
| 25 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 26 | /* 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. */ |
| 55 | type 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 */ |
| 73 | type union RAW_PCU_EventParam { |
| 74 | integer tdma_fn |
| 75 | }; |
| 76 | |
| 77 | type record RAW_PCU_Event { |
| 78 | RAW_PCU_EventType event, |
| 79 | /* TODO: can we use 'anytype' here? */ |
| 80 | RAW_PCU_EventParam data optional |
| 81 | }; |
| 82 | |
| 83 | template (value) RAW_PCU_Event ts_RAW_PCU_EV(RAW_PCU_EventType event) := { |
| 84 | event := event, |
| 85 | data := omit |
| 86 | } |
| 87 | template 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 | |
| 93 | template (value) RAW_PCU_Event ts_RAW_PCU_CLCK_EV(RAW_PCU_EventType event, integer fn) := { |
| 94 | event := event, |
| 95 | data := { tdma_fn := fn } |
| 96 | } |
| 97 | template 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 Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 104 | /* Commands are mostly used by the MTC to configure the components |
| 105 | * at run-time, e.g. to enable or disable some optional features. */ |
| 106 | type enumerated RAW_PCU_CommandType { |
Vadim Yanitskiy | 91f8a09 | 2020-05-06 21:41:05 +0700 | [diff] [blame] | 107 | GENERAL_CMD_SHUTDOWN, /*!< Shut down component and all its child components */ |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 108 | TDMA_CMD_ENABLE_PTCCH_UL_FWD /*!< Enable forwarding of TDMA_EV_PTCCH_UL_BURST to the MTC */ |
| 109 | }; |
| 110 | |
| 111 | type record RAW_PCU_Command { |
| 112 | RAW_PCU_CommandType cmd, |
| 113 | anytype data optional |
| 114 | }; |
| 115 | |
| 116 | template (value) RAW_PCU_Command ts_RAW_PCU_CMD(RAW_PCU_CommandType cmd) := { |
| 117 | cmd := cmd, |
| 118 | data := omit |
| 119 | } |
| 120 | template 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 Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 126 | /* PCUIF req_data containing decoded rlcmac/rr, for users to be able to match |
| 127 | * directly on receive() |
| 128 | */ |
| 129 | type record BTS_PDTCH_Block { |
| 130 | uint8_t bts_nr, |
| 131 | PCUIF_data raw, |
| 132 | RlcmacDlBlock dl_block |
| 133 | }; |
| 134 | type record BTS_PTCCH_Block { |
| 135 | uint8_t bts_nr, |
| 136 | PCUIF_data raw, |
| 137 | PTCCHDownlinkMsg dl_block |
| 138 | }; |
| 139 | type record BTS_CCCH_Block { |
| 140 | uint8_t bts_nr, |
| 141 | PCUIF_data raw, |
| 142 | GsmRrMessage rr_msg |
| 143 | }; |
| 144 | template 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 | }; |
| 151 | template 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 | }; |
| 158 | template 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 Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 166 | /* Generic port for messages and events */ |
| 167 | type port RAW_PCU_MSG_PT message { |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 168 | inout RAW_PCU_Command; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 169 | inout RAW_PCU_Event; |
| 170 | inout PCUIF_Message; |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 171 | inout BTS_PDTCH_Block; |
| 172 | inout BTS_PTCCH_Block; |
| 173 | inout BTS_CCCH_Block; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 174 | } with { extension "internal" }; |
| 175 | |
| 176 | /* TDMA frame clock generator */ |
| 177 | type 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 Yanitskiy | 20f8700 | 2019-10-06 00:51:50 +0700 | [diff] [blame] | 184 | /* Derive PTCCH/U sub-slot from a given TDMA frame-number */ |
| 185 | function 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 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 215 | function f_ClckGen_CT_handler() |
| 216 | runs on RAW_PCU_ClckGen_CT { |
| 217 | var integer fn104, fn52, fn13; |
| 218 | |
| 219 | while (true) { |
| 220 | fn104 := fn mod 104; |
| 221 | fn52 := fn mod 52; |
| 222 | fn13 := fn mod 13; |
| 223 | |
| 224 | if (fn13 == 0 or fn13 == 4 or fn13 == 8) { |
| 225 | /* 1/4 bursts of a PDTCH block on both Uplink and Downlink */ |
| 226 | CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_BEG, fn)); |
| 227 | } else if (fn13 == 3 or fn13 == 7 or fn13 == 11) { |
| 228 | /* 4/4 bursts of a PDTCH block on both Uplink and Downlink */ |
| 229 | CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_END, fn)); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 230 | } else if (fn52 == 12 or fn52 == 38) { |
Vadim Yanitskiy | b58b730 | 2019-10-06 01:01:48 +0700 | [diff] [blame] | 231 | /* 4/4 bursts of a PTCCH (Timing Advance Control) block on Downlink */ |
| 232 | if (fn104 == 90) { |
| 233 | CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PTCCH_DL_BLOCK, fn)); |
| 234 | } |
| 235 | /* One Access Burst on PTCCH/U (goes 3 time-slots after PTCCH/D) */ |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 236 | CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PTCCH_UL_BURST, fn)); |
| 237 | } |
| 238 | |
| 239 | /* TDMA hyperframe period is (2048 * 51 * 26) frames */ |
| 240 | fn := (fn + 1) mod (2048 * 51 * 26); |
| 241 | |
| 242 | /* (Re)start TDMA clock timer and wait */ |
| 243 | T_TDMAClock.start; |
| 244 | T_TDMAClock.timeout; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | type record of PCUIF_Message PCUIF_MsgQueue; |
| 249 | |
| 250 | /* Enqueue a given message to the end of a given queue */ |
| 251 | private function f_PCUIF_MsgQueue_enqueue(inout PCUIF_MsgQueue queue, |
| 252 | in PCUIF_Message msg) |
| 253 | { |
| 254 | queue := queue & { msg }; |
| 255 | } |
| 256 | |
| 257 | /* Dequeue the first message of a given queue */ |
| 258 | private function f_PCUIF_MsgQueue_dequeue(inout PCUIF_MsgQueue queue, |
| 259 | out PCUIF_Message msg) |
| 260 | { |
| 261 | var integer len := lengthof(queue); |
| 262 | |
| 263 | if (len == 0) { |
| 264 | setverdict(fail, "Failed to dequeue a message: the queue is empty!"); |
| 265 | mtc.stop; |
| 266 | } |
| 267 | |
| 268 | /* Store the first message */ |
| 269 | msg := queue[0]; |
| 270 | |
| 271 | /* Remove the first message from queue */ |
| 272 | if (len > 1) { |
| 273 | queue := substr(queue, 1, len - 1); |
| 274 | } else { |
| 275 | queue := { }; |
| 276 | } |
| 277 | } |
| 278 | |
Pau Espin Pedrol | 65bab9e | 2019-12-04 21:05:10 +0100 | [diff] [blame] | 279 | /* Get first message from queue. true if non-empty, false otherwise */ |
| 280 | private function f_PCUIF_MsgQueue_first(inout PCUIF_MsgQueue queue, |
| 281 | out PCUIF_Message msg) return boolean |
| 282 | { |
| 283 | if (lengthof(queue) == 0) { |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | msg := queue[0]; |
| 288 | return true; |
| 289 | } |
| 290 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 291 | /* Multiple base stations can be connected to the PCU. This component |
| 292 | * represents one BTS with an associated TDMA clock generator. */ |
| 293 | type component RAW_PCU_BTS_CT { |
| 294 | /* TDMA clock generator */ |
| 295 | var RAW_PCU_ClckGen_CT vc_CLCK_GEN; |
| 296 | port RAW_PCU_MSG_PT CLCK; |
| 297 | |
| 298 | /* Queues of PCUIF messages to be sent |
| 299 | * TODO: we may have multiple PDCH time-slots */ |
| 300 | var PCUIF_MsgQueue pdtch_data_queue := { }; |
| 301 | var PCUIF_MsgQueue pdtch_rts_queue := { }; |
| 302 | var PCUIF_MsgQueue ptcch_rts_queue := { }; |
| 303 | |
| 304 | /* Connection towards the PCU interface */ |
| 305 | port RAW_PCU_MSG_PT PCUIF; |
| 306 | /* Connection towards the test case */ |
| 307 | port RAW_PCU_MSG_PT TC; |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 308 | |
| 309 | /* Whether to forward PTCCH/U burst events to the TC */ |
| 310 | var boolean cfg_ptcch_burst_fwd := false; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 311 | } |
| 312 | |
Pau Espin Pedrol | 65bab9e | 2019-12-04 21:05:10 +0100 | [diff] [blame] | 313 | /* Queue received messages from Test Case, they will eventually be scheduled and |
| 314 | * sent according to their FN. FN value of 0 has the special meaning of "schedule |
| 315 | * as soon as possible". */ |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 316 | private altstep as_BTS_CT_MsgQueue(integer bts_nr) |
| 317 | runs on RAW_PCU_BTS_CT { |
| 318 | var PCUIF_Message pcu_msg; |
| 319 | |
| 320 | /* Enqueue DATA.ind and RTS.req messages */ |
| 321 | [] TC.receive(tr_PCUIF_MSG(PCU_IF_MSG_DATA_IND, bts_nr)) -> value pcu_msg { |
| 322 | f_PCUIF_MsgQueue_enqueue(pdtch_data_queue, pcu_msg); |
| 323 | repeat; |
| 324 | } |
| 325 | [] TC.receive(tr_PCUIF_RTS_REQ(bts_nr, sapi := PCU_IF_SAPI_PDTCH)) -> value pcu_msg { |
| 326 | f_PCUIF_MsgQueue_enqueue(pdtch_rts_queue, pcu_msg); |
| 327 | repeat; |
| 328 | } |
| 329 | [] TC.receive(tr_PCUIF_RTS_REQ(bts_nr, sapi := PCU_IF_SAPI_PTCCH)) -> value pcu_msg { |
| 330 | f_PCUIF_MsgQueue_enqueue(ptcch_rts_queue, pcu_msg); |
| 331 | repeat; |
| 332 | } |
| 333 | /* Forward other messages directly to the PCU */ |
| 334 | [] TC.receive(tr_PCUIF_MSG(?, bts_nr)) -> value pcu_msg { |
| 335 | PCUIF.send(pcu_msg); |
| 336 | repeat; |
| 337 | } |
| 338 | } |
| 339 | |
Pau Espin Pedrol | 65bab9e | 2019-12-04 21:05:10 +0100 | [diff] [blame] | 340 | /* Handle schedule events and manage actions: Send msgs over PCUIF to PCU, |
| 341 | * advertise Test Case about sent messages, etc. */ |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 342 | private altstep as_BTS_CT_TDMASched(integer bts_nr) |
| 343 | runs on RAW_PCU_BTS_CT { |
| 344 | var PCUIF_Message pcu_msg; |
| 345 | var RAW_PCU_Event event; |
Pau Espin Pedrol | 6072725 | 2019-12-04 21:40:25 +0100 | [diff] [blame] | 346 | var integer ev_begin_fn; |
Pau Espin Pedrol | 65bab9e | 2019-12-04 21:05:10 +0100 | [diff] [blame] | 347 | var integer next_fn; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 348 | |
| 349 | [] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_BEG)) -> value event { |
| 350 | /* If the RTS queue for PDTCH is not empty, send a message */ |
| 351 | if (lengthof(pdtch_rts_queue) > 0) { |
| 352 | f_PCUIF_MsgQueue_dequeue(pdtch_rts_queue, pcu_msg); |
| 353 | |
| 354 | /* Patch TDMA frame / block number and send */ |
| 355 | pcu_msg.u.rts_req.fn := event.data.tdma_fn; |
| 356 | pcu_msg.u.rts_req.block_nr := 0; /* FIXME! */ |
| 357 | PCUIF.send(pcu_msg); |
| 358 | } |
| 359 | |
| 360 | /* We don't really need to send every frame to OsmoPCU, because |
| 361 | * it omits frame numbers not starting at a MAC block. */ |
| 362 | PCUIF.send(ts_PCUIF_TIME_IND(bts_nr, event.data.tdma_fn)); |
| 363 | repeat; |
| 364 | } |
| 365 | [lengthof(pdtch_data_queue) > 0] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_END)) -> value event { |
Pau Espin Pedrol | 6072725 | 2019-12-04 21:40:25 +0100 | [diff] [blame] | 366 | /* FN matching the beginning of current block: */ |
| 367 | ev_begin_fn := event.data.tdma_fn - 3; |
Pau Espin Pedrol | 65bab9e | 2019-12-04 21:05:10 +0100 | [diff] [blame] | 368 | |
| 369 | /* Check if we reached time to serve the first DATA.ind message in the queue: */ |
| 370 | f_PCUIF_MsgQueue_first(pdtch_data_queue, pcu_msg); |
| 371 | next_fn := pcu_msg.u.data_ind.fn; |
| 372 | if (next_fn != 0 and next_fn != ev_begin_fn) { |
| 373 | if (next_fn < ev_begin_fn) { |
| 374 | setverdict(fail, "We are late scheduling the block! ", next_fn, " < ", ev_begin_fn); |
| 375 | mtc.stop; |
| 376 | } |
| 377 | repeat; |
| 378 | } |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 379 | /* Dequeue a DATA.ind message */ |
| 380 | f_PCUIF_MsgQueue_dequeue(pdtch_data_queue, pcu_msg); |
| 381 | |
| 382 | /* Patch TDMA frame / block number */ |
Pau Espin Pedrol | 6072725 | 2019-12-04 21:40:25 +0100 | [diff] [blame] | 383 | pcu_msg.u.data_ind.fn := ev_begin_fn; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 384 | pcu_msg.u.data_ind.block_nr := 0; /* FIXME! */ |
| 385 | |
| 386 | PCUIF.send(pcu_msg); /* Send to the PCU and notify the TC */ |
Pau Espin Pedrol | 6072725 | 2019-12-04 21:40:25 +0100 | [diff] [blame] | 387 | TC.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_SENT, ev_begin_fn)); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 388 | repeat; |
| 389 | } |
| 390 | [lengthof(ptcch_rts_queue) > 0] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PTCCH_DL_BLOCK)) -> value event { |
Pau Espin Pedrol | 6072725 | 2019-12-04 21:40:25 +0100 | [diff] [blame] | 391 | /* FN matching the beginning of current block (PTCCH is interleaved over 4 non-consecutive bursts): */ |
| 392 | ev_begin_fn := event.data.tdma_fn - 78; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 393 | /* Dequeue an RTS.req message for PTCCH */ |
| 394 | f_PCUIF_MsgQueue_dequeue(ptcch_rts_queue, pcu_msg); |
| 395 | |
| 396 | /* Patch TDMA frame / block number and send */ |
Pau Espin Pedrol | 6072725 | 2019-12-04 21:40:25 +0100 | [diff] [blame] | 397 | pcu_msg.u.rts_req.fn := ev_begin_fn; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 398 | pcu_msg.u.rts_req.block_nr := 0; /* FIXME! */ |
| 399 | PCUIF.send(pcu_msg); |
| 400 | repeat; |
| 401 | } |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 402 | /* Optional forwarding of PTCCH/U burst indications to the test case */ |
| 403 | [cfg_ptcch_burst_fwd] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PTCCH_UL_BURST)) -> value event { |
| 404 | TC.send(event); |
| 405 | repeat; |
| 406 | } |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 407 | /* Ignore other clock events (and guard against an empty queue) */ |
| 408 | [] CLCK.receive(tr_RAW_PCU_CLCK_EV) { repeat; } |
| 409 | } |
| 410 | |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 411 | function f_BTS_CT_handler(integer bts_nr, PCUIF_info_ind info_ind, boolean decode_data_req := false) |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 412 | runs on RAW_PCU_BTS_CT { |
| 413 | var PCUIF_Message pcu_msg; |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 414 | var RAW_PCU_Command cmd; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 415 | var RAW_PCU_Event event; |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 416 | var BTS_PDTCH_Block pcu_msg_pdtch; |
| 417 | var BTS_PTCCH_Block pcu_msg_ptcch; |
| 418 | var BTS_CCCH_Block pcu_msg_rr; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 419 | |
| 420 | /* Init TDMA clock generator (so we can stop and start it) */ |
| 421 | vc_CLCK_GEN := RAW_PCU_ClckGen_CT.create("ClckGen-" & int2str(bts_nr)) alive; |
| 422 | connect(vc_CLCK_GEN:CLCK, self:CLCK); |
| 423 | |
| 424 | /* Wait until the PCU is connected */ |
| 425 | PCUIF.receive(tr_RAW_PCU_EV(PCU_EV_CONNECT)); |
| 426 | |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 427 | var template PCUIF_Sapi tr_ccch_sapi := (PCU_IF_SAPI_PCH, PCU_IF_SAPI_AGCH); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 428 | alt { |
| 429 | /* Wait for TXT.ind (PCU_VERSION) and respond with INFO.ind (SI13) */ |
| 430 | [] PCUIF.receive(tr_PCUIF_TXT_IND(bts_nr, PCU_VERSION, ?)) -> value pcu_msg { |
| 431 | log("Rx TXT.ind from the PCU, version is ", pcu_msg.u.txt_ind.text); |
| 432 | |
| 433 | /* Send System Information 13 to the PCU */ |
| 434 | PCUIF.send(PCUIF_Message:{ |
| 435 | msg_type := PCU_IF_MSG_INFO_IND, |
| 436 | bts_nr := bts_nr, |
| 437 | spare := '0000'O, |
| 438 | u := { info_ind := info_ind } |
| 439 | }); |
| 440 | |
| 441 | /* Notify the test case that we're done with SI13 */ |
| 442 | TC.send(ts_RAW_PCU_EV(BTS_EV_SI13_NEGO)); |
| 443 | |
| 444 | /* Start feeding clock to the PCU */ |
| 445 | vc_CLCK_GEN.start(f_ClckGen_CT_handler()); |
| 446 | repeat; |
| 447 | } |
Pau Espin Pedrol | d16bb27 | 2019-12-02 12:57:03 +0100 | [diff] [blame] | 448 | /* PCU -> TS becomes active */ |
| 449 | [] PCUIF.receive(tr_PCUIF_ACT_REQ(bts_nr, ?, ?)) -> value pcu_msg { |
| 450 | log("Rx ACT.req from the PCU: TRX" & int2str(pcu_msg.u.act_req.trx_nr) & |
| 451 | "/TS" & int2str(pcu_msg.u.act_req.ts_nr)); |
| 452 | repeat; |
| 453 | } |
| 454 | /* PCU -> TS becomes inactive */ |
| 455 | [] PCUIF.receive(tr_PCUIF_DEACT_REQ(bts_nr, ?, ?)) -> value pcu_msg { |
| 456 | log("Rx DEACT.req from the PCU: TRX" & int2str(pcu_msg.u.act_req.trx_nr) & |
| 457 | "/TS" & int2str(pcu_msg.u.act_req.ts_nr)); |
| 458 | repeat; |
| 459 | } |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 460 | [decode_data_req] PCUIF.receive(tr_PCUIF_DATA_REQ(bts_nr, ?, ?, sapi := tr_ccch_sapi)) -> value pcu_msg { |
| 461 | var octetstring data; |
| 462 | /* On PCH the payload is prefixed with paging group (3 octets): skip it. |
| 463 | * TODO: add an additional template parameter, so we can match it. */ |
| 464 | if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_PCH) { |
| 465 | data := substr(pcu_msg.u.data_req.data, 3, pcu_msg.u.data_req.len - 3); |
| 466 | } else if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_AGCH) { |
| 467 | data := pcu_msg.u.data_req.data; |
| 468 | } |
| 469 | pcu_msg_rr.bts_nr := bts_nr; |
| 470 | pcu_msg_rr.raw := pcu_msg.u.data_req; |
| 471 | pcu_msg_rr.rr_msg := dec_GsmRrMessage(data); |
| 472 | TC.send(pcu_msg_rr); |
| 473 | repeat; |
| 474 | } |
| 475 | [decode_data_req] PCUIF.receive(tr_PCUIF_DATA_REQ(bts_nr, ?, ?, sapi := PCU_IF_SAPI_PDTCH)) -> value pcu_msg { |
| 476 | pcu_msg_pdtch.bts_nr := bts_nr; |
| 477 | pcu_msg_pdtch.raw := pcu_msg.u.data_req; |
| 478 | pcu_msg_pdtch.dl_block := dec_RlcmacDlBlock(pcu_msg_pdtch.raw.data); |
| 479 | TC.send(pcu_msg_pdtch); |
| 480 | repeat; |
| 481 | } |
| 482 | [decode_data_req] PCUIF.receive(tr_PCUIF_DATA_REQ(bts_nr, ?, ?, sapi := PCU_IF_SAPI_PTCCH)) -> value pcu_msg { |
| 483 | pcu_msg_ptcch.bts_nr := bts_nr; |
| 484 | pcu_msg_ptcch.raw := pcu_msg.u.data_req; |
| 485 | pcu_msg_ptcch.dl_block := dec_PTCCHDownlinkMsg(pcu_msg_ptcch.raw.data); |
| 486 | TC.send(pcu_msg_ptcch); |
| 487 | repeat; |
| 488 | } |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 489 | /* PCU -> test case forwarding (filter by the BTS number) */ |
| 490 | [] PCUIF.receive(tr_PCUIF_MSG(?, bts_nr)) -> value pcu_msg { |
| 491 | TC.send(pcu_msg); |
| 492 | repeat; |
| 493 | } |
| 494 | |
| 495 | /* TC -> [Queue] -> PCU forwarding */ |
| 496 | [] as_BTS_CT_MsgQueue(bts_nr); |
| 497 | /* TDMA scheduler (clock and queue handling) */ |
| 498 | [] as_BTS_CT_TDMASched(bts_nr); |
| 499 | |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 500 | /* Command handling */ |
Vadim Yanitskiy | 91f8a09 | 2020-05-06 21:41:05 +0700 | [diff] [blame] | 501 | [] TC.receive(tr_RAW_PCU_CMD(GENERAL_CMD_SHUTDOWN)) { |
| 502 | log("Shutting down virtual BTS #", bts_nr, "..."); |
| 503 | vc_CLCK_GEN.stop; |
| 504 | break; |
| 505 | } |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 506 | [] TC.receive(tr_RAW_PCU_CMD(TDMA_CMD_ENABLE_PTCCH_UL_FWD)) { |
| 507 | log("Enabling forwarding of PTCCH/U TDMA events to the TC"); |
| 508 | cfg_ptcch_burst_fwd := true; |
| 509 | repeat; |
| 510 | } |
| 511 | [] TC.receive(tr_RAW_PCU_CMD) -> value cmd { |
| 512 | log("Ignore unhandled command: ", cmd); |
| 513 | repeat; |
| 514 | } |
| 515 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 516 | /* TODO: handle events (e.g. disconnection) from the PCU interface */ |
| 517 | [] PCUIF.receive(tr_RAW_PCU_EV) -> value event { |
| 518 | log("Ignore unhandled event: ", event); |
| 519 | repeat; |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | /* PCU interface (UNIX domain socket) handler */ |
| 525 | type component RAW_PCUIF_CT { |
| 526 | var ConnectionId g_pcu_conn_id := -1; |
| 527 | var boolean g_pcu_connected := false; |
| 528 | port PCUIF_CODEC_PT PCU; |
| 529 | |
| 530 | /* Connection towards BTS component(s) */ |
| 531 | port RAW_PCU_MSG_PT BTS; |
| 532 | /* Connection to the MTC (test case) */ |
| 533 | port RAW_PCU_MSG_PT MTC; |
| 534 | }; |
| 535 | |
| 536 | /* All received messages and events from OsmoPCU can be additionally sent |
| 537 | * directly to the MTC component. Pass direct := true to enable this mode. */ |
| 538 | function f_PCUIF_CT_handler(charstring pcu_sock_path, boolean direct := false) |
| 539 | runs on RAW_PCUIF_CT { |
| 540 | var PCUIF_send_data pcu_sd_msg; |
| 541 | var PCUIF_Message pcu_msg; |
| 542 | timer T_Conn := 10.0; |
| 543 | |
| 544 | log("Init PCU interface on '" & pcu_sock_path & "', waiting for connection..."); |
| 545 | g_pcu_conn_id := f_pcuif_listen(PCU, pcu_sock_path); |
| 546 | |
| 547 | /* Wait for connection */ |
| 548 | T_Conn.start; |
| 549 | alt { |
| 550 | [not g_pcu_connected] PCU.receive(UD_connected:?) { |
| 551 | log("OsmoPCU is now connected"); |
| 552 | /* Duplicate this event to the MTC if requested */ |
| 553 | if (direct) { MTC.send(ts_RAW_PCU_EV(PCU_EV_CONNECT)); } |
| 554 | BTS.send(ts_RAW_PCU_EV(PCU_EV_CONNECT)); |
| 555 | g_pcu_connected := true; |
| 556 | setverdict(pass); |
| 557 | T_Conn.stop; |
| 558 | repeat; |
| 559 | } |
| 560 | /* PCU -> BTS / MTC message forwarding */ |
| 561 | [g_pcu_connected] PCU.receive(PCUIF_send_data:?) -> value pcu_sd_msg { |
| 562 | /* Send to the BTSes if at least one is connected */ |
| 563 | if (BTS.checkstate("Connected")) { BTS.send(pcu_sd_msg.data); } |
| 564 | /* Duplicate this message to the MTC if requested */ |
| 565 | if (direct) { MTC.send(pcu_sd_msg.data); } |
| 566 | repeat; |
| 567 | } |
| 568 | /* MTC -> PCU message forwarding */ |
| 569 | [g_pcu_connected] MTC.receive(PCUIF_Message:?) -> value pcu_msg { |
| 570 | PCU.send(t_SD_PCUIF(g_pcu_conn_id, pcu_msg)); |
| 571 | repeat; |
| 572 | } |
| 573 | /* BTS -> PCU message forwarding */ |
| 574 | [g_pcu_connected] BTS.receive(PCUIF_Message:?) -> value pcu_msg { |
| 575 | PCU.send(t_SD_PCUIF(g_pcu_conn_id, pcu_msg)); |
| 576 | repeat; |
| 577 | } |
| 578 | [not g_pcu_connected] MTC.receive(PCUIF_Message:?) -> value pcu_msg { |
| 579 | log("PCU is not connected, dropping ", pcu_msg); |
| 580 | repeat; |
| 581 | } |
| 582 | [not g_pcu_connected] BTS.receive(PCUIF_Message:?) -> value pcu_msg { |
| 583 | log("PCU is not connected, dropping ", pcu_msg); |
| 584 | repeat; |
| 585 | } |
| 586 | /* TODO: handle disconnect and reconnect of the PCU */ |
| 587 | [] PCU.receive { |
| 588 | log("Unhandled message on PCU interface"); |
| 589 | repeat; |
| 590 | } |
| 591 | [not g_pcu_connected] T_Conn.timeout { |
| 592 | setverdict(fail, "Timeout waiting for PCU connection"); |
| 593 | mtc.stop; |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | } |