A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-rate-ops.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Natale Patriciello <natale.patriciello@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
18#ifndef TCP_RATE_OPS_H
19#define TCP_RATE_OPS_H
20
21#include "tcp-tx-item.h"
22
23#include "ns3/data-rate.h"
24#include "ns3/object.h"
25#include "ns3/traced-callback.h"
26#include "ns3/traced-value.h"
27
28namespace ns3
29{
30
31/**
32 * \brief Interface for all operations that involve a Rate monitoring for TCP.
33 *
34 * The interface is meant to take information to generate rate information
35 * valid for congestion avoidance algorithm such as BBR.
36 *
37 * Please take a look to the TcpRateLinux class for an example.
38 */
39class TcpRateOps : public Object
40{
41 public:
42 struct TcpRateSample;
43 struct TcpRateConnection;
44
45 /**
46 * Get the type ID.
47 * \brief Get the type ID.
48 * \return the object TypeId
49 */
50 static TypeId GetTypeId();
51 /**
52 * \brief Put the rate information inside the sent skb
53 *
54 * Snapshot the current delivery information in the skb, to generate
55 * a rate sample later when the skb is (s)acked in SkbDelivered ().
56 *
57 * \param skb The SKB sent
58 * \param isStartOfTransmission true if this is a start of transmission
59 * (i.e., in_flight == 0)
60 */
61 virtual void SkbSent(TcpTxItem* skb, bool isStartOfTransmission) = 0;
62
63 /**
64 * \brief Update the Rate information after an item is received
65 *
66 * When an skb is sacked or acked, we fill in the rate sample with the (prior)
67 * delivery information when the skb was last transmitted.
68 *
69 * If an ACK (s)acks multiple skbs (e.g., stretched-acks), this function is
70 * called multiple times. We favor the information from the most recently
71 * sent skb, i.e., the skb with the highest prior_delivered count.
72 *
73 * \param skb The SKB delivered ((s)ACKed)
74 */
75 virtual void SkbDelivered(TcpTxItem* skb) = 0;
76
77 /**
78 * \brief If a gap is detected between sends, it means we are app-limited.
79 * TODO What the Linux kernel is setting in tp->app_limited?
80 * https://elixir.bootlin.com/linux/latest/source/net/ipv4/tcp_rate.c#L177
81 *
82 * \param cWnd Congestion Window
83 * \param in_flight In Flight size (in bytes)
84 * \param segmentSize Segment size
85 * \param tailSeq Tail Sequence
86 * \param nextTx NextTx
87 * \param lostOut Number of lost bytes
88 * \param retransOut Number of retransmitted bytes
89 */
90 virtual void CalculateAppLimited(uint32_t cWnd,
91 uint32_t in_flight,
93 const SequenceNumber32& tailSeq,
94 const SequenceNumber32& nextTx,
95 const uint32_t lostOut,
96 const uint32_t retransOut) = 0;
97
98 /**
99 *
100 * \brief Generate a TcpRateSample to feed a congestion avoidance algorithm.
101 *
102 * This function will be called after an ACK (or a SACK) is received. The
103 * (S)ACK carries some implicit information, such as how many segments have been
104 * lost or delivered. These values will be this function input.
105 *
106 * \param delivered number of delivered segments (e.g., receiving a cumulative
107 * ACK means having more than 1 segment delivered) relative to the most recent
108 * (S)ACK received
109 * \param lost number of segments that we detected as lost after the reception
110 * of the most recent (S)ACK
111 * \param priorInFlight number of segments previously considered in flight
112 * \param is_sack_reneg Is SACK reneged?
113 * \param minRtt Minimum RTT so far
114 * \return The TcpRateSample that will be used for CA
115 */
116 virtual const TcpRateSample& GenerateSample(uint32_t delivered,
117 uint32_t lost,
118 bool is_sack_reneg,
119 uint32_t priorInFlight,
120 const Time& minRtt) = 0;
121
122 /**
123 * \return The information about the rate connection
124 *
125 */
127
128 /**
129 * \brief Rate Sample structure
130 *
131 * A rate sample measures the number of (original/retransmitted) data
132 * packets delivered "delivered" over an interval of time "interval_us".
133 * The tcp_rate code fills in the rate sample, and congestion
134 * control modules that define a cong_control function to run at the end
135 * of ACK processing can optionally chose to consult this sample when
136 * setting cwnd and pacing rate.
137 * A sample is invalid if "delivered" or "interval_us" is negative.
138 */
140 {
141 DataRate m_deliveryRate{DataRate("0bps")}; //!< The delivery rate sample
142 bool m_isAppLimited{false}; //!< Indicates whether the rate sample is application-limited
143 Time m_interval{Seconds(0.0)}; //!< The length of the sampling interval
145 0}; //!< The amount of data marked as delivered over the sampling interval
146 uint32_t m_priorDelivered{0}; //!< The delivered count of the most recent packet delivered
147 Time m_priorTime{Seconds(0.0)}; //!< The delivered time of the most recent packet delivered
149 Seconds(0.0)}; //!< Send time interval calculated from the most recent packet delivered
151 Seconds(0.0)}; //!< ACK time interval calculated from the most recent packet delivered
153 0}; //!< The amount of data marked as lost from the most recent ack received
154 uint32_t m_priorInFlight{0}; //!< The value if bytes in flight prior to last received ack
155 uint32_t m_ackedSacked{0}; //!< The amount of data acked and sacked in the last received ack
156
157 /**
158 * \brief Is the sample valid?
159 * \return true if the sample is valid, false otherwise.
160 */
161 bool IsValid() const
162 {
163 return (m_priorTime != Seconds(0.0) || m_interval != Seconds(0.0));
164 }
165 };
166
167 /**
168 * \brief Information about the connection rate
169 *
170 * In this struct, the values are for the entire connection, and not just
171 * for an interval of time
172 */
174 {
175 uint64_t m_delivered{0}; //!< The total amount of data in bytes delivered so far
176 Time m_deliveredTime{Seconds(0)}; //!< Simulator time when m_delivered was last updated
178 Seconds(0)}; //!< The send time of the packet that was most recently marked as delivered
180 0}; //!< The index of the last transmitted packet marked as application-limited
181 uint32_t m_txItemDelivered{0}; //!< The value of delivered when the acked item was sent
183 0}; //!< The amount of data delivered considered to calculate delivery rate.
185 Seconds(0)}; //!< The value of interval considered to calculate delivery rate.
186 bool m_rateAppLimited{false}; //!< Was sample was taken when data is app limited?
187 };
188};
189
190/**
191 * \brief Linux management and generation of Rate information for TCP
192 *
193 * This class is inspired by what Linux is performing in tcp_rate.c
194 */
196{
197 public:
198 /**
199 * Get the type ID.
200 * \brief Get the type ID.
201 * \return the object TypeId
202 */
203 static TypeId GetTypeId();
204
205 ~TcpRateLinux() override
206 {
207 }
208
209 void SkbSent(TcpTxItem* skb, bool isStartOfTransmission) override;
210 void SkbDelivered(TcpTxItem* skb) override;
212 uint32_t in_flight,
214 const SequenceNumber32& tailSeq,
215 const SequenceNumber32& nextTx,
216 const uint32_t lostOut,
217 const uint32_t retransOut) override;
218 const TcpRateSample& GenerateSample(uint32_t delivered,
219 uint32_t lost,
220 bool is_sack_reneg,
221 uint32_t priorInFlight,
222 const Time& minRtt) override;
223
225 {
226 return m_rate;
227 }
228
229 /**
230 * TracedCallback signature for tcp rate update events.
231 *
232 * The callback will be fired each time the rate is updated.
233 *
234 * \param [in] rate The rate information.
235 */
236 typedef void (*TcpRateUpdated)(const TcpRateConnection& rate);
237
238 /**
239 * TracedCallback signature for tcp rate sample update events.
240 *
241 * The callback will be fired each time the rate sample is updated.
242 *
243 * \param [in] sample The rate sample that will be passed to congestion control
244 * algorithms.
245 */
246 typedef void (*TcpRateSampleUpdated)(const TcpRateSample& sample);
247
248 private:
249 // Rate sample related variables
250 TcpRateConnection m_rate; //!< Rate information
251 TcpRateSample m_rateSample; //!< Rate sample (continuously updated)
252
255};
256
257/**
258 * \brief Output operator.
259 * \param os The output stream.
260 * \param sample the TcpRateLinux::TcpRateSample to print.
261 * \returns The output stream.
262 */
263std::ostream& operator<<(std::ostream& os, const TcpRateOps::TcpRateSample& sample);
264
265/**
266 * \brief Output operator.
267 * \param os The output stream.
268 * \param rate the TcpRateLinux::TcpRateConnection to print.
269 * \returns The output stream.
270 */
271std::ostream& operator<<(std::ostream& os, const TcpRateOps::TcpRateConnection& rate);
272
273/**
274 * Comparison operator
275 * \param lhs left operand
276 * \param rhs right operand
277 * \return true if the operands are equal
278 */
280
281/**
282 * Comparison operator
283 * \param lhs left operand
284 * \param rhs right operand
285 * \return true if the operands are equal
286 */
289
290} // namespace ns3
291
292#endif /* TCP_RATE_OPS_H */
Class for representing data rates.
Definition: data-rate.h:89
A base class which provides memory management and object aggregation.
Definition: object.h:89
Linux management and generation of Rate information for TCP.
Definition: tcp-rate-ops.h:196
TracedCallback< const TcpRateConnection & > m_rateTrace
Rate trace.
Definition: tcp-rate-ops.h:253
void(* TcpRateSampleUpdated)(const TcpRateSample &sample)
TracedCallback signature for tcp rate sample update events.
Definition: tcp-rate-ops.h:246
void SkbDelivered(TcpTxItem *skb) override
Update the Rate information after an item is received.
const TcpRateConnection & GetConnectionRate() override
Definition: tcp-rate-ops.h:224
TracedCallback< const TcpRateSample & > m_rateSampleTrace
Rate Sample trace.
Definition: tcp-rate-ops.h:254
TcpRateSample m_rateSample
Rate sample (continuously updated)
Definition: tcp-rate-ops.h:251
void(* TcpRateUpdated)(const TcpRateConnection &rate)
TracedCallback signature for tcp rate update events.
Definition: tcp-rate-ops.h:236
TcpRateConnection m_rate
Rate information.
Definition: tcp-rate-ops.h:250
void SkbSent(TcpTxItem *skb, bool isStartOfTransmission) override
Put the rate information inside the sent skb.
const TcpRateSample & GenerateSample(uint32_t delivered, uint32_t lost, bool is_sack_reneg, uint32_t priorInFlight, const Time &minRtt) override
Generate a TcpRateSample to feed a congestion avoidance algorithm.
Definition: tcp-rate-ops.cc:57
static TypeId GetTypeId()
Get the type ID.
Definition: tcp-rate-ops.cc:39
~TcpRateLinux() override
Definition: tcp-rate-ops.h:205
void CalculateAppLimited(uint32_t cWnd, uint32_t in_flight, uint32_t segmentSize, const SequenceNumber32 &tailSeq, const SequenceNumber32 &nextTx, const uint32_t lostOut, const uint32_t retransOut) override
If a gap is detected between sends, it means we are app-limited.
Interface for all operations that involve a Rate monitoring for TCP.
Definition: tcp-rate-ops.h:40
static TypeId GetTypeId()
Get the type ID.
Definition: tcp-rate-ops.cc:30
virtual const TcpRateSample & GenerateSample(uint32_t delivered, uint32_t lost, bool is_sack_reneg, uint32_t priorInFlight, const Time &minRtt)=0
Generate a TcpRateSample to feed a congestion avoidance algorithm.
virtual void SkbSent(TcpTxItem *skb, bool isStartOfTransmission)=0
Put the rate information inside the sent skb.
virtual void CalculateAppLimited(uint32_t cWnd, uint32_t in_flight, uint32_t segmentSize, const SequenceNumber32 &tailSeq, const SequenceNumber32 &nextTx, const uint32_t lostOut, const uint32_t retransOut)=0
If a gap is detected between sends, it means we are app-limited.
virtual const TcpRateConnection & GetConnectionRate()=0
virtual void SkbDelivered(TcpTxItem *skb)=0
Update the Rate information after an item is received.
Item that encloses the application packet and some flags for it.
Definition: tcp-tx-item.h:33
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
uint32_t segmentSize
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
Information about the connection rate.
Definition: tcp-rate-ops.h:174
uint32_t m_txItemDelivered
The value of delivered when the acked item was sent.
Definition: tcp-rate-ops.h:181
Time m_deliveredTime
Simulator time when m_delivered was last updated.
Definition: tcp-rate-ops.h:176
int32_t m_rateDelivered
The amount of data delivered considered to calculate delivery rate.
Definition: tcp-rate-ops.h:182
uint64_t m_delivered
The total amount of data in bytes delivered so far.
Definition: tcp-rate-ops.h:175
uint32_t m_appLimited
The index of the last transmitted packet marked as application-limited.
Definition: tcp-rate-ops.h:179
bool m_rateAppLimited
Was sample was taken when data is app limited?
Definition: tcp-rate-ops.h:186
Time m_firstSentTime
The send time of the packet that was most recently marked as delivered.
Definition: tcp-rate-ops.h:177
Time m_rateInterval
The value of interval considered to calculate delivery rate.
Definition: tcp-rate-ops.h:184
Rate Sample structure.
Definition: tcp-rate-ops.h:140
Time m_ackElapsed
ACK time interval calculated from the most recent packet delivered.
Definition: tcp-rate-ops.h:150
bool IsValid() const
Is the sample valid?
Definition: tcp-rate-ops.h:161
bool m_isAppLimited
Indicates whether the rate sample is application-limited.
Definition: tcp-rate-ops.h:142
uint32_t m_ackedSacked
The amount of data acked and sacked in the last received ack.
Definition: tcp-rate-ops.h:155
DataRate m_deliveryRate
The delivery rate sample.
Definition: tcp-rate-ops.h:141
uint32_t m_priorInFlight
The value if bytes in flight prior to last received ack.
Definition: tcp-rate-ops.h:154
Time m_sendElapsed
Send time interval calculated from the most recent packet delivered.
Definition: tcp-rate-ops.h:148
Time m_interval
The length of the sampling interval.
Definition: tcp-rate-ops.h:143
uint32_t m_priorDelivered
The delivered count of the most recent packet delivered.
Definition: tcp-rate-ops.h:146
int32_t m_delivered
The amount of data marked as delivered over the sampling interval.
Definition: tcp-rate-ops.h:144
uint32_t m_bytesLoss
The amount of data marked as lost from the most recent ack received.
Definition: tcp-rate-ops.h:152
Time m_priorTime
The delivered time of the most recent packet delivered.
Definition: tcp-rate-ops.h:147