A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-rtt-estimation.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Natale Patriciello <natale.patriciello@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "tcp-error-model.h"
9#include "tcp-general-test.h"
10
11#include "ns3/log.h"
12#include "ns3/node.h"
13#include "ns3/rtt-estimator.h"
14
15using namespace ns3;
16
17NS_LOG_COMPONENT_DEFINE("TcpRttEstimationTestSuite");
18
19/**
20 * @ingroup internet-test
21 *
22 * @brief Check Rtt calculations
23 *
24 * First check is that, for each ACK, we have a valid estimation of the RTT.
25 * The second check is that, when updating RTT history, we should consider
26 * retransmission only segments which sequence number is lower than the highest
27 * already transmitted.
28 */
30{
31 public:
32 /**
33 * @brief Constructor.
34 * @param desc Test description.
35 * @param enableTs Enable TimeStamp option.
36 * @param pktCount Packet number.
37 */
38 TcpRttEstimationTest(const std::string& desc, bool enableTs, uint32_t pktCount);
39
40 protected:
43
44 void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
45 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
46 void UpdatedRttHistory(const SequenceNumber32& seq,
47 uint32_t sz,
48 bool isRetransmission,
49 SocketWho who) override;
50 void RttTrace(Time oldTime, Time newTime) override;
51 void FinalChecks() override;
52
53 void ConfigureEnvironment() override;
54
55 private:
56 bool m_enableTs; //!< Enable TimeStamp option
57 bool m_rttChanged; //!< True if RTT has changed.
58 SequenceNumber32 m_highestTxSeq; //!< Highest sequence number sent.
59 uint32_t m_pktCount; //!< Packet counter.
60 uint32_t m_dataCount; //!< Data counter.
61};
62
64 bool enableTs,
65 uint32_t pktCount)
66 : TcpGeneralTest(desc),
67 m_enableTs(enableTs),
68 m_rttChanged(false),
69 m_highestTxSeq(0),
70 m_pktCount(pktCount),
71 m_dataCount(0)
72{
73}
74
75void
84
87{
89 if (!m_enableTs)
90 {
91 s->SetAttribute("Timestamp", BooleanValue(false));
92 }
93
94 return s;
95}
96
99{
101 if (!m_enableTs)
102 {
103 s->SetAttribute("Timestamp", BooleanValue(false));
104 }
105
106 return s;
107}
108
109void
111{
112 if (who == SENDER && h.GetFlags() != TcpHeader::SYN)
113 {
115 {
117 m_dataCount = 0;
118 }
119
121 NS_TEST_ASSERT_MSG_NE(rttEstimator,
122 nullptr,
123 "rtt is 0 (and should be different from zero)");
124 NS_LOG_DEBUG("S Tx: seq=" << h.GetSequenceNumber() << " ack=" << h.GetAckNumber());
125 NS_TEST_ASSERT_MSG_NE(rttEstimator->GetEstimate(),
126 Seconds(1),
127 "Default Estimate for the RTT");
128 }
129}
130
131void
133{
134 if (who == RECEIVER)
135 {
136 NS_LOG_DEBUG("R Rx: seq=" << h.GetSequenceNumber() << " ack=" << h.GetAckNumber());
137 }
138}
139
140void
142 uint32_t sz,
143 bool isRetransmission,
144 SocketWho who)
145{
146 if (sz == 0)
147 {
148 return;
149 }
150
151 if (seq < m_highestTxSeq)
152 {
153 NS_TEST_ASSERT_MSG_EQ(isRetransmission, true, "A retransmission is not flagged as such");
154 }
155 else if (seq == m_highestTxSeq && m_dataCount == 0)
156 {
157 NS_TEST_ASSERT_MSG_EQ(isRetransmission,
158 false,
159 "Incorrectly flagging seq as retransmission");
160 m_dataCount++;
161 }
162 else if (seq == m_highestTxSeq && m_dataCount > 0)
163 {
164 NS_TEST_ASSERT_MSG_EQ(isRetransmission, true, "A retransmission is not flagged as such");
165 }
166}
167
168void
170{
171 NS_LOG_DEBUG("Rtt changed to " << newTime.GetSeconds());
172 m_rttChanged = true;
173}
174
175void
177{
178 NS_TEST_ASSERT_MSG_EQ(m_rttChanged, true, "Rtt was not updated");
179}
180
181/**
182 * @ingroup internet-test
183 *
184 * @brief Check Rtt calculations with packet losses.
185 *
186 * @see TcpRttEstimationTest
187 */
189{
190 public:
191 /**
192 * @brief Constructor.
193 * @param desc Test description.
194 * @param enableTs Enable TimeStamp option.
195 * @param pktCount Packet number.
196 * @param toDrop List of packet to drop.
197 */
198 TcpRttEstimationWithLossTest(const std::string& desc,
199 bool enableTs,
200 uint32_t pktCount,
201 std::vector<uint32_t> toDrop);
202
203 protected:
205
206 private:
207 std::vector<uint32_t> m_toDrop; //!< Packets to drop.
208};
209
211 bool enableTs,
212 uint32_t pktCount,
213 std::vector<uint32_t> toDrop)
214 : TcpRttEstimationTest(desc, enableTs, pktCount),
215 m_toDrop(toDrop)
216{
217}
218
221{
223
224 for (auto it = m_toDrop.begin(); it != m_toDrop.end(); ++it)
225 {
226 errorModel->AddSeqToKill(SequenceNumber32(*it));
227 }
228
229 return errorModel;
230}
231
232/**
233 * @ingroup internet-test
234 *
235 * @brief TCP RTT estimation TestSuite
236 */
238{
239 public:
241 : TestSuite("tcp-rtt-estimation-test", Type::UNIT)
242 {
243 AddTestCase(new TcpRttEstimationTest("RTT estimation, ts, no data", true, 0),
244 TestCase::Duration::QUICK);
245 AddTestCase(new TcpRttEstimationTest("RTT estimation, no ts, no data", false, 0),
246 TestCase::Duration::QUICK);
247 AddTestCase(new TcpRttEstimationTest("RTT estimation, ts, some data", true, 10),
248 TestCase::Duration::QUICK);
249 AddTestCase(new TcpRttEstimationTest("RTT estimation, no ts, some data", false, 10),
250 TestCase::Duration::QUICK);
251
252 std::vector<uint32_t> toDrop;
253 toDrop.push_back(501);
254
255 AddTestCase(new TcpRttEstimationWithLossTest("RTT estimation, no ts,"
256 " some data, with retr",
257 false,
258 10,
259 toDrop),
260 TestCase::Duration::QUICK);
261 AddTestCase(new TcpRttEstimationWithLossTest("RTT estimation, ts,"
262 " some data, with retr",
263 true,
264 10,
265 toDrop),
266 TestCase::Duration::QUICK);
267
268 toDrop.push_back(501);
269 AddTestCase(new TcpRttEstimationWithLossTest("RTT estimation, no ts,"
270 " some data, with retr",
271 false,
272 10,
273 toDrop),
274 TestCase::Duration::QUICK);
275 AddTestCase(new TcpRttEstimationWithLossTest("RTT estimation, ts,"
276 " some data, with retr",
277 true,
278 10,
279 toDrop),
280 TestCase::Duration::QUICK);
281
282 toDrop.push_back(54001);
283 toDrop.push_back(58001);
284 toDrop.push_back(58501);
285 toDrop.push_back(60001);
286 toDrop.push_back(68501);
287 AddTestCase(new TcpRttEstimationWithLossTest("RTT estimation, no ts,"
288 " a lot of data, with retr",
289 false,
290 1000,
291 toDrop),
292 TestCase::Duration::QUICK);
293 AddTestCase(new TcpRttEstimationWithLossTest("RTT estimation, ts,"
294 " a lot of data, with retr",
295 true,
296 1000,
297 toDrop),
298 TestCase::Duration::QUICK);
299 }
300};
301
303 g_tcpRttEstimationTestSuite; //!< Static variable for test initialization
Check Rtt calculations.
TcpRttEstimationTest(const std::string &desc, bool enableTs, uint32_t pktCount)
Constructor.
bool m_enableTs
Enable TimeStamp option.
SequenceNumber32 m_highestTxSeq
Highest sequence number sent.
void ConfigureEnvironment() override
Change the configuration of the environment.
uint32_t m_pktCount
Packet counter.
void UpdatedRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission, SocketWho who) override
Updated the Rtt history.
bool m_rttChanged
True if RTT has changed.
Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node) override
Create and install the socket to install on the sender.
void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet received from IP layer.
void FinalChecks() override
Performs the (eventual) final checks through test asserts.
void RttTrace(Time oldTime, Time newTime) override
Rtt changes.
void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet transmitted down to IP layer.
Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node) override
Create and install the socket to install on the receiver.
uint32_t m_dataCount
Data counter.
TCP RTT estimation TestSuite.
Check Rtt calculations with packet losses.
Ptr< ErrorModel > CreateReceiverErrorModel() override
Create and return the error model to install in the receiver node.
TcpRttEstimationWithLossTest(const std::string &desc, bool enableTs, uint32_t pktCount, std::vector< uint32_t > toDrop)
Constructor.
std::vector< uint32_t > m_toDrop
Packets to drop.
AttributeValue implementation for Boolean.
Definition boolean.h:26
Smart pointer class similar to boost::intrusive_ptr.
General infrastructure for TCP testing.
Ptr< RttEstimator > GetRttEstimator(SocketWho who)
Get the Rtt estimator of the socket.
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
void SetPropagationDelay(Time propDelay)
Propagation delay of the bottleneck link.
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
@ RECEIVER
Receiver node.
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
virtual void ConfigureEnvironment()
Change the configuration of the environment.
void SetTransmitStart(Time startTime)
Set the initial time at which the application sends the first data packet.
Header for the Transmission Control Protocol.
Definition tcp-header.h:36
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
uint8_t GetFlags() const
Get the flags.
SequenceNumber32 GetAckNumber() const
Get the ACK number.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition test.h:134
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Definition test.h:554
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1356
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpRttEstimationTestSuite g_tcpRttEstimationTestSuite
Static variable for test initialization.