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 | |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 53 | modulepar { |
| 54 | boolean mp_send_all_data_ind := true; |
| 55 | } |
| 56 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 57 | /* Events are used by the components to indicate that something |
| 58 | * has happened, e.g. we have got a connection from the PCU. */ |
| 59 | type enumerated RAW_PCU_EventType { |
| 60 | /* Events related to RAW_PCUIF_CT */ |
| 61 | PCU_EV_DISCONNECT, /*!< OsmoPCU has disconnected */ |
| 62 | PCU_EV_CONNECT, /*!< OsmoPCU is now connected */ |
| 63 | |
| 64 | /* Events related to RAW_PCU_BTS_CT */ |
| 65 | BTS_EV_SI13_NEGO, /*!< SI13 negotiation complete */ |
| 66 | |
| 67 | /* TDMA clock related events (TDMA frame-number in parameters) */ |
| 68 | TDMA_EV_PDTCH_BLOCK_BEG, /*!< 1/4 bursts of a PDTCH block on both Uplink and Downlink */ |
| 69 | TDMA_EV_PDTCH_BLOCK_END, /*!< 4/4 bursts of a PDTCH block on both Uplink and Downlink */ |
| 70 | TDMA_EV_PTCCH_DL_BLOCK, /*!< 4/4 bursts of a PTCCH block on Downlink */ |
| 71 | TDMA_EV_PTCCH_UL_BURST, /*!< One Access Burst on PTCCH/U */ |
| 72 | |
| 73 | TDMA_EV_PDTCH_BLOCK_SENT /*!< A PDTCH block has been sent to the PCU */ |
| 74 | }; |
| 75 | |
| 76 | /* Union of all possible parameters of the events */ |
| 77 | type union RAW_PCU_EventParam { |
| 78 | integer tdma_fn |
| 79 | }; |
| 80 | |
| 81 | type record RAW_PCU_Event { |
| 82 | RAW_PCU_EventType event, |
| 83 | /* TODO: can we use 'anytype' here? */ |
| 84 | RAW_PCU_EventParam data optional |
| 85 | }; |
| 86 | |
| 87 | template (value) RAW_PCU_Event ts_RAW_PCU_EV(RAW_PCU_EventType event) := { |
| 88 | event := event, |
| 89 | data := omit |
| 90 | } |
| 91 | template RAW_PCU_Event tr_RAW_PCU_EV(template RAW_PCU_EventType event := ?, |
| 92 | template RAW_PCU_EventParam data := *) := { |
| 93 | event := event, |
| 94 | data := data |
| 95 | } |
| 96 | |
| 97 | template (value) RAW_PCU_Event ts_RAW_PCU_CLCK_EV(RAW_PCU_EventType event, integer fn) := { |
| 98 | event := event, |
| 99 | data := { tdma_fn := fn } |
| 100 | } |
| 101 | template RAW_PCU_Event tr_RAW_PCU_CLCK_EV := { |
| 102 | event := (TDMA_EV_PDTCH_BLOCK_BEG, TDMA_EV_PDTCH_BLOCK_END, |
| 103 | TDMA_EV_PTCCH_DL_BLOCK, TDMA_EV_PTCCH_UL_BURST, |
| 104 | TDMA_EV_PDTCH_BLOCK_SENT), |
| 105 | data := { tdma_fn := ? } |
| 106 | } |
| 107 | |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 108 | /* Commands are mostly used by the MTC to configure the components |
| 109 | * at run-time, e.g. to enable or disable some optional features. */ |
| 110 | type enumerated RAW_PCU_CommandType { |
Vadim Yanitskiy | 91f8a09 | 2020-05-06 21:41:05 +0700 | [diff] [blame] | 111 | GENERAL_CMD_SHUTDOWN, /*!< Shut down component and all its child components */ |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 112 | TDMA_CMD_ENABLE_PTCCH_UL_FWD /*!< Enable forwarding of TDMA_EV_PTCCH_UL_BURST to the MTC */ |
| 113 | }; |
| 114 | |
| 115 | type record RAW_PCU_Command { |
| 116 | RAW_PCU_CommandType cmd, |
| 117 | anytype data optional |
| 118 | }; |
| 119 | |
| 120 | template (value) RAW_PCU_Command ts_RAW_PCU_CMD(RAW_PCU_CommandType cmd) := { |
| 121 | cmd := cmd, |
| 122 | data := omit |
| 123 | } |
| 124 | template RAW_PCU_Command tr_RAW_PCU_CMD(template RAW_PCU_CommandType cmd := ?, |
| 125 | template anytype data := *) := { |
| 126 | cmd := cmd, |
| 127 | data := data |
| 128 | } |
| 129 | |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 130 | /* PCUIF req_data containing decoded rlcmac/rr, for users to be able to match |
| 131 | * directly on receive() |
| 132 | */ |
| 133 | type record BTS_PDTCH_Block { |
| 134 | uint8_t bts_nr, |
| 135 | PCUIF_data raw, |
Pau Espin Pedrol | cf2ada5 | 2021-09-22 14:11:44 +0200 | [diff] [blame] | 136 | RlcmacDlBlock dl_block optional |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 137 | }; |
| 138 | type record BTS_PTCCH_Block { |
| 139 | uint8_t bts_nr, |
| 140 | PCUIF_data raw, |
Pau Espin Pedrol | cf2ada5 | 2021-09-22 14:11:44 +0200 | [diff] [blame] | 141 | PTCCHDownlinkMsg dl_block optional |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 142 | }; |
| 143 | type record BTS_CCCH_Block { |
| 144 | uint8_t bts_nr, |
| 145 | PCUIF_data raw, |
| 146 | GsmRrMessage rr_msg |
| 147 | }; |
| 148 | template BTS_PDTCH_Block tr_PCUIF_DATA_PDTCH(template uint8_t bts_nr, |
| 149 | template PCUIF_data raw, |
| 150 | template RlcmacDlBlock dl_block := ?) := { |
| 151 | bts_nr := bts_nr, |
| 152 | raw := raw, |
| 153 | dl_block := dl_block |
| 154 | }; |
| 155 | template BTS_PTCCH_Block tr_PCUIF_DATA_PTCCH(template uint8_t bts_nr, |
| 156 | template PCUIF_data raw, |
| 157 | template PTCCHDownlinkMsg dl_block := ?) := { |
| 158 | bts_nr := bts_nr, |
| 159 | raw := raw, |
| 160 | dl_block := dl_block |
| 161 | }; |
| 162 | template BTS_CCCH_Block tr_PCUIF_DATA_RR(template uint8_t bts_nr, |
| 163 | template PCUIF_data raw, |
| 164 | template GsmRrMessage rr_msg := ?) := { |
| 165 | bts_nr := bts_nr, |
| 166 | raw := raw, |
| 167 | rr_msg := rr_msg |
| 168 | }; |
| 169 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 170 | /* Generic port for messages and events */ |
| 171 | type port RAW_PCU_MSG_PT message { |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 172 | inout RAW_PCU_Command; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 173 | inout RAW_PCU_Event; |
| 174 | inout PCUIF_Message; |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 175 | inout BTS_PDTCH_Block; |
| 176 | inout BTS_PTCCH_Block; |
| 177 | inout BTS_CCCH_Block; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 178 | } with { extension "internal" }; |
| 179 | |
| 180 | /* TDMA frame clock generator */ |
| 181 | type component RAW_PCU_ClckGen_CT { |
| 182 | /* One TDMA frame is 4.615 ms long */ |
| 183 | timer T_TDMAClock := 4.615 / 1000.0; |
| 184 | port RAW_PCU_MSG_PT CLCK; |
| 185 | var integer fn := 0; |
| 186 | } |
| 187 | |
Vadim Yanitskiy | 20f8700 | 2019-10-06 00:51:50 +0700 | [diff] [blame] | 188 | /* Derive PTCCH/U sub-slot from a given TDMA frame-number */ |
| 189 | function f_tdma_ptcch_fn2ss(integer fn) return integer |
| 190 | { |
| 191 | var integer ss := -1; |
| 192 | |
| 193 | /* See 3GPP TS 45.002, table 6 */ |
| 194 | select (fn mod 416) { |
| 195 | case (12) { ss := 0; } |
| 196 | case (38) { ss := 1; } |
| 197 | case (64) { ss := 2; } |
| 198 | case (90) { ss := 3; } |
| 199 | |
| 200 | case (116) { ss := 4; } |
| 201 | case (142) { ss := 5; } |
| 202 | case (168) { ss := 6; } |
| 203 | case (194) { ss := 7; } |
| 204 | |
| 205 | case (220) { ss := 8; } |
| 206 | case (246) { ss := 9; } |
| 207 | case (272) { ss := 10; } |
| 208 | case (298) { ss := 11; } |
| 209 | |
| 210 | case (324) { ss := 12; } |
| 211 | case (350) { ss := 13; } |
| 212 | case (376) { ss := 14; } |
| 213 | case (402) { ss := 15; } |
| 214 | } |
| 215 | |
| 216 | return ss; |
| 217 | } |
| 218 | |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 219 | function f_ClckGen_CT_handler(integer start_fn := 0) |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 220 | runs on RAW_PCU_ClckGen_CT { |
| 221 | var integer fn104, fn52, fn13; |
| 222 | |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 223 | fn := start_fn; |
| 224 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 225 | while (true) { |
| 226 | fn104 := fn mod 104; |
| 227 | fn52 := fn mod 52; |
| 228 | fn13 := fn mod 13; |
| 229 | |
| 230 | if (fn13 == 0 or fn13 == 4 or fn13 == 8) { |
| 231 | /* 1/4 bursts of a PDTCH block on both Uplink and Downlink */ |
| 232 | CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_BEG, fn)); |
| 233 | } else if (fn13 == 3 or fn13 == 7 or fn13 == 11) { |
| 234 | /* 4/4 bursts of a PDTCH block on both Uplink and Downlink */ |
| 235 | 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] | 236 | } else if (fn52 == 12 or fn52 == 38) { |
Vadim Yanitskiy | b58b730 | 2019-10-06 01:01:48 +0700 | [diff] [blame] | 237 | /* 4/4 bursts of a PTCCH (Timing Advance Control) block on Downlink */ |
| 238 | if (fn104 == 90) { |
| 239 | CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PTCCH_DL_BLOCK, fn)); |
| 240 | } |
| 241 | /* 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] | 242 | CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PTCCH_UL_BURST, fn)); |
| 243 | } |
| 244 | |
| 245 | /* TDMA hyperframe period is (2048 * 51 * 26) frames */ |
| 246 | fn := (fn + 1) mod (2048 * 51 * 26); |
| 247 | |
| 248 | /* (Re)start TDMA clock timer and wait */ |
| 249 | T_TDMAClock.start; |
| 250 | T_TDMAClock.timeout; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | type record of PCUIF_Message PCUIF_MsgQueue; |
| 255 | |
| 256 | /* Enqueue a given message to the end of a given queue */ |
| 257 | private function f_PCUIF_MsgQueue_enqueue(inout PCUIF_MsgQueue queue, |
| 258 | in PCUIF_Message msg) |
| 259 | { |
| 260 | queue := queue & { msg }; |
| 261 | } |
| 262 | |
| 263 | /* Dequeue the first message of a given queue */ |
| 264 | private function f_PCUIF_MsgQueue_dequeue(inout PCUIF_MsgQueue queue, |
| 265 | out PCUIF_Message msg) |
| 266 | { |
| 267 | var integer len := lengthof(queue); |
| 268 | |
| 269 | if (len == 0) { |
| 270 | setverdict(fail, "Failed to dequeue a message: the queue is empty!"); |
| 271 | mtc.stop; |
| 272 | } |
| 273 | |
| 274 | /* Store the first message */ |
| 275 | msg := queue[0]; |
| 276 | |
| 277 | /* Remove the first message from queue */ |
| 278 | if (len > 1) { |
| 279 | queue := substr(queue, 1, len - 1); |
| 280 | } else { |
| 281 | queue := { }; |
| 282 | } |
| 283 | } |
| 284 | |
Pau Espin Pedrol | 65bab9e | 2019-12-04 21:05:10 +0100 | [diff] [blame] | 285 | /* Get first message from queue. true if non-empty, false otherwise */ |
| 286 | private function f_PCUIF_MsgQueue_first(inout PCUIF_MsgQueue queue, |
| 287 | out PCUIF_Message msg) return boolean |
| 288 | { |
| 289 | if (lengthof(queue) == 0) { |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | msg := queue[0]; |
| 294 | return true; |
| 295 | } |
| 296 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 297 | /* Multiple base stations can be connected to the PCU. This component |
| 298 | * represents one BTS with an associated TDMA clock generator. */ |
| 299 | type component RAW_PCU_BTS_CT { |
| 300 | /* TDMA clock generator */ |
| 301 | var RAW_PCU_ClckGen_CT vc_CLCK_GEN; |
| 302 | port RAW_PCU_MSG_PT CLCK; |
| 303 | |
| 304 | /* Queues of PCUIF messages to be sent |
| 305 | * TODO: we may have multiple PDCH time-slots */ |
| 306 | var PCUIF_MsgQueue pdtch_data_queue := { }; |
| 307 | var PCUIF_MsgQueue pdtch_rts_queue := { }; |
| 308 | var PCUIF_MsgQueue ptcch_rts_queue := { }; |
| 309 | |
| 310 | /* Connection towards the PCU interface */ |
| 311 | port RAW_PCU_MSG_PT PCUIF; |
| 312 | /* Connection towards the test case */ |
| 313 | port RAW_PCU_MSG_PT TC; |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 314 | |
| 315 | /* Whether to forward PTCCH/U burst events to the TC */ |
| 316 | var boolean cfg_ptcch_burst_fwd := false; |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 317 | |
| 318 | var PCUIF_info_ind g_info_ind; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Pau Espin Pedrol | 65bab9e | 2019-12-04 21:05:10 +0100 | [diff] [blame] | 321 | /* Queue received messages from Test Case, they will eventually be scheduled and |
| 322 | * sent according to their FN. FN value of 0 has the special meaning of "schedule |
| 323 | * as soon as possible". */ |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 324 | private altstep as_BTS_CT_MsgQueue(integer bts_nr) |
| 325 | runs on RAW_PCU_BTS_CT { |
| 326 | var PCUIF_Message pcu_msg; |
| 327 | |
| 328 | /* Enqueue DATA.ind and RTS.req messages */ |
| 329 | [] TC.receive(tr_PCUIF_MSG(PCU_IF_MSG_DATA_IND, bts_nr)) -> value pcu_msg { |
Pau Espin Pedrol | aa45707 | 2021-04-19 18:06:16 +0200 | [diff] [blame] | 330 | if (pcu_msg.u.data_ind.sapi == PCU_IF_SAPI_BCCH) { |
| 331 | PCUIF.send(pcu_msg); /* Forward directly ASAP */ |
| 332 | } else { |
| 333 | f_PCUIF_MsgQueue_enqueue(pdtch_data_queue, pcu_msg); |
| 334 | } |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 335 | repeat; |
| 336 | } |
| 337 | [] TC.receive(tr_PCUIF_RTS_REQ(bts_nr, sapi := PCU_IF_SAPI_PDTCH)) -> value pcu_msg { |
| 338 | f_PCUIF_MsgQueue_enqueue(pdtch_rts_queue, pcu_msg); |
| 339 | repeat; |
| 340 | } |
| 341 | [] TC.receive(tr_PCUIF_RTS_REQ(bts_nr, sapi := PCU_IF_SAPI_PTCCH)) -> value pcu_msg { |
| 342 | f_PCUIF_MsgQueue_enqueue(ptcch_rts_queue, pcu_msg); |
| 343 | repeat; |
| 344 | } |
| 345 | /* Forward other messages directly to the PCU */ |
| 346 | [] TC.receive(tr_PCUIF_MSG(?, bts_nr)) -> value pcu_msg { |
| 347 | PCUIF.send(pcu_msg); |
| 348 | repeat; |
| 349 | } |
| 350 | } |
| 351 | |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 352 | /* Submit empty data on any available TS, to set up initial TDMA clock */ |
| 353 | private function f_tx_first_data_ind(integer bts_nr, PCUIF_info_ind info_ind, integer start_fn) |
| 354 | runs on RAW_PCU_BTS_CT |
| 355 | { |
| 356 | var PCUIF_Message pcu_msg; |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 357 | |
| 358 | /* Find an active TS: */ |
| 359 | for (var uint8_t ts_nr := 0; ts_nr < 8; ts_nr := ts_nr + 1) { |
Vadim Yanitskiy | 1da1fef | 2021-03-23 04:28:18 +0100 | [diff] [blame] | 360 | for (var integer trx_nr := 0; trx_nr < lengthof(g_info_ind.trx); trx_nr := trx_nr + 1) { |
| 361 | if (g_info_ind.trx[trx_nr].pdch_mask[ts_nr] == '0'B) { |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 362 | continue; /* TRX+TS not activated */ |
| 363 | } |
| 364 | |
| 365 | /* Send empty DATA.ind to set up FN */ |
| 366 | pcu_msg := valueof(ts_PCUIF_DATA_IND(bts_nr, trx_nr, ts_nr, 0 /* FIXME */, |
| 367 | PCU_IF_SAPI_PDTCH, ''O, start_fn, |
Vadim Yanitskiy | 1da1fef | 2021-03-23 04:28:18 +0100 | [diff] [blame] | 368 | g_info_ind.trx[trx_nr].arfcn, |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 369 | rssi := -80, ber10k := 0, |
| 370 | ta_offs_qbits := 0, lqual_cb := 10)); |
| 371 | PCUIF.send(pcu_msg); |
| 372 | return; |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
Pau Espin Pedrol | 9fc065a | 2021-05-11 17:05:39 +0200 | [diff] [blame] | 377 | private function fn2macblock(uint32_t fn) return uint8_t |
| 378 | { |
| 379 | return (fn mod 52) / 4; |
| 380 | } |
| 381 | |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 382 | /* Get first message from queue. true if non-empty, false otherwise */ |
| 383 | private function f_tx_data_ind_fn(integer bts_nr, integer fn) |
| 384 | runs on RAW_PCU_BTS_CT |
| 385 | { |
| 386 | var PCUIF_Message pcu_msg; |
| 387 | var boolean has_msg, use_msg; |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 388 | |
| 389 | for (var uint8_t ts_nr := 0; ts_nr < 8; ts_nr := ts_nr + 1) { |
Vadim Yanitskiy | 1da1fef | 2021-03-23 04:28:18 +0100 | [diff] [blame] | 390 | for (var integer trx_nr := 0; trx_nr < lengthof(g_info_ind.trx); trx_nr := trx_nr + 1) { |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 391 | //var charstring prefix := "BTS=" & int2str(bts_nr) & ",TRX=" & int2str(trx_nr) & ",TS=" & int2str(ts_nr) & ",FN=" & int2str(fn) & ": "; |
Vadim Yanitskiy | 1da1fef | 2021-03-23 04:28:18 +0100 | [diff] [blame] | 392 | if (g_info_ind.trx[trx_nr].pdch_mask[ts_nr] == '0'B) { |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 393 | //log(prefix, "disabled"); |
| 394 | continue; /* TRX+TS not activated */ |
| 395 | } |
| 396 | |
| 397 | /* Check if we reached time to serve the first DATA.ind message in the queue: */ |
| 398 | has_msg := f_PCUIF_MsgQueue_first(pdtch_data_queue, pcu_msg) and |
| 399 | pcu_msg.u.data_ind.trx_nr == trx_nr and |
| 400 | pcu_msg.u.data_ind.ts_nr == ts_nr; |
| 401 | use_msg := has_msg and (pcu_msg.u.data_ind.fn == 0 or pcu_msg.u.data_ind.fn == fn); |
| 402 | if (use_msg) { |
| 403 | /* Dequeue a DATA.ind message */ |
| 404 | f_PCUIF_MsgQueue_dequeue(pdtch_data_queue, pcu_msg); |
| 405 | /* Patch TDMA frame / block number */ |
| 406 | pcu_msg.u.data_ind.fn := fn; |
Pau Espin Pedrol | 9fc065a | 2021-05-11 17:05:39 +0200 | [diff] [blame] | 407 | pcu_msg.u.data_ind.block_nr := fn2macblock(fn); |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 408 | //log(prefix, "DATA.ind"); |
| 409 | } else if (has_msg and pcu_msg.u.data_ind.fn < fn) { |
| 410 | setverdict(fail, "We are late scheduling the block! ", pcu_msg.u.data_ind.fn, " < ", fn); |
| 411 | mtc.stop; |
| 412 | } else { |
| 413 | /* NOPE.ind: */ |
| 414 | pcu_msg := valueof(ts_PCUIF_DATA_IND(bts_nr, trx_nr, ts_nr, 0 /* FIXME */, |
| 415 | PCU_IF_SAPI_PDTCH, ''O, fn, |
Vadim Yanitskiy | 1da1fef | 2021-03-23 04:28:18 +0100 | [diff] [blame] | 416 | g_info_ind.trx[trx_nr].arfcn, |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 417 | rssi := -80, ber10k := 0, |
| 418 | ta_offs_qbits := 0, lqual_cb := 10)); |
| 419 | //log(prefix, "DATA.ind (len=0)"); |
| 420 | } |
| 421 | |
| 422 | if (use_msg or mp_send_all_data_ind) { |
| 423 | PCUIF.send(pcu_msg); /* Send to the PCU and notify the TC */ |
| 424 | if (use_msg) { |
| 425 | TC.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_SENT, fn)); |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | |
Pau Espin Pedrol | 65bab9e | 2019-12-04 21:05:10 +0100 | [diff] [blame] | 432 | /* Handle schedule events and manage actions: Send msgs over PCUIF to PCU, |
| 433 | * advertise Test Case about sent messages, etc. */ |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 434 | private altstep as_BTS_CT_TDMASched(integer bts_nr) |
| 435 | runs on RAW_PCU_BTS_CT { |
| 436 | var PCUIF_Message pcu_msg; |
| 437 | var RAW_PCU_Event event; |
Pau Espin Pedrol | 6072725 | 2019-12-04 21:40:25 +0100 | [diff] [blame] | 438 | var integer ev_begin_fn; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 439 | |
| 440 | [] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_BEG)) -> value event { |
| 441 | /* If the RTS queue for PDTCH is not empty, send a message */ |
| 442 | if (lengthof(pdtch_rts_queue) > 0) { |
| 443 | f_PCUIF_MsgQueue_dequeue(pdtch_rts_queue, pcu_msg); |
| 444 | |
| 445 | /* Patch TDMA frame / block number and send */ |
| 446 | pcu_msg.u.rts_req.fn := event.data.tdma_fn; |
Pau Espin Pedrol | 9fc065a | 2021-05-11 17:05:39 +0200 | [diff] [blame] | 447 | pcu_msg.u.rts_req.block_nr := fn2macblock(event.data.tdma_fn); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 448 | PCUIF.send(pcu_msg); |
| 449 | } |
| 450 | |
| 451 | /* We don't really need to send every frame to OsmoPCU, because |
| 452 | * it omits frame numbers not starting at a MAC block. */ |
| 453 | PCUIF.send(ts_PCUIF_TIME_IND(bts_nr, event.data.tdma_fn)); |
| 454 | repeat; |
| 455 | } |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 456 | [] 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] | 457 | /* FN matching the beginning of current block: */ |
| 458 | ev_begin_fn := event.data.tdma_fn - 3; |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 459 | f_tx_data_ind_fn(bts_nr, ev_begin_fn); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 460 | repeat; |
| 461 | } |
| 462 | [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] | 463 | /* FN matching the beginning of current block (PTCCH is interleaved over 4 non-consecutive bursts): */ |
| 464 | ev_begin_fn := event.data.tdma_fn - 78; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 465 | /* Dequeue an RTS.req message for PTCCH */ |
| 466 | f_PCUIF_MsgQueue_dequeue(ptcch_rts_queue, pcu_msg); |
| 467 | |
| 468 | /* Patch TDMA frame / block number and send */ |
Pau Espin Pedrol | 6072725 | 2019-12-04 21:40:25 +0100 | [diff] [blame] | 469 | pcu_msg.u.rts_req.fn := ev_begin_fn; |
Pau Espin Pedrol | 9fc065a | 2021-05-11 17:05:39 +0200 | [diff] [blame] | 470 | pcu_msg.u.rts_req.block_nr := fn2macblock(ev_begin_fn); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 471 | PCUIF.send(pcu_msg); |
| 472 | repeat; |
| 473 | } |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 474 | /* Optional forwarding of PTCCH/U burst indications to the test case */ |
| 475 | [cfg_ptcch_burst_fwd] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PTCCH_UL_BURST)) -> value event { |
| 476 | TC.send(event); |
| 477 | repeat; |
| 478 | } |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 479 | /* Ignore other clock events (and guard against an empty queue) */ |
| 480 | [] CLCK.receive(tr_RAW_PCU_CLCK_EV) { repeat; } |
| 481 | } |
| 482 | |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 483 | 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] | 484 | runs on RAW_PCU_BTS_CT { |
| 485 | var PCUIF_Message pcu_msg; |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 486 | var RAW_PCU_Command cmd; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 487 | var RAW_PCU_Event event; |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 488 | var BTS_PDTCH_Block pcu_msg_pdtch; |
| 489 | var BTS_PTCCH_Block pcu_msg_ptcch; |
| 490 | var BTS_CCCH_Block pcu_msg_rr; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 491 | |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 492 | g_info_ind := info_ind; |
| 493 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 494 | /* Init TDMA clock generator (so we can stop and start it) */ |
| 495 | vc_CLCK_GEN := RAW_PCU_ClckGen_CT.create("ClckGen-" & int2str(bts_nr)) alive; |
| 496 | connect(vc_CLCK_GEN:CLCK, self:CLCK); |
| 497 | |
| 498 | /* Wait until the PCU is connected */ |
| 499 | PCUIF.receive(tr_RAW_PCU_EV(PCU_EV_CONNECT)); |
| 500 | |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 501 | 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] | 502 | alt { |
| 503 | /* Wait for TXT.ind (PCU_VERSION) and respond with INFO.ind (SI13) */ |
| 504 | [] PCUIF.receive(tr_PCUIF_TXT_IND(bts_nr, PCU_VERSION, ?)) -> value pcu_msg { |
| 505 | log("Rx TXT.ind from the PCU, version is ", pcu_msg.u.txt_ind.text); |
| 506 | |
| 507 | /* Send System Information 13 to the PCU */ |
| 508 | PCUIF.send(PCUIF_Message:{ |
| 509 | msg_type := PCU_IF_MSG_INFO_IND, |
| 510 | bts_nr := bts_nr, |
| 511 | spare := '0000'O, |
| 512 | u := { info_ind := info_ind } |
| 513 | }); |
| 514 | |
Pau Espin Pedrol | c62ebac | 2021-03-12 15:07:06 +0100 | [diff] [blame] | 515 | const integer start_fn := 0; |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 516 | if (mp_send_all_data_ind) { |
| 517 | f_tx_first_data_ind(bts_nr, info_ind, start_fn); |
| 518 | } |
| 519 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 520 | /* Notify the test case that we're done with SI13 */ |
| 521 | TC.send(ts_RAW_PCU_EV(BTS_EV_SI13_NEGO)); |
| 522 | |
| 523 | /* Start feeding clock to the PCU */ |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 524 | vc_CLCK_GEN.start(f_ClckGen_CT_handler(start_fn)); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 525 | repeat; |
| 526 | } |
Pau Espin Pedrol | d16bb27 | 2019-12-02 12:57:03 +0100 | [diff] [blame] | 527 | /* PCU -> TS becomes active */ |
| 528 | [] PCUIF.receive(tr_PCUIF_ACT_REQ(bts_nr, ?, ?)) -> value pcu_msg { |
| 529 | log("Rx ACT.req from the PCU: TRX" & int2str(pcu_msg.u.act_req.trx_nr) & |
| 530 | "/TS" & int2str(pcu_msg.u.act_req.ts_nr)); |
| 531 | repeat; |
| 532 | } |
| 533 | /* PCU -> TS becomes inactive */ |
| 534 | [] PCUIF.receive(tr_PCUIF_DEACT_REQ(bts_nr, ?, ?)) -> value pcu_msg { |
| 535 | log("Rx DEACT.req from the PCU: TRX" & int2str(pcu_msg.u.act_req.trx_nr) & |
| 536 | "/TS" & int2str(pcu_msg.u.act_req.ts_nr)); |
| 537 | repeat; |
| 538 | } |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 539 | [decode_data_req] PCUIF.receive(tr_PCUIF_DATA_REQ(bts_nr, ?, ?, sapi := tr_ccch_sapi)) -> value pcu_msg { |
| 540 | var octetstring data; |
| 541 | /* On PCH the payload is prefixed with paging group (3 octets): skip it. |
| 542 | * TODO: add an additional template parameter, so we can match it. */ |
| 543 | if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_PCH) { |
| 544 | data := substr(pcu_msg.u.data_req.data, 3, pcu_msg.u.data_req.len - 3); |
| 545 | } else if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_AGCH) { |
| 546 | data := pcu_msg.u.data_req.data; |
| 547 | } |
| 548 | pcu_msg_rr.bts_nr := bts_nr; |
| 549 | pcu_msg_rr.raw := pcu_msg.u.data_req; |
| 550 | pcu_msg_rr.rr_msg := dec_GsmRrMessage(data); |
| 551 | TC.send(pcu_msg_rr); |
| 552 | repeat; |
| 553 | } |
| 554 | [decode_data_req] PCUIF.receive(tr_PCUIF_DATA_REQ(bts_nr, ?, ?, sapi := PCU_IF_SAPI_PDTCH)) -> value pcu_msg { |
| 555 | pcu_msg_pdtch.bts_nr := bts_nr; |
| 556 | pcu_msg_pdtch.raw := pcu_msg.u.data_req; |
Pau Espin Pedrol | cf2ada5 | 2021-09-22 14:11:44 +0200 | [diff] [blame] | 557 | if (pcu_msg_pdtch.raw.len != 0) { |
| 558 | pcu_msg_pdtch.dl_block := dec_RlcmacDlBlock(pcu_msg_pdtch.raw.data); |
| 559 | } else { |
| 560 | pcu_msg_pdtch.dl_block := omit; |
| 561 | } |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 562 | TC.send(pcu_msg_pdtch); |
| 563 | repeat; |
| 564 | } |
| 565 | [decode_data_req] PCUIF.receive(tr_PCUIF_DATA_REQ(bts_nr, ?, ?, sapi := PCU_IF_SAPI_PTCCH)) -> value pcu_msg { |
| 566 | pcu_msg_ptcch.bts_nr := bts_nr; |
| 567 | pcu_msg_ptcch.raw := pcu_msg.u.data_req; |
Pau Espin Pedrol | cf2ada5 | 2021-09-22 14:11:44 +0200 | [diff] [blame] | 568 | if (pcu_msg_ptcch.raw.len != 0) { |
| 569 | pcu_msg_ptcch.dl_block := dec_PTCCHDownlinkMsg(pcu_msg_ptcch.raw.data); |
| 570 | } else { |
| 571 | pcu_msg_ptcch.dl_block := omit; |
| 572 | } |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 573 | TC.send(pcu_msg_ptcch); |
| 574 | repeat; |
| 575 | } |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 576 | /* PCU -> test case forwarding (filter by the BTS number) */ |
| 577 | [] PCUIF.receive(tr_PCUIF_MSG(?, bts_nr)) -> value pcu_msg { |
| 578 | TC.send(pcu_msg); |
| 579 | repeat; |
| 580 | } |
| 581 | |
| 582 | /* TC -> [Queue] -> PCU forwarding */ |
| 583 | [] as_BTS_CT_MsgQueue(bts_nr); |
| 584 | /* TDMA scheduler (clock and queue handling) */ |
| 585 | [] as_BTS_CT_TDMASched(bts_nr); |
| 586 | |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 587 | /* Command handling */ |
Vadim Yanitskiy | 91f8a09 | 2020-05-06 21:41:05 +0700 | [diff] [blame] | 588 | [] TC.receive(tr_RAW_PCU_CMD(GENERAL_CMD_SHUTDOWN)) { |
| 589 | log("Shutting down virtual BTS #", bts_nr, "..."); |
| 590 | vc_CLCK_GEN.stop; |
| 591 | break; |
| 592 | } |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 593 | [] TC.receive(tr_RAW_PCU_CMD(TDMA_CMD_ENABLE_PTCCH_UL_FWD)) { |
| 594 | log("Enabling forwarding of PTCCH/U TDMA events to the TC"); |
| 595 | cfg_ptcch_burst_fwd := true; |
| 596 | repeat; |
| 597 | } |
| 598 | [] TC.receive(tr_RAW_PCU_CMD) -> value cmd { |
| 599 | log("Ignore unhandled command: ", cmd); |
| 600 | repeat; |
| 601 | } |
| 602 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 603 | /* TODO: handle events (e.g. disconnection) from the PCU interface */ |
| 604 | [] PCUIF.receive(tr_RAW_PCU_EV) -> value event { |
| 605 | log("Ignore unhandled event: ", event); |
| 606 | repeat; |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | /* PCU interface (UNIX domain socket) handler */ |
| 612 | type component RAW_PCUIF_CT { |
| 613 | var ConnectionId g_pcu_conn_id := -1; |
| 614 | var boolean g_pcu_connected := false; |
| 615 | port PCUIF_CODEC_PT PCU; |
| 616 | |
| 617 | /* Connection towards BTS component(s) */ |
| 618 | port RAW_PCU_MSG_PT BTS; |
| 619 | /* Connection to the MTC (test case) */ |
| 620 | port RAW_PCU_MSG_PT MTC; |
| 621 | }; |
| 622 | |
| 623 | /* All received messages and events from OsmoPCU can be additionally sent |
| 624 | * directly to the MTC component. Pass direct := true to enable this mode. */ |
| 625 | function f_PCUIF_CT_handler(charstring pcu_sock_path, boolean direct := false) |
| 626 | runs on RAW_PCUIF_CT { |
| 627 | var PCUIF_send_data pcu_sd_msg; |
| 628 | var PCUIF_Message pcu_msg; |
| 629 | timer T_Conn := 10.0; |
| 630 | |
| 631 | log("Init PCU interface on '" & pcu_sock_path & "', waiting for connection..."); |
| 632 | g_pcu_conn_id := f_pcuif_listen(PCU, pcu_sock_path); |
| 633 | |
| 634 | /* Wait for connection */ |
| 635 | T_Conn.start; |
| 636 | alt { |
| 637 | [not g_pcu_connected] PCU.receive(UD_connected:?) { |
| 638 | log("OsmoPCU is now connected"); |
| 639 | /* Duplicate this event to the MTC if requested */ |
| 640 | if (direct) { MTC.send(ts_RAW_PCU_EV(PCU_EV_CONNECT)); } |
| 641 | BTS.send(ts_RAW_PCU_EV(PCU_EV_CONNECT)); |
| 642 | g_pcu_connected := true; |
| 643 | setverdict(pass); |
| 644 | T_Conn.stop; |
| 645 | repeat; |
| 646 | } |
| 647 | /* PCU -> BTS / MTC message forwarding */ |
| 648 | [g_pcu_connected] PCU.receive(PCUIF_send_data:?) -> value pcu_sd_msg { |
| 649 | /* Send to the BTSes if at least one is connected */ |
| 650 | if (BTS.checkstate("Connected")) { BTS.send(pcu_sd_msg.data); } |
| 651 | /* Duplicate this message to the MTC if requested */ |
| 652 | if (direct) { MTC.send(pcu_sd_msg.data); } |
| 653 | repeat; |
| 654 | } |
| 655 | /* MTC -> PCU message forwarding */ |
| 656 | [g_pcu_connected] MTC.receive(PCUIF_Message:?) -> value pcu_msg { |
| 657 | PCU.send(t_SD_PCUIF(g_pcu_conn_id, pcu_msg)); |
| 658 | repeat; |
| 659 | } |
| 660 | /* BTS -> PCU message forwarding */ |
| 661 | [g_pcu_connected] BTS.receive(PCUIF_Message:?) -> value pcu_msg { |
| 662 | PCU.send(t_SD_PCUIF(g_pcu_conn_id, pcu_msg)); |
| 663 | repeat; |
| 664 | } |
| 665 | [not g_pcu_connected] MTC.receive(PCUIF_Message:?) -> value pcu_msg { |
| 666 | log("PCU is not connected, dropping ", pcu_msg); |
| 667 | repeat; |
| 668 | } |
| 669 | [not g_pcu_connected] BTS.receive(PCUIF_Message:?) -> value pcu_msg { |
| 670 | log("PCU is not connected, dropping ", pcu_msg); |
| 671 | repeat; |
| 672 | } |
| 673 | /* TODO: handle disconnect and reconnect of the PCU */ |
| 674 | [] PCU.receive { |
| 675 | log("Unhandled message on PCU interface"); |
| 676 | repeat; |
| 677 | } |
| 678 | [not g_pcu_connected] T_Conn.timeout { |
| 679 | setverdict(fail, "Timeout waiting for PCU connection"); |
| 680 | mtc.stop; |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | } |