A Discrete-Event Network Simulator
API
tcp-rate-ops.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2018 Natale Patriciello <natale.patriciello@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19#include "tcp-rate-ops.h"
20#include "ns3/log.h"
21#include "ns3/simulator.h"
22
23namespace ns3 {
24
25NS_LOG_COMPONENT_DEFINE ("TcpRateOps");
27
28TypeId
30{
31 static TypeId tid = TypeId ("ns3::TcpRateOps")
32 .SetParent<Object> ()
33 .SetGroupName ("Internet")
34 ;
35 return tid;
36}
37
39
42{
43 static TypeId tid = TypeId ("ns3::TcpRateLinux")
45 .SetGroupName ("Internet")
46 .AddTraceSource ("TcpRateUpdated",
47 "Tcp rate information has been updated",
49 "ns3::TcpRateLinux::TcpRateUpdated")
50 .AddTraceSource ("TcpRateSampleUpdated",
51 "Tcp rate sample has been updated",
53 "ns3::TcpRateLinux::TcpRateSampleUpdated")
54 ;
55 return tid;
56}
57
59TcpRateLinux::GenerateSample (uint32_t delivered, uint32_t lost, bool is_sack_reneg,
60 uint32_t priorInFlight, const Time &minRtt)
61{
62 NS_LOG_FUNCTION (this << delivered << lost << is_sack_reneg);
63
64 /* Clear app limited if bubble is acked and gone. */
66 {
67 NS_LOG_INFO ("Updating Rate m_appLimited to zero");
69 }
70
71 NS_LOG_INFO ("Updating RateSample m_ackedSacked=" << delivered <<
72 ", m_bytesLoss=" << lost << " and m_priorInFlight" << priorInFlight);
73 m_rateSample.m_ackedSacked = delivered; /* freshly ACKed or SACKed */
74 m_rateSample.m_bytesLoss = lost; /* freshly marked lost */
75 m_rateSample.m_priorInFlight = priorInFlight;
76
77 /* Return an invalid sample if no timing information is available or
78 * in recovery from loss with SACK reneging. Rate samples taken during
79 * a SACK reneging event may overestimate bw by including packets that
80 * were SACKed before the reneg.
81 */
82 if (m_rateSample.m_priorTime == Seconds (0) || is_sack_reneg)
83 {
84 NS_LOG_INFO ("PriorTime is zero, invalidating sample");
88 return m_rateSample;
89 }
90
91 // LINUX:
92 // /* Model sending data and receiving ACKs as separate pipeline phases
93 // * for a window. Usually the ACK phase is longer, but with ACK
94 // * compression the send phase can be longer. To be safe we use the
95 // * longer phase.
96 // */
97 // auto snd_us = m_rateSample.m_interval; /* send phase */
98 // auto ack_us = Simulator::Now () - m_rateSample.m_prior_mstamp;
99 // m_rateSample.m_interval = std::max (snd_us, ack_us);
100
103 NS_LOG_INFO ("Updating sample interval=" << m_rateSample.m_interval << " and delivered data" << m_rateSample.m_delivered);
104
105 /* Normally we expect m_interval >= minRtt.
106 * Note that rate may still be over-estimated when a spuriously
107 * retransmistted skb was first (s)acked because "interval_us"
108 * is under-estimated (up to an RTT). However continuously
109 * measuring the delivery rate during loss recovery is crucial
110 * for connections suffer heavy or prolonged losses.
111 */
112 if (m_rateSample.m_interval < minRtt)
113 {
114 NS_LOG_INFO ("Sampling interval is invalid");
116 m_rateSample.m_priorTime = Seconds (0); // To make rate sample invalid
118 return m_rateSample;
119 }
120
121 /* Record the last non-app-limited or the highest app-limited bw */
125 {
130 NS_LOG_INFO ("Updating delivery rate=" << m_rateSample.m_deliveryRate);
131 }
132
134 return m_rateSample;
135}
136
137void
139 uint32_t segmentSize, const SequenceNumber32 &tailSeq,
140 const SequenceNumber32 &nextTx, const uint32_t lostOut,
141 const uint32_t retransOut)
142{
143 NS_LOG_FUNCTION (this);
144
145 /* Missing checks from Linux:
146 * - Nothing in sending host's qdisc queues or NIC tx queue. NOT IMPLEMENTED
147 */
148 if (tailSeq - nextTx < static_cast<int32_t> (segmentSize) // We have less than one packet to send.
149 && in_flight < cWnd // We are not limited by CWND.
150 && lostOut <= retransOut) // All lost packets have been retransmitted.
151 {
152 m_rate.m_appLimited = std::max<uint32_t> (m_rate.m_delivered + in_flight, 1);
154 }
155
156 // m_appLimited will be reset once in GenerateSample, if it has to be.
157 // else
158 // {
159 // m_rate.m_appLimited = 0;
160 // }
161}
162
163void
165{
166 NS_LOG_FUNCTION (this << skb);
167
169
170 if (skbInfo.m_deliveredTime == Time::Max ())
171 {
172 return;
173 }
174
175 m_rate.m_delivered += skb->GetSeqSize ();
177
180 {
186
188
190 }
191
192 /* Mark off the skb delivered once it's taken into account to avoid being
193 * used again when it's cumulatively acked, in case it was SACKed.
194 */
195 skbInfo.m_deliveredTime = Time::Max ();
198}
199
200void
201TcpRateLinux::SkbSent (TcpTxItem *skb, bool isStartOfTransmission)
202{
203 NS_LOG_FUNCTION (this << skb << isStartOfTransmission);
204
206
207 /* In general we need to start delivery rate samples from the
208 * time we received the most recent ACK, to ensure we include
209 * the full time the network needs to deliver all in-flight
210 * packets. If there are no packets in flight yet, then we
211 * know that any ACKs after now indicate that the network was
212 * able to deliver those packets completely in the sampling
213 * interval between now and the next ACK.
214 *
215 * Note that we use the entire window size instead of bytes_in_flight
216 * because the latter is a guess based on RTO and loss-marking
217 * heuristics. We don't want spurious RTOs or loss markings to cause
218 * a spuriously small time interval, causing a spuriously high
219 * bandwidth estimate.
220 */
221 if (isStartOfTransmission)
222 {
223 NS_LOG_INFO ("Starting of a transmission at time " << Simulator::Now ().GetSeconds ());
227 }
228
231 skbInfo.m_isAppLimited = (m_rate.m_appLimited != 0);
233}
234
235std::ostream &
236operator<< (std::ostream & os, TcpRateLinux::TcpRateConnection const & rate)
237{
238 os << "m_delivered = " << rate.m_delivered << std::endl;
239 os << "m_deliveredTime = " << rate.m_deliveredTime << std::endl;
240 os << "m_firstSentTime = " << rate.m_firstSentTime << std::endl;
241 os << "m_appLimited = " << rate.m_appLimited << std::endl;
242 os << "m_rateDelivered = " << rate.m_rateDelivered << std::endl;
243 os << "m_rateInterval = " << rate.m_rateInterval << std::endl;
244 os << "m_rateAppLimited = " << rate.m_rateAppLimited << std::endl;
245 os << "m_txItemDelivered = " << rate.m_txItemDelivered << std::endl;
246 return os;
247}
248
249std::ostream &
250operator<< (std::ostream & os, TcpRateLinux::TcpRateSample const & sample)
251{
252 os << "m_deliveryRate = " << sample.m_deliveryRate << std::endl;
253 os << " m_isAppLimited = " << sample.m_isAppLimited << std::endl;
254 os << " m_interval = " << sample.m_interval << std::endl;
255 os << " m_delivered = " << sample.m_delivered << std::endl;
256 os << " m_priorDelivered = " << sample.m_priorDelivered << std::endl;
257 os << " m_priorTime = " << sample.m_priorTime << std::endl;
258 os << " m_sendElapsed = " << sample.m_sendElapsed << std::endl;
259 os << " m_ackElapsed = " << sample.m_ackElapsed << std::endl;
260 os << " m_bytesLoss = " << sample.m_bytesLoss << std::endl;
261 os << " m_priorInFlight= " << sample.m_priorInFlight << std::endl;
262 os << " m_ackedSacked = " << sample.m_ackedSacked << std::endl;
263 return os;
264}
265
266bool
268{
269 return (lhs.m_deliveryRate == rhs.m_deliveryRate
270 && lhs.m_isAppLimited == rhs.m_isAppLimited
271 && lhs.m_interval == rhs.m_interval
272 && lhs.m_delivered == rhs.m_delivered
274 && lhs.m_priorTime == rhs.m_priorTime
275 && lhs.m_sendElapsed == rhs.m_sendElapsed
276 && lhs.m_ackElapsed == rhs.m_ackElapsed
277 );
278}
279
280bool
283{
284 return (lhs.m_delivered == rhs.m_delivered
285 && lhs.m_deliveredTime == rhs.m_deliveredTime
286 && lhs.m_firstSentTime == rhs.m_firstSentTime
287 && lhs.m_appLimited == rhs.m_appLimited
288 );
289}
290
291
292} // namespace ns3
#define max(a, b)
Definition: 80211b.c:43
A base class which provides memory management and object aggregation.
Definition: object.h:88
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Linux management and generation of Rate information for TCP.
Definition: tcp-rate-ops.h:181
TracedCallback< const TcpRateConnection & > m_rateTrace
Rate trace.
Definition: tcp-rate-ops.h:231
TracedCallback< const TcpRateSample & > m_rateSampleTrace
Rate Sample trace.
Definition: tcp-rate-ops.h:232
virtual void SkbDelivered(TcpTxItem *skb) override
Update the Rate information after an item is received.
TcpRateSample m_rateSample
Rate sample (continuosly updated)
Definition: tcp-rate-ops.h:229
TcpRateConnection m_rate
Rate information.
Definition: tcp-rate-ops.h:228
virtual void SkbSent(TcpTxItem *skb, bool isStartOfTransmission) override
Put the rate information inside the sent skb.
virtual 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:59
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-rate-ops.cc:41
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) 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:39
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-rate-ops.cc:29
Item that encloses the application packet and some flags for it.
Definition: tcp-tx-item.h:33
RateInformation & GetRateInformation(void)
Get (to modify) the Rate Information of this item.
Definition: tcp-tx-item.cc:98
uint32_t GetSeqSize(void) const
Get the size in the sequence number space.
Definition: tcp-tx-item.cc:62
const Time & GetLastSent(void) const
Get a reference to the time the packet was sent for the last time.
Definition: tcp-tx-item.cc:92
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:380
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
Definition: nstime.h:283
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:206
#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:282
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:329
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1245
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:158
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:139
Information about the connection rate.
Definition: tcp-rate-ops.h:163
uint32_t m_txItemDelivered
The value of delivered when the acked item was sent.
Definition: tcp-rate-ops.h:168
Time m_deliveredTime
Simulator time when m_delivered was last updated.
Definition: tcp-rate-ops.h:165
int32_t m_rateDelivered
The amount of data delivered considered to calculate delivery rate.
Definition: tcp-rate-ops.h:169
uint64_t m_delivered
The total amount of data in bytes delivered so far.
Definition: tcp-rate-ops.h:164
uint32_t m_appLimited
The index of the last transmitted packet marked as application-limited.
Definition: tcp-rate-ops.h:167
bool m_rateAppLimited
Was sample was taken when data is app limited?
Definition: tcp-rate-ops.h:171
Time m_firstSentTime
The send time of the packet that was most recently marked as delivered.
Definition: tcp-rate-ops.h:166
Time m_rateInterval
The value of interval considered to calculate delivery rate.
Definition: tcp-rate-ops.h:170
Rate Sample structure.
Definition: tcp-rate-ops.h:134
Time m_ackElapsed
ACK time interval calculated from the most recent packet delivered.
Definition: tcp-rate-ops.h:142
bool m_isAppLimited
Indicates whether the rate sample is application-limited.
Definition: tcp-rate-ops.h:136
uint32_t m_ackedSacked
The amount of data acked and sacked in the last received ack.
Definition: tcp-rate-ops.h:145
DataRate m_deliveryRate
The delivery rate sample.
Definition: tcp-rate-ops.h:135
uint32_t m_priorInFlight
The value if bytes in flight prior to last received ack.
Definition: tcp-rate-ops.h:144
Time m_sendElapsed
Send time interval calculated from the most recent packet delivered.
Definition: tcp-rate-ops.h:141
Time m_interval
The length of the sampling interval.
Definition: tcp-rate-ops.h:137
uint32_t m_priorDelivered
The delivered count of the most recent packet delivered.
Definition: tcp-rate-ops.h:139
int32_t m_delivered
The amount of data marked as delivered over the sampling interval.
Definition: tcp-rate-ops.h:138
uint32_t m_bytesLoss
The amount of data marked as lost from the most recent ack received.
Definition: tcp-rate-ops.h:143
Time m_priorTime
The delivered time of the most recent packet delivered.
Definition: tcp-rate-ops.h:140
Various rate-related information, can be accessed by TcpRateOps.
Definition: tcp-tx-item.h:88
bool m_isAppLimited
Connection's app limited at the time the packet was sent.
Definition: tcp-tx-item.h:92
uint64_t m_delivered
Connection's delivered data at the time the packet was sent.
Definition: tcp-tx-item.h:89
Time m_deliveredTime
Connection's delivered time at the time the packet was sent.
Definition: tcp-tx-item.h:90
Time m_firstSent
Connection's first sent time at the time the packet was sent.
Definition: tcp-tx-item.h:91