Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
| 3 | * Copyright (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #pragma once |
| 17 | |
| 18 | #ifdef __cplusplus |
| 19 | |
| 20 | #include "tbf.h" |
| 21 | |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 22 | #include <stdint.h> |
| 23 | |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | #include <tbf_fsm.h> |
| 28 | #ifdef __cplusplus |
| 29 | } |
| 30 | #endif |
| 31 | |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 32 | /* |
| 33 | * TBF instance |
| 34 | */ |
| 35 | |
| 36 | enum tbf_dl_prio { |
| 37 | DL_PRIO_NONE, |
| 38 | DL_PRIO_SENT_DATA, /* the data has been sent and not (yet) nacked */ |
| 39 | DL_PRIO_LOW_AGE, /* the age has reached the first threshold */ |
| 40 | DL_PRIO_NEW_DATA, /* the data has not been sent yet or nacked */ |
| 41 | DL_PRIO_HIGH_AGE, /* the age has reached the second threshold */ |
| 42 | DL_PRIO_CONTROL, /* a control block needs to be sent */ |
| 43 | }; |
| 44 | |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 45 | struct gprs_rlcmac_dl_tbf : public gprs_rlcmac_tbf { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 46 | gprs_rlcmac_dl_tbf(struct gprs_rlcmac_bts *bts, GprsMs *ms); |
Pau Espin Pedrol | 62e06f9 | 2021-07-26 17:27:51 +0200 | [diff] [blame] | 47 | ~gprs_rlcmac_dl_tbf(); |
Pau Espin Pedrol | b3f2397 | 2020-10-23 21:00:23 +0200 | [diff] [blame] | 48 | gprs_rlc_window *window(); |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 49 | |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 50 | int rcvd_dl_ack(bool final_ack, unsigned first_bsn, struct bitvec *rbb); |
Pau Espin Pedrol | d29a143 | 2022-12-15 18:57:35 +0100 | [diff] [blame] | 51 | struct msgb *create_dl_acked_block(uint32_t fn, const gprs_rlcmac_pdch *pdch, |
| 52 | enum mcs_kind req_mcs_kind = EGPRS); |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 53 | |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 54 | void request_dl_ack(); |
Pau Espin Pedrol | 405d2d1 | 2021-07-29 18:14:07 +0200 | [diff] [blame] | 55 | bool need_poll_for_dl_ack_nack() const; |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 56 | bool have_data() const; |
| 57 | int frames_since_last_poll(unsigned fn) const; |
| 58 | int frames_since_last_drain(unsigned fn) const; |
| 59 | bool keep_open(unsigned fn) const; |
| 60 | int release(); |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 61 | uint16_t window_size() const; |
| 62 | void set_window_size(); |
| 63 | void update_coding_scheme_counter_dl(enum CodingScheme cs); |
| 64 | |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 65 | /* Please note that all variables here will be reset when changing |
| 66 | * from WAIT RELEASE back to FLOW state (re-use of TBF). |
| 67 | * All states that need reset must be in this struct, so this is why |
| 68 | * variables are in both (dl and ul) structs and not outside union. |
| 69 | */ |
| 70 | int32_t m_tx_counter; /* count all transmitted blocks */ |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 71 | bool m_dl_ack_requested; |
| 72 | int32_t m_last_dl_poll_fn; |
| 73 | int32_t m_last_dl_drained_fn; |
| 74 | |
| 75 | struct BandWidth { |
| 76 | struct timespec dl_bw_tv; /* timestamp for dl bw calculation */ |
| 77 | uint32_t dl_bw_octets; /* number of octets since bw_tv */ |
| 78 | uint32_t dl_throughput; /* throughput to be displayed in stats */ |
| 79 | |
| 80 | struct timespec dl_loss_tv; /* timestamp for loss calculation */ |
| 81 | uint16_t dl_loss_lost; /* sum of lost packets */ |
| 82 | uint16_t dl_loss_received; /* sum of received packets */ |
| 83 | |
| 84 | BandWidth(); |
| 85 | } m_bw; |
| 86 | |
| 87 | struct rate_ctr_group *m_dl_gprs_ctrs; |
| 88 | struct rate_ctr_group *m_dl_egprs_ctrs; |
| 89 | |
Pau Espin Pedrol | 343c0ee | 2022-11-17 19:55:08 +0100 | [diff] [blame] | 90 | struct tbf_dl_fsm_ctx state_fsm; |
| 91 | |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 92 | protected: |
| 93 | struct ana_result { |
| 94 | unsigned received_packets; |
| 95 | unsigned lost_packets; |
| 96 | unsigned received_bytes; |
| 97 | unsigned lost_bytes; |
| 98 | }; |
| 99 | |
Pau Espin Pedrol | 022f9e5 | 2020-11-16 18:49:39 +0100 | [diff] [blame] | 100 | int take_next_bsn(uint32_t fn, int previous_bsn, enum mcs_kind req_mcs_kind, |
| 101 | bool *may_combine); |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 102 | bool restart_bsn_cycle(); |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 103 | int create_new_bsn(const uint32_t fn, enum CodingScheme cs); |
Pau Espin Pedrol | d29a143 | 2022-12-15 18:57:35 +0100 | [diff] [blame] | 104 | struct msgb *create_dl_acked_block(const uint32_t fn, const struct gprs_rlcmac_pdch *pdch, |
| 105 | int index, int index2 = -1); |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 106 | int update_window(unsigned first_bsn, const struct bitvec *rbb); |
Pau Espin Pedrol | efcb046 | 2021-07-26 12:33:39 +0200 | [diff] [blame] | 107 | int rcvd_dl_final_ack(); |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 108 | bool dl_window_stalled() const; |
| 109 | void reuse_tbf(); |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 110 | int analyse_errors(char *show_rbb, uint8_t ssn, ana_result *res); |
| 111 | void schedule_next_frame(); |
| 112 | |
| 113 | enum egprs_rlc_dl_reseg_bsn_state egprs_dl_get_data |
| 114 | (int bsn, uint8_t **block_data); |
| 115 | unsigned int get_egprs_dl_spb_status(int bsn); |
| 116 | enum egprs_rlcmac_dl_spb get_egprs_dl_spb(int bsn); |
| 117 | |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 118 | /* Please note that all variables below will be reset when changing |
| 119 | * from WAIT RELEASE back to FLOW state (re-use of TBF). |
| 120 | * All states that need reset must be in this struct, so this is why |
| 121 | * variables are in both (dl and ul) structs and not outside union. |
| 122 | */ |
| 123 | gprs_rlc_dl_window m_window; |
| 124 | }; |
| 125 | |
| 126 | inline uint16_t gprs_rlcmac_dl_tbf::window_size() const |
| 127 | { |
| 128 | return m_window.ws(); |
| 129 | } |
| 130 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 131 | #else /* ifdef __cplusplus */ |
| 132 | struct gprs_rlcmac_dl_tbf; |
| 133 | #endif |
| 134 | |
| 135 | #ifdef __cplusplus |
| 136 | extern "C" { |
| 137 | #endif |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 138 | struct gprs_rlcmac_bts; |
| 139 | |
Pau Espin Pedrol | 29b9f94 | 2022-10-27 14:53:16 +0200 | [diff] [blame] | 140 | struct gprs_rlcmac_dl_tbf *dl_tbf_alloc(struct gprs_rlcmac_bts *bts, struct GprsMs *ms, |
| 141 | int8_t use_trx, bool single_slot); |
| 142 | |
Pau Espin Pedrol | cc30b05 | 2022-10-27 15:25:55 +0200 | [diff] [blame] | 143 | struct gprs_rlcmac_dl_tbf *tbf_as_dl_tbf(struct gprs_rlcmac_tbf *tbf); |
Pau Espin Pedrol | 1e1275f | 2022-11-17 20:57:34 +0100 | [diff] [blame] | 144 | const struct gprs_rlcmac_dl_tbf *tbf_as_dl_tbf_const(const struct gprs_rlcmac_tbf *tbf); |
Pau Espin Pedrol | 8a35e64 | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 145 | /* dispatch Unitdata.DL messages */ |
| 146 | int dl_tbf_handle(struct gprs_rlcmac_bts *bts, |
| 147 | const uint32_t tlli, const uint32_t old_tlli, |
| 148 | const char *imsi, const uint8_t ms_class, |
| 149 | const uint8_t egprs_ms_class, const uint16_t delay_csec, |
| 150 | const uint8_t *data, const uint16_t len); |
| 151 | |
Pau Espin Pedrol | ee35008 | 2022-10-28 17:35:03 +0200 | [diff] [blame] | 152 | void dl_tbf_trigger_ass_on_pacch(struct gprs_rlcmac_dl_tbf *tbf, struct gprs_rlcmac_tbf *old_tbf); |
| 153 | void dl_tbf_trigger_ass_on_pch(struct gprs_rlcmac_dl_tbf *tbf); |
Pau Espin Pedrol | 8fa3e06 | 2022-10-28 17:38:52 +0200 | [diff] [blame] | 154 | void dl_tbf_request_dl_ack(struct gprs_rlcmac_dl_tbf *tbf); |
Pau Espin Pedrol | b7a2b59 | 2022-12-13 14:43:59 +0100 | [diff] [blame] | 155 | int dl_tbf_upgrade_to_multislot(struct gprs_rlcmac_dl_tbf *tbf); |
Pau Espin Pedrol | a161bf4 | 2021-07-30 13:42:06 +0200 | [diff] [blame] | 156 | |
Pau Espin Pedrol | bd1f01f | 2022-10-27 15:19:39 +0200 | [diff] [blame] | 157 | static inline struct gprs_rlcmac_tbf *dl_tbf_as_tbf(struct gprs_rlcmac_dl_tbf *dl_tbf) |
| 158 | { |
| 159 | return (struct gprs_rlcmac_tbf *)dl_tbf; |
| 160 | } |
| 161 | |
| 162 | static inline const struct gprs_rlcmac_tbf *dl_tbf_as_tbf_const(const struct gprs_rlcmac_dl_tbf *dl_tbf) |
| 163 | { |
| 164 | return (const struct gprs_rlcmac_tbf *)dl_tbf; |
| 165 | } |
| 166 | |
| 167 | #define LOGPTBFDL(dl_tbf, level, fmt, args...) LOGP(DTBFDL, level, "%s " fmt, tbf_name(dl_tbf_as_tbf_const(dl_tbf)), ## args) |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 168 | #ifdef __cplusplus |
| 169 | } |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 170 | #endif |