blob: 10116654b0d5b4bf501e56345d859d10b4e3a72d [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
26/*
27 * TBF instance
28 */
29
30enum tbf_dl_prio {
31 DL_PRIO_NONE,
32 DL_PRIO_SENT_DATA, /* the data has been sent and not (yet) nacked */
33 DL_PRIO_LOW_AGE, /* the age has reached the first threshold */
34 DL_PRIO_NEW_DATA, /* the data has not been sent yet or nacked */
35 DL_PRIO_HIGH_AGE, /* the age has reached the second threshold */
36 DL_PRIO_CONTROL, /* a control block needs to be sent */
37};
38
39#define LOGPTBFDL(tbf, level, fmt, args...) LOGP(DTBFDL, level, "%s " fmt, tbf_name(tbf), ## args)
40
41struct gprs_rlcmac_dl_tbf : public gprs_rlcmac_tbf {
42 gprs_rlcmac_dl_tbf(BTS *bts);
43 gprs_rlc_dl_window *window();
44 void cleanup();
45 void enable_egprs();
46 /* dispatch Unitdata.DL messages */
47 static int handle(struct gprs_rlcmac_bts *bts,
48 const uint32_t tlli, const uint32_t old_tlli,
49 const char *imsi, const uint8_t ms_class,
50 const uint8_t egprs_ms_class, const uint16_t delay_csec,
51 const uint8_t *data, const uint16_t len);
52
53 int append_data(const uint8_t ms_class,
54 const uint16_t pdu_delay_csec,
55 const uint8_t *data, const uint16_t len);
56
57 int rcvd_dl_ack(bool final, uint8_t ssn, uint8_t *rbb);
58 int rcvd_dl_ack(bool final_ack, unsigned first_bsn, struct bitvec *rbb);
59 struct msgb *create_dl_acked_block(uint32_t fn, uint8_t ts);
60 void trigger_ass(struct gprs_rlcmac_tbf *old_tbf);
61
62 bool handle_ack_nack();
63 void request_dl_ack();
64 bool need_control_ts() const;
65 bool have_data() const;
66 int frames_since_last_poll(unsigned fn) const;
67 int frames_since_last_drain(unsigned fn) const;
68 bool keep_open(unsigned fn) const;
69 int release();
70 int abort();
71 uint16_t window_size() const;
72 void set_window_size();
73 void update_coding_scheme_counter_dl(enum CodingScheme cs);
74
75 /* TODO: add the gettimeofday as parameter */
76 struct msgb *llc_dequeue(bssgp_bvc_ctx *bctx);
77
78 /* Please note that all variables here will be reset when changing
79 * from WAIT RELEASE back to FLOW state (re-use of TBF).
80 * All states that need reset must be in this struct, so this is why
81 * variables are in both (dl and ul) structs and not outside union.
82 */
83 int32_t m_tx_counter; /* count all transmitted blocks */
84 uint8_t m_wait_confirm; /* wait for CCCH IMM.ASS cnf */
85 bool m_dl_ack_requested;
86 int32_t m_last_dl_poll_fn;
87 int32_t m_last_dl_drained_fn;
88
89 struct BandWidth {
90 struct timespec dl_bw_tv; /* timestamp for dl bw calculation */
91 uint32_t dl_bw_octets; /* number of octets since bw_tv */
92 uint32_t dl_throughput; /* throughput to be displayed in stats */
93
94 struct timespec dl_loss_tv; /* timestamp for loss calculation */
95 uint16_t dl_loss_lost; /* sum of lost packets */
96 uint16_t dl_loss_received; /* sum of received packets */
97
98 BandWidth();
99 } m_bw;
100
101 struct rate_ctr_group *m_dl_gprs_ctrs;
102 struct rate_ctr_group *m_dl_egprs_ctrs;
103
104protected:
105 struct ana_result {
106 unsigned received_packets;
107 unsigned lost_packets;
108 unsigned received_bytes;
109 unsigned lost_bytes;
110 };
111
112 int take_next_bsn(uint32_t fn, int previous_bsn,
113 bool *may_combine);
114 bool restart_bsn_cycle();
115 int create_new_bsn(const uint32_t fn, GprsCodingScheme cs);
116 struct msgb *create_dl_acked_block(const uint32_t fn, const uint8_t ts,
117 int index, int index2 = -1);
118 int update_window(const uint8_t ssn, const uint8_t *rbb);
119 int update_window(unsigned first_bsn, const struct bitvec *rbb);
120 int maybe_start_new_window();
121 bool dl_window_stalled() const;
122 void reuse_tbf();
123 void start_llc_timer();
124 int analyse_errors(char *show_rbb, uint8_t ssn, ana_result *res);
125 void schedule_next_frame();
126
127 enum egprs_rlc_dl_reseg_bsn_state egprs_dl_get_data
128 (int bsn, uint8_t **block_data);
129 unsigned int get_egprs_dl_spb_status(int bsn);
130 enum egprs_rlcmac_dl_spb get_egprs_dl_spb(int bsn);
131
132 struct osmo_timer_list m_llc_timer;
133
134 /* Please note that all variables below will be reset when changing
135 * from WAIT RELEASE back to FLOW state (re-use of TBF).
136 * All states that need reset must be in this struct, so this is why
137 * variables are in both (dl and ul) structs and not outside union.
138 */
139 gprs_rlc_dl_window m_window;
140};
141
142inline uint16_t gprs_rlcmac_dl_tbf::window_size() const
143{
144 return m_window.ws();
145}
146
147inline void gprs_rlcmac_dl_tbf::enable_egprs()
148{
149 m_window.set_sns(RLC_EGPRS_SNS);
150 gprs_rlcmac_tbf::enable_egprs();
151}
152
153inline gprs_rlcmac_dl_tbf *as_dl_tbf(gprs_rlcmac_tbf *tbf)
154{
155 if (tbf && tbf->direction == GPRS_RLCMAC_DL_TBF)
156 return static_cast<gprs_rlcmac_dl_tbf *>(tbf);
157 else
158 return NULL;
159}
160#endif