blob: 58d863b3484d7191a39ff4e96029450c60256104 [file] [log] [blame]
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +02001/*
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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#pragma once
21
22#ifdef __cplusplus
23
24#include "tbf.h"
25
Pau Espin Pedrol8a35e642021-01-18 17:14:14 +010026#include <stdint.h>
27
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020028/*
29 * TBF instance
30 */
31
32enum tbf_dl_prio {
33 DL_PRIO_NONE,
34 DL_PRIO_SENT_DATA, /* the data has been sent and not (yet) nacked */
35 DL_PRIO_LOW_AGE, /* the age has reached the first threshold */
36 DL_PRIO_NEW_DATA, /* the data has not been sent yet or nacked */
37 DL_PRIO_HIGH_AGE, /* the age has reached the second threshold */
38 DL_PRIO_CONTROL, /* a control block needs to be sent */
39};
40
41#define LOGPTBFDL(tbf, level, fmt, args...) LOGP(DTBFDL, level, "%s " fmt, tbf_name(tbf), ## args)
42
43struct gprs_rlcmac_dl_tbf : public gprs_rlcmac_tbf {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010044 gprs_rlcmac_dl_tbf(struct gprs_rlcmac_bts *bts, GprsMs *ms);
Pau Espin Pedrolb3f23972020-10-23 21:00:23 +020045 gprs_rlc_window *window();
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020046 void cleanup();
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020047
Pau Espin Pedrol758ace82020-10-28 19:58:17 +010048 int append_data(uint16_t pdu_delay_csec,
49 const uint8_t *data, uint16_t len);
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020050
51 int rcvd_dl_ack(bool final, uint8_t ssn, uint8_t *rbb);
52 int rcvd_dl_ack(bool final_ack, unsigned first_bsn, struct bitvec *rbb);
Pau Espin Pedrol022f9e52020-11-16 18:49:39 +010053 struct msgb *create_dl_acked_block(uint32_t fn, uint8_t ts, enum mcs_kind req_mcs_kind = EGPRS);
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020054 void trigger_ass(struct gprs_rlcmac_tbf *old_tbf);
55
56 bool handle_ack_nack();
57 void request_dl_ack();
58 bool need_control_ts() const;
59 bool have_data() const;
60 int frames_since_last_poll(unsigned fn) const;
61 int frames_since_last_drain(unsigned fn) const;
62 bool keep_open(unsigned fn) const;
63 int release();
64 int abort();
65 uint16_t window_size() const;
66 void set_window_size();
67 void update_coding_scheme_counter_dl(enum CodingScheme cs);
68
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020069 struct msgb *llc_dequeue(bssgp_bvc_ctx *bctx);
70
71 /* Please note that all variables here will be reset when changing
72 * from WAIT RELEASE back to FLOW state (re-use of TBF).
73 * All states that need reset must be in this struct, so this is why
74 * variables are in both (dl and ul) structs and not outside union.
75 */
76 int32_t m_tx_counter; /* count all transmitted blocks */
77 uint8_t m_wait_confirm; /* wait for CCCH IMM.ASS cnf */
78 bool m_dl_ack_requested;
79 int32_t m_last_dl_poll_fn;
80 int32_t m_last_dl_drained_fn;
81
82 struct BandWidth {
83 struct timespec dl_bw_tv; /* timestamp for dl bw calculation */
84 uint32_t dl_bw_octets; /* number of octets since bw_tv */
85 uint32_t dl_throughput; /* throughput to be displayed in stats */
86
87 struct timespec dl_loss_tv; /* timestamp for loss calculation */
88 uint16_t dl_loss_lost; /* sum of lost packets */
89 uint16_t dl_loss_received; /* sum of received packets */
90
91 BandWidth();
92 } m_bw;
93
94 struct rate_ctr_group *m_dl_gprs_ctrs;
95 struct rate_ctr_group *m_dl_egprs_ctrs;
96
97protected:
98 struct ana_result {
99 unsigned received_packets;
100 unsigned lost_packets;
101 unsigned received_bytes;
102 unsigned lost_bytes;
103 };
104
Pau Espin Pedrol022f9e52020-11-16 18:49:39 +0100105 int take_next_bsn(uint32_t fn, int previous_bsn, enum mcs_kind req_mcs_kind,
106 bool *may_combine);
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +0200107 bool restart_bsn_cycle();
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200108 int create_new_bsn(const uint32_t fn, enum CodingScheme cs);
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +0200109 struct msgb *create_dl_acked_block(const uint32_t fn, const uint8_t ts,
110 int index, int index2 = -1);
111 int update_window(const uint8_t ssn, const uint8_t *rbb);
112 int update_window(unsigned first_bsn, const struct bitvec *rbb);
113 int maybe_start_new_window();
114 bool dl_window_stalled() const;
115 void reuse_tbf();
116 void start_llc_timer();
117 int analyse_errors(char *show_rbb, uint8_t ssn, ana_result *res);
118 void schedule_next_frame();
119
120 enum egprs_rlc_dl_reseg_bsn_state egprs_dl_get_data
121 (int bsn, uint8_t **block_data);
122 unsigned int get_egprs_dl_spb_status(int bsn);
123 enum egprs_rlcmac_dl_spb get_egprs_dl_spb(int bsn);
124
125 struct osmo_timer_list m_llc_timer;
126
127 /* Please note that all variables below will be reset when changing
128 * from WAIT RELEASE back to FLOW state (re-use of TBF).
129 * All states that need reset must be in this struct, so this is why
130 * variables are in both (dl and ul) structs and not outside union.
131 */
132 gprs_rlc_dl_window m_window;
133};
134
135inline uint16_t gprs_rlcmac_dl_tbf::window_size() const
136{
137 return m_window.ws();
138}
139
Pau Espin Pedrolb3859692020-10-23 22:37:52 +0200140struct gprs_rlcmac_dl_tbf *tbf_alloc_dl_tbf(struct gprs_rlcmac_bts *bts, GprsMs *ms,
141 int8_t use_trx, bool single_slot);
142
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100143#else /* ifdef __cplusplus */
144struct gprs_rlcmac_dl_tbf;
145#endif
146
147#ifdef __cplusplus
148extern "C" {
149#endif
Pau Espin Pedrol8a35e642021-01-18 17:14:14 +0100150struct gprs_rlcmac_bts;
151
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100152struct gprs_rlcmac_dl_tbf *as_dl_tbf(struct gprs_rlcmac_tbf *tbf);
Pau Espin Pedrol8a35e642021-01-18 17:14:14 +0100153/* dispatch Unitdata.DL messages */
154int dl_tbf_handle(struct gprs_rlcmac_bts *bts,
155 const uint32_t tlli, const uint32_t old_tlli,
156 const char *imsi, const uint8_t ms_class,
157 const uint8_t egprs_ms_class, const uint16_t delay_csec,
158 const uint8_t *data, const uint16_t len);
159
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100160#ifdef __cplusplus
161}
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +0200162#endif