A Discrete-Event Network Simulator
API
tcp-rtt-estimation.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 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 
20 #include "tcp-general-test.h"
21 #include "ns3/node.h"
22 #include "ns3/log.h"
23 #include "tcp-error-model.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("TcpRttEstimationTestSuite");
28 
38 {
39 public:
40  TcpRttEstimationTest (const std::string &desc, bool enableTs, uint32_t dataPkt);
41 
42 protected:
45 
46  virtual void Rx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
47  virtual void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
48  virtual void UpdatedRttHistory (const SequenceNumber32 & seq, uint32_t sz,
49  bool isRetransmission, SocketWho who);
50  virtual void RttTrace (Time oldTime, Time newTime);
51  void FinalChecks ();
52 
53  virtual void ConfigureEnvironment ();
54 
55 private:
56  bool m_enableTs;
59  uint32_t m_pktCount;
60  uint32_t m_dataCount;
61 };
62 
63 TcpRttEstimationTest::TcpRttEstimationTest (const std::string &desc, bool enableTs,
64  uint32_t pktCount)
65  : TcpGeneralTest (desc),
66  m_enableTs (enableTs),
67  m_rttChanged (false),
68  m_highestTxSeq (0),
69  m_pktCount (pktCount),
70  m_dataCount (0)
71 {
72 }
73 
74 void
76 {
80  SetTransmitStart (Seconds (2.0));
81  SetMTU (500);
82 }
83 
86 {
88  if (!m_enableTs)
89  {
90  s->SetAttribute ("Timestamp", BooleanValue (false));
91  }
92 
93  return s;
94 }
95 
98 {
100  if (!m_enableTs)
101  {
102  s->SetAttribute ("Timestamp", BooleanValue (false));
103  }
104 
105  return s;
106 }
107 
108 void
110 {
111  if (who == SENDER && h.GetFlags () != TcpHeader::SYN)
112  {
114  {
116  m_dataCount = 0;
117  }
118 
119  Ptr<RttEstimator> rttEstimator = GetRttEstimator (SENDER);
120  NS_ASSERT (rttEstimator != 0);
121  NS_LOG_DEBUG ("S Tx: seq=" << h.GetSequenceNumber () << " ack=" << h.GetAckNumber ());
122  NS_TEST_ASSERT_MSG_NE (rttEstimator->GetEstimate (), Seconds (1),
123  "Default Estimate for the RTT");
124  }
125 }
126 
127 void
129 {
130  if (who == RECEIVER)
131  {
132  NS_LOG_DEBUG ("R Rx: seq=" << h.GetSequenceNumber () << " ack=" << h.GetAckNumber ());
133  }
134 }
135 
136 void
138  bool isRetransmission, SocketWho who)
139 {
140  if (sz == 0)
141  {
142  return;
143  }
144 
145  if (seq < m_highestTxSeq)
146  {
147  NS_TEST_ASSERT_MSG_EQ (isRetransmission, true,
148  "A retransmission is not flagged as such");
149  }
150  else if (seq == m_highestTxSeq && m_dataCount == 0)
151  {
152  NS_TEST_ASSERT_MSG_EQ (isRetransmission, false,
153  "Incorrectly flagging seq as retransmission");
154  m_dataCount++;
155  }
156  else if (seq == m_highestTxSeq && m_dataCount > 0)
157  {
158  NS_TEST_ASSERT_MSG_EQ (isRetransmission, true,
159  "A retransmission is not flagged as such");
160  }
161 }
162 
163 void
165 {
166  NS_LOG_DEBUG ("Rtt changed to " << newTime.GetSeconds ());
167  m_rttChanged = true;
168 }
169 
170 void
172 {
173  NS_TEST_ASSERT_MSG_EQ (m_rttChanged, true, "Rtt was not updated");
174 }
175 
176 //-----------------------------------------------------------------------------
178 {
179 public:
180  TcpRttEstimationWithLossTest (const std::string &desc, bool enableTs,
181  uint32_t pktCount, std::vector<uint32_t> toDrop);
182 
183 protected:
185 
186 private:
187  std::vector<uint32_t> m_toDrop;
188 };
189 
191  bool enableTs,
192  uint32_t pktCount,
193  std::vector<uint32_t> toDrop)
194  : TcpRttEstimationTest (desc, enableTs, pktCount),
195  m_toDrop (toDrop)
196 {
197 
198 }
199 
202 {
203  Ptr<TcpSeqErrorModel> errorModel = CreateObject<TcpSeqErrorModel> ();
204 
205  std::vector<uint32_t>::iterator it;
206 
207  for (it = m_toDrop.begin (); it != m_toDrop.end (); ++it)
208  {
209  errorModel->AddSeqToKill (SequenceNumber32 ((*it)));
210  }
211 
212  return errorModel;
213 }
214 
215 //-----------------------------------------------------------------------------
216 
218 {
219 public:
220  TcpRttEstimationTestSuite () : TestSuite ("tcp-rtt-estimation-test", UNIT)
221  {
222  AddTestCase (new TcpRttEstimationTest ("RTT estimation, ts, no data", true, 0),
224  AddTestCase (new TcpRttEstimationTest ("RTT estimation, no ts, no data", false, 0),
226  AddTestCase (new TcpRttEstimationTest ("RTT estimation, ts, some data", true, 10),
228  AddTestCase (new TcpRttEstimationTest ("RTT estimation, no ts, some data", false, 10),
230 
231  std::vector<uint32_t> toDrop;
232  toDrop.push_back (501);
233 
234  AddTestCase (new TcpRttEstimationWithLossTest ("RTT estimation, no ts,"
235  " some data, with retr",
236  false, 10, toDrop),
238  AddTestCase (new TcpRttEstimationWithLossTest ("RTT estimation, ts,"
239  " some data, with retr",
240  true, 10, toDrop),
242 
243  toDrop.push_back (501);
244  AddTestCase (new TcpRttEstimationWithLossTest ("RTT estimation, no ts,"
245  " some data, with retr",
246  false, 10, toDrop),
248  AddTestCase (new TcpRttEstimationWithLossTest ("RTT estimation, ts,"
249  " some data, with retr",
250  true, 10, toDrop),
252 
253  toDrop.push_back (54001);
254  toDrop.push_back (58001);
255  toDrop.push_back (58501);
256  toDrop.push_back (60001);
257  toDrop.push_back (68501);
258  AddTestCase (new TcpRttEstimationWithLossTest ("RTT estimation, no ts,"
259  " a lot of data, with retr",
260  false, 1000, toDrop),
262  AddTestCase (new TcpRttEstimationWithLossTest ("RTT estimation, ts,"
263  " a lot of data, with retr",
264  true, 1000, toDrop),
266  }
267 
269 
270 } // namespace ns3
271 
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void FinalChecks()
Performs the (eventual) final checks through test asserts.
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
Definition: tcp-header.cc:143
AttributeValue implementation for Boolean.
Definition: boolean.h:34
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:173
Fast test.
Definition: test.h:1152
A suite of tests to run.
Definition: test.h:1333
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:149
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:903
void SetTransmitStart(Time startTime)
Set the initial time at which the application sends the first data packet.
This test suite implements a Unit Test.
Definition: test.h:1343
Check Rtt calculations.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
TcpRttEstimationTest(const std::string &desc, bool enableTs, uint32_t dataPkt)
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
virtual void ConfigureEnvironment()
Change the configuration of the evironment.
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
virtual void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
#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:161
ns3::TcpRttEstimationTestSuite g_tcpRttEstimationTestSuite
TcpRttEstimationWithLossTest(const std::string &desc, bool enableTs, uint32_t pktCount, std::vector< uint32_t > toDrop)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
virtual void RttTrace(Time oldTime, Time newTime)
Rtt changes.
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
virtual void UpdatedRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission, SocketWho who)
Updated the Rtt history.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
Ptr< RttEstimator > GetRttEstimator(SocketWho who)
Get the Rtt estimator of the socket.
General infrastructure for TCP testing.
#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:617
virtual void ConfigureEnvironment(void)
Change the configuration of the evironment.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
Ptr< ErrorModel > CreateReceiverErrorModel()
Create and return the error model to install in the receiver node.
void SetPropagationDelay(Time propDelay)
Propagation delay of the bottleneck link.