A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-rate-ops.cc
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#include "tcp-rate-ops.h"
8
9#include "ns3/log.h"
10#include "ns3/simulator.h"
11
12namespace ns3
13{
14
15NS_LOG_COMPONENT_DEFINE("TcpRateOps");
17
18TypeId
20{
21 static TypeId tid = TypeId("ns3::TcpRateOps").SetParent<Object>().SetGroupName("Internet");
22 return tid;
23}
24
26
29{
30 static TypeId tid =
31 TypeId("ns3::TcpRateLinux")
33 .SetGroupName("Internet")
34 .AddTraceSource("TcpRateUpdated",
35 "Tcp rate information has been updated",
37 "ns3::TcpRateLinux::TcpRateUpdated")
38 .AddTraceSource("TcpRateSampleUpdated",
39 "Tcp rate sample has been updated",
41 "ns3::TcpRateLinux::TcpRateSampleUpdated");
42 return tid;
43}
44
47 uint32_t lost,
48 bool is_sack_reneg,
49 uint32_t priorInFlight,
50 const Time& minRtt)
51{
52 NS_LOG_FUNCTION(this << delivered << lost << is_sack_reneg);
53
54 /* Clear app limited if bubble is acked and gone. */
56 {
57 NS_LOG_INFO("Updating Rate m_appLimited to zero");
59 }
60
61 NS_LOG_INFO("Updating RateSample m_ackedSacked=" << delivered << ", m_bytesLoss=" << lost
62 << " and m_priorInFlight" << priorInFlight);
63 m_rateSample.m_ackedSacked = delivered; /* freshly ACKed or SACKed */
64 m_rateSample.m_bytesLoss = lost; /* freshly marked lost */
65 m_rateSample.m_priorInFlight = priorInFlight;
66
67 /* Return an invalid sample if no timing information is available or
68 * in recovery from loss with SACK reneging. Rate samples taken during
69 * a SACK reneging event may overestimate bw by including packets that
70 * were SACKed before the reneg.
71 */
72 if (m_rateSample.m_priorTime.IsZero() || is_sack_reneg)
73 {
74 NS_LOG_INFO("PriorTime is zero, invalidating sample");
78 return m_rateSample;
79 }
80
81 // LINUX:
82 // /* Model sending data and receiving ACKs as separate pipeline phases
83 // * for a window. Usually the ACK phase is longer, but with ACK
84 // * compression the send phase can be longer. To be safe we use the
85 // * longer phase.
86 // */
87 // auto snd_us = m_rateSample.m_interval; /* send phase */
88 // auto ack_us = Simulator::Now () - m_rateSample.m_prior_mstamp;
89 // m_rateSample.m_interval = std::max (snd_us, ack_us);
90
93 NS_LOG_INFO("Updating sample interval=" << m_rateSample.m_interval << " and delivered data"
95
96 /* Normally we expect m_interval >= minRtt.
97 * Note that rate may still be over-estimated when a spuriously
98 * retransmitted skb was first (s)acked because "interval_us"
99 * is under-estimated (up to an RTT). However continuously
100 * measuring the delivery rate during loss recovery is crucial
101 * for connections suffer heavy or prolonged losses.
102 */
103 if (m_rateSample.m_interval < minRtt)
104 {
105 NS_LOG_INFO("Sampling interval is invalid");
107 m_rateSample.m_priorTime = Seconds(0); // To make rate sample invalid
109 return m_rateSample;
110 }
111
112 /* Record the last non-app-limited or the highest app-limited bw */
115 {
121 NS_LOG_INFO("Updating delivery rate=" << m_rateSample.m_deliveryRate);
122 }
123
125 return m_rateSample;
126}
127
128void
130 uint32_t in_flight,
132 const SequenceNumber32& tailSeq,
133 const SequenceNumber32& nextTx,
134 const uint32_t lostOut,
135 const uint32_t retransOut)
136{
137 NS_LOG_FUNCTION(this);
138
139 /* Missing checks from Linux:
140 * - Nothing in sending host's qdisc queues or NIC tx queue. NOT IMPLEMENTED
141 */
142 if (tailSeq - nextTx <
143 static_cast<int32_t>(segmentSize) // We have less than one packet to send.
144 && in_flight < cWnd // We are not limited by CWND.
145 && lostOut <= retransOut) // All lost packets have been retransmitted.
146 {
147 m_rate.m_appLimited = std::max<uint32_t>(m_rate.m_delivered + in_flight, 1);
149 }
150
151 // m_appLimited will be reset once in GenerateSample, if it has to be.
152 // else
153 // {
154 // m_rate.m_appLimited = 0;
155 // }
156}
157
158void
160{
161 NS_LOG_FUNCTION(this << skb);
162
164
165 if (skbInfo.m_deliveredTime == Time::Max())
166 {
167 return;
168 }
169
170 m_rate.m_delivered += skb->GetSeqSize();
172
174 {
180
182
184 }
185
186 /* Mark off the skb delivered once it's taken into account to avoid being
187 * used again when it's cumulatively acked, in case it was SACKed.
188 */
189 skbInfo.m_deliveredTime = Time::Max();
192}
193
194void
195TcpRateLinux::SkbSent(TcpTxItem* skb, bool isStartOfTransmission)
196{
197 NS_LOG_FUNCTION(this << skb << isStartOfTransmission);
198
200
201 /* In general we need to start delivery rate samples from the
202 * time we received the most recent ACK, to ensure we include
203 * the full time the network needs to deliver all in-flight
204 * packets. If there are no packets in flight yet, then we
205 * know that any ACKs after now indicate that the network was
206 * able to deliver those packets completely in the sampling
207 * interval between now and the next ACK.
208 *
209 * Note that we use the entire window size instead of bytes_in_flight
210 * because the latter is a guess based on RTO and loss-marking
211 * heuristics. We don't want spurious RTOs or loss markings to cause
212 * a spuriously small time interval, causing a spuriously high
213 * bandwidth estimate.
214 */
215 if (isStartOfTransmission)
216 {
217 NS_LOG_INFO("Starting of a transmission at time " << Simulator::Now().GetSeconds());
221 }
222
225 skbInfo.m_isAppLimited = (m_rate.m_appLimited != 0);
227}
228
229std::ostream&
230operator<<(std::ostream& os, const TcpRateOps::TcpRateConnection& rate)
231{
232 os << "m_delivered = " << rate.m_delivered << std::endl;
233 os << "m_deliveredTime = " << rate.m_deliveredTime << std::endl;
234 os << "m_firstSentTime = " << rate.m_firstSentTime << std::endl;
235 os << "m_appLimited = " << rate.m_appLimited << std::endl;
236 os << "m_rateDelivered = " << rate.m_rateDelivered << std::endl;
237 os << "m_rateInterval = " << rate.m_rateInterval << std::endl;
238 os << "m_rateAppLimited = " << rate.m_rateAppLimited << std::endl;
239 os << "m_txItemDelivered = " << rate.m_txItemDelivered << std::endl;
240 return os;
241}
242
243std::ostream&
244operator<<(std::ostream& os, const TcpRateOps::TcpRateSample& sample)
245{
246 os << "m_deliveryRate = " << sample.m_deliveryRate << std::endl;
247 os << " m_isAppLimited = " << sample.m_isAppLimited << std::endl;
248 os << " m_interval = " << sample.m_interval << std::endl;
249 os << " m_delivered = " << sample.m_delivered << std::endl;
250 os << " m_priorDelivered = " << sample.m_priorDelivered << std::endl;
251 os << " m_priorTime = " << sample.m_priorTime << std::endl;
252 os << " m_sendElapsed = " << sample.m_sendElapsed << std::endl;
253 os << " m_ackElapsed = " << sample.m_ackElapsed << std::endl;
254 os << " m_bytesLoss = " << sample.m_bytesLoss << std::endl;
255 os << " m_priorInFlight= " << sample.m_priorInFlight << std::endl;
256 os << " m_ackedSacked = " << sample.m_ackedSacked << std::endl;
257 return os;
258}
259
260bool
262{
263 return (lhs.m_deliveryRate == rhs.m_deliveryRate && lhs.m_isAppLimited == rhs.m_isAppLimited &&
264 lhs.m_interval == rhs.m_interval && lhs.m_delivered == rhs.m_delivered &&
265 lhs.m_priorDelivered == rhs.m_priorDelivered && lhs.m_priorTime == rhs.m_priorTime &&
266 lhs.m_sendElapsed == rhs.m_sendElapsed && lhs.m_ackElapsed == rhs.m_ackElapsed);
267}
268
269bool
275
276} // namespace ns3
Class for representing data rates.
Definition data-rate.h:78
A base class which provides memory management and object aggregation.
Definition object.h:78
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Linux management and generation of Rate information for TCP.
TracedCallback< const TcpRateConnection & > m_rateTrace
Rate trace.
void SkbDelivered(TcpTxItem *skb) override
Update the Rate information after an item is received.
TracedCallback< const TcpRateSample & > m_rateSampleTrace
Rate Sample trace.
TcpRateSample m_rateSample
Rate sample (continuously updated)
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.
static TypeId GetTypeId()
Get the type ID.
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.
Item that encloses the application packet and some flags for it.
Definition tcp-tx-item.h:22
uint32_t GetSeqSize() const
Get the size in the sequence number space.
const Time & GetLastSent() const
Get a reference to the time the packet was sent for the last time.
RateInformation & GetRateInformation()
Get (to modify) the Rate Information of this item.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition nstime.h:286
bool IsZero() const
Exactly equivalent to t == 0.
Definition nstime.h:304
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
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 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.
Various rate-related information, can be accessed by TcpRateOps.
Definition tcp-tx-item.h:77
bool m_isAppLimited
Connection's app limited at the time the packet was sent.
Definition tcp-tx-item.h:83
uint64_t m_delivered
Connection's delivered data at the time the packet was sent.
Definition tcp-tx-item.h:78
Time m_deliveredTime
Connection's delivered time at the time the packet was sent.
Definition tcp-tx-item.h:79
Time m_firstSent
Connection's first sent time at the time the packet was sent.
Definition tcp-tx-item.h:81