blob: bfe906826ebb0053741f2beba2980691f694fc50 [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.
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020014 */
15
16#pragma once
17
18#ifdef __cplusplus
19
20#include "tbf.h"
21
Pau Espin Pedrol8a35e642021-01-18 17:14:14 +010022#include <stdint.h>
23
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020024/*
25 * TBF instance
26 */
27
28enum tbf_dl_prio {
29 DL_PRIO_NONE,
30 DL_PRIO_SENT_DATA, /* the data has been sent and not (yet) nacked */
31 DL_PRIO_LOW_AGE, /* the age has reached the first threshold */
32 DL_PRIO_NEW_DATA, /* the data has not been sent yet or nacked */
33 DL_PRIO_HIGH_AGE, /* the age has reached the second threshold */
34 DL_PRIO_CONTROL, /* a control block needs to be sent */
35};
36
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020037struct gprs_rlcmac_dl_tbf : public gprs_rlcmac_tbf {
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010038 gprs_rlcmac_dl_tbf(struct gprs_rlcmac_bts *bts, GprsMs *ms);
Pau Espin Pedrol62e06f92021-07-26 17:27:51 +020039 ~gprs_rlcmac_dl_tbf();
Pau Espin Pedrolb3f23972020-10-23 21:00:23 +020040 gprs_rlc_window *window();
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020041
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020042 int rcvd_dl_ack(bool final_ack, unsigned first_bsn, struct bitvec *rbb);
Pau Espin Pedrol022f9e52020-11-16 18:49:39 +010043 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 +020044
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020045 void request_dl_ack();
Pau Espin Pedrol405d2d12021-07-29 18:14:07 +020046 bool need_poll_for_dl_ack_nack() const;
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020047 bool have_data() const;
48 int frames_since_last_poll(unsigned fn) const;
49 int frames_since_last_drain(unsigned fn) const;
50 bool keep_open(unsigned fn) const;
51 int release();
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020052 uint16_t window_size() const;
53 void set_window_size();
54 void update_coding_scheme_counter_dl(enum CodingScheme cs);
55
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020056 /* Please note that all variables here will be reset when changing
57 * from WAIT RELEASE back to FLOW state (re-use of TBF).
58 * All states that need reset must be in this struct, so this is why
59 * variables are in both (dl and ul) structs and not outside union.
60 */
61 int32_t m_tx_counter; /* count all transmitted blocks */
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020062 bool m_dl_ack_requested;
63 int32_t m_last_dl_poll_fn;
64 int32_t m_last_dl_drained_fn;
65
66 struct BandWidth {
67 struct timespec dl_bw_tv; /* timestamp for dl bw calculation */
68 uint32_t dl_bw_octets; /* number of octets since bw_tv */
69 uint32_t dl_throughput; /* throughput to be displayed in stats */
70
71 struct timespec dl_loss_tv; /* timestamp for loss calculation */
72 uint16_t dl_loss_lost; /* sum of lost packets */
73 uint16_t dl_loss_received; /* sum of received packets */
74
75 BandWidth();
76 } m_bw;
77
78 struct rate_ctr_group *m_dl_gprs_ctrs;
79 struct rate_ctr_group *m_dl_egprs_ctrs;
80
81protected:
82 struct ana_result {
83 unsigned received_packets;
84 unsigned lost_packets;
85 unsigned received_bytes;
86 unsigned lost_bytes;
87 };
88
Pau Espin Pedrol022f9e52020-11-16 18:49:39 +010089 int take_next_bsn(uint32_t fn, int previous_bsn, enum mcs_kind req_mcs_kind,
90 bool *may_combine);
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020091 bool restart_bsn_cycle();
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020092 int create_new_bsn(const uint32_t fn, enum CodingScheme cs);
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020093 struct msgb *create_dl_acked_block(const uint32_t fn, const uint8_t ts,
94 int index, int index2 = -1);
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020095 int update_window(unsigned first_bsn, const struct bitvec *rbb);
Pau Espin Pedrolefcb0462021-07-26 12:33:39 +020096 int rcvd_dl_final_ack();
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020097 bool dl_window_stalled() const;
98 void reuse_tbf();
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020099 int analyse_errors(char *show_rbb, uint8_t ssn, ana_result *res);
100 void schedule_next_frame();
101
102 enum egprs_rlc_dl_reseg_bsn_state egprs_dl_get_data
103 (int bsn, uint8_t **block_data);
104 unsigned int get_egprs_dl_spb_status(int bsn);
105 enum egprs_rlcmac_dl_spb get_egprs_dl_spb(int bsn);
106
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +0200107 /* Please note that all variables below will be reset when changing
108 * from WAIT RELEASE back to FLOW state (re-use of TBF).
109 * All states that need reset must be in this struct, so this is why
110 * variables are in both (dl and ul) structs and not outside union.
111 */
112 gprs_rlc_dl_window m_window;
113};
114
115inline uint16_t gprs_rlcmac_dl_tbf::window_size() const
116{
117 return m_window.ws();
118}
119
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100120#else /* ifdef __cplusplus */
121struct gprs_rlcmac_dl_tbf;
122#endif
123
124#ifdef __cplusplus
125extern "C" {
126#endif
Pau Espin Pedrol8a35e642021-01-18 17:14:14 +0100127struct gprs_rlcmac_bts;
128
Pau Espin Pedrol29b9f942022-10-27 14:53:16 +0200129struct gprs_rlcmac_dl_tbf *dl_tbf_alloc(struct gprs_rlcmac_bts *bts, struct GprsMs *ms,
130 int8_t use_trx, bool single_slot);
131
Pau Espin Pedrolcc30b052022-10-27 15:25:55 +0200132struct gprs_rlcmac_dl_tbf *tbf_as_dl_tbf(struct gprs_rlcmac_tbf *tbf);
Pau Espin Pedrol8a35e642021-01-18 17:14:14 +0100133/* dispatch Unitdata.DL messages */
134int dl_tbf_handle(struct gprs_rlcmac_bts *bts,
135 const uint32_t tlli, const uint32_t old_tlli,
136 const char *imsi, const uint8_t ms_class,
137 const uint8_t egprs_ms_class, const uint16_t delay_csec,
138 const uint8_t *data, const uint16_t len);
139
Pau Espin Pedrolee350082022-10-28 17:35:03 +0200140void dl_tbf_trigger_ass_on_pacch(struct gprs_rlcmac_dl_tbf *tbf, struct gprs_rlcmac_tbf *old_tbf);
141void dl_tbf_trigger_ass_on_pch(struct gprs_rlcmac_dl_tbf *tbf);
Pau Espin Pedrol8fa3e062022-10-28 17:38:52 +0200142void dl_tbf_request_dl_ack(struct gprs_rlcmac_dl_tbf *tbf);
Pau Espin Pedrola161bf42021-07-30 13:42:06 +0200143
Pau Espin Pedrolbd1f01f2022-10-27 15:19:39 +0200144static inline struct gprs_rlcmac_tbf *dl_tbf_as_tbf(struct gprs_rlcmac_dl_tbf *dl_tbf)
145{
146 return (struct gprs_rlcmac_tbf *)dl_tbf;
147}
148
149static inline const struct gprs_rlcmac_tbf *dl_tbf_as_tbf_const(const struct gprs_rlcmac_dl_tbf *dl_tbf)
150{
151 return (const struct gprs_rlcmac_tbf *)dl_tbf;
152}
153
154#define LOGPTBFDL(dl_tbf, level, fmt, args...) LOGP(DTBFDL, level, "%s " fmt, tbf_name(dl_tbf_as_tbf_const(dl_tbf)), ## args)
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100155#ifdef __cplusplus
156}
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +0200157#endif