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