A Discrete-Event Network Simulator
API
tcp-rtt-estimation.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 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
19#include "tcp-error-model.h"
20#include "tcp-general-test.h"
21
22#include "ns3/log.h"
23#include "ns3/node.h"
24#include "ns3/rtt-estimator.h"
25
26using namespace ns3;
27
28NS_LOG_COMPONENT_DEFINE("TcpRttEstimationTestSuite");
29
42{
43 public:
50 TcpRttEstimationTest(const std::string& desc, bool enableTs, uint32_t pktCount);
51
52 protected:
55
56 void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
57 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
58 void UpdatedRttHistory(const SequenceNumber32& seq,
59 uint32_t sz,
60 bool isRetransmission,
61 SocketWho who) override;
62 void RttTrace(Time oldTime, Time newTime) override;
63 void FinalChecks() override;
64
65 void ConfigureEnvironment() override;
66
67 private:
73};
74
76 bool enableTs,
77 uint32_t pktCount)
78 : TcpGeneralTest(desc),
79 m_enableTs(enableTs),
80 m_rttChanged(false),
81 m_highestTxSeq(0),
82 m_pktCount(pktCount),
83 m_dataCount(0)
84{
85}
86
87void
89{
90 TcpGeneralTest::ConfigureEnvironment();
94 SetMTU(500);
95}
96
99{
100 Ptr<TcpSocketMsgBase> s = TcpGeneralTest::CreateReceiverSocket(node);
101 if (!m_enableTs)
102 {
103 s->SetAttribute("Timestamp", BooleanValue(false));
104 }
105
106 return s;
107}
108
111{
112 Ptr<TcpSocketMsgBase> s = TcpGeneralTest::CreateSenderSocket(node);
113 if (!m_enableTs)
114 {
115 s->SetAttribute("Timestamp", BooleanValue(false));
116 }
117
118 return s;
119}
120
121void
123{
124 if (who == SENDER && h.GetFlags() != TcpHeader::SYN)
125 {
127 {
129 m_dataCount = 0;
130 }
131
133 NS_TEST_ASSERT_MSG_NE(rttEstimator,
134 nullptr,
135 "rtt is 0 (and should be different from zero)");
136 NS_LOG_DEBUG("S Tx: seq=" << h.GetSequenceNumber() << " ack=" << h.GetAckNumber());
137 NS_TEST_ASSERT_MSG_NE(rttEstimator->GetEstimate(),
138 Seconds(1),
139 "Default Estimate for the RTT");
140 }
141}
142
143void
145{
146 if (who == RECEIVER)
147 {
148 NS_LOG_DEBUG("R Rx: seq=" << h.GetSequenceNumber() << " ack=" << h.GetAckNumber());
149 }
150}
151
152void
154 uint32_t sz,
155 bool isRetransmission,
156 SocketWho who)
157{
158 if (sz == 0)
159 {
160 return;
161 }
162
163 if (seq < m_highestTxSeq)
164 {
165 NS_TEST_ASSERT_MSG_EQ(isRetransmission, true, "A retransmission is not flagged as such");
166 }
167 else if (seq == m_highestTxSeq && m_dataCount == 0)
168 {
169 NS_TEST_ASSERT_MSG_EQ(isRetransmission,
170 false,
171 "Incorrectly flagging seq as retransmission");
172 m_dataCount++;
173 }
174 else if (seq == m_highestTxSeq && m_dataCount > 0)
175 {
176 NS_TEST_ASSERT_MSG_EQ(isRetransmission, true, "A retransmission is not flagged as such");
177 }
178}
179
180void
182{
183 NS_LOG_DEBUG("Rtt changed to " << newTime.GetSeconds());
184 m_rttChanged = true;
185}
186
187void
189{
190 NS_TEST_ASSERT_MSG_EQ(m_rttChanged, true, "Rtt was not updated");
191}
192
202{
203 public:
211 TcpRttEstimationWithLossTest(const std::string& desc,
212 bool enableTs,
213 uint32_t pktCount,
214 std::vector<uint32_t> toDrop);
215
216 protected:
218
219 private:
220 std::vector<uint32_t> m_toDrop;
221};
222
224 bool enableTs,
225 uint32_t pktCount,
226 std::vector<uint32_t> toDrop)
227 : TcpRttEstimationTest(desc, enableTs, pktCount),
228 m_toDrop(toDrop)
229{
230}
231
234{
235 Ptr<TcpSeqErrorModel> errorModel = CreateObject<TcpSeqErrorModel>();
236
237 std::vector<uint32_t>::iterator it;
238
239 for (it = m_toDrop.begin(); it != m_toDrop.end(); ++it)
240 {
241 errorModel->AddSeqToKill(SequenceNumber32((*it)));
242 }
243
244 return errorModel;
245}
246
254{
255 public:
257 : TestSuite("tcp-rtt-estimation-test", UNIT)
258 {
259 AddTestCase(new TcpRttEstimationTest("RTT estimation, ts, no data", true, 0),
260 TestCase::QUICK);
261 AddTestCase(new TcpRttEstimationTest("RTT estimation, no ts, no data", false, 0),
262 TestCase::QUICK);
263 AddTestCase(new TcpRttEstimationTest("RTT estimation, ts, some data", true, 10),
264 TestCase::QUICK);
265 AddTestCase(new TcpRttEstimationTest("RTT estimation, no ts, some data", false, 10),
266 TestCase::QUICK);
267
268 std::vector<uint32_t> toDrop;
269 toDrop.push_back(501);
270
271 AddTestCase(new TcpRttEstimationWithLossTest("RTT estimation, no ts,"
272 " some data, with retr",
273 false,
274 10,
275 toDrop),
276 TestCase::QUICK);
277 AddTestCase(new TcpRttEstimationWithLossTest("RTT estimation, ts,"
278 " some data, with retr",
279 true,
280 10,
281 toDrop),
282 TestCase::QUICK);
283
284 toDrop.push_back(501);
285 AddTestCase(new TcpRttEstimationWithLossTest("RTT estimation, no ts,"
286 " some data, with retr",
287 false,
288 10,
289 toDrop),
290 TestCase::QUICK);
291 AddTestCase(new TcpRttEstimationWithLossTest("RTT estimation, ts,"
292 " some data, with retr",
293 true,
294 10,
295 toDrop),
296 TestCase::QUICK);
297
298 toDrop.push_back(54001);
299 toDrop.push_back(58001);
300 toDrop.push_back(58501);
301 toDrop.push_back(60001);
302 toDrop.push_back(68501);
303 AddTestCase(new TcpRttEstimationWithLossTest("RTT estimation, no ts,"
304 " a lot of data, with retr",
305 false,
306 1000,
307 toDrop),
308 TestCase::QUICK);
309 AddTestCase(new TcpRttEstimationWithLossTest("RTT estimation, ts,"
310 " a lot of data, with retr",
311 true,
312 1000,
313 toDrop),
314 TestCase::QUICK);
315 }
316};
317
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:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
General infrastructure for TCP testing.
Ptr< RttEstimator > GetRttEstimator(SocketWho who)
Get the Rtt estimator of the socket.
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.
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
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:46
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
Definition: tcp-header.cc:137
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:167
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:143
void AddSeqToKill(const SequenceNumber32 &seq)
Add the sequence number to the list of segments to be killed.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:402
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
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:144
#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:564
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpRttEstimationTestSuite g_tcpRttEstimationTestSuite
Static variable for test initialization.