A Discrete-Event Network Simulator
API
tcp-timestamp-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 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 "ns3/private/tcp-option-ts.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("TimestampTestSuite");
28 
30 {
31 public:
33  {
38  };
39 
41 protected:
44 
45  virtual void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
46  virtual void Rx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
47 
49 };
50 
52  : TcpGeneralTest ("Testing the TCP Timestamp option")
53 {
54  m_configuration = conf;
55 }
56 
59 {
61 
62  switch (m_configuration)
63  {
64  case DISABLED:
65  socket->SetAttribute ("Timestamp", BooleanValue (false));
66  break;
67 
68  case ENABLED_RECEIVER:
69  socket->SetAttribute ("Timestamp", BooleanValue (true));
70  break;
71 
72  case ENABLED_SENDER:
73  socket->SetAttribute ("Timestamp", BooleanValue (false));
74  break;
75 
76  case ENABLED:
77  socket->SetAttribute ("Timestamp", BooleanValue (true));
78  break;
79  }
80 
81  return socket;
82 }
83 
86 {
88 
89  switch (m_configuration)
90  {
91  case DISABLED:
92  socket->SetAttribute ("Timestamp", BooleanValue (false));
93  break;
94 
95  case ENABLED_RECEIVER:
96  socket->SetAttribute ("Timestamp", BooleanValue (false));
97  break;
98 
99  case ENABLED_SENDER:
100  socket->SetAttribute ("Timestamp", BooleanValue (true));
101  break;
102 
103  case ENABLED:
104  socket->SetAttribute ("Timestamp", BooleanValue (true));
105  break;
106  }
107 
108  return socket;
109 }
110 
111 void
113 {
114  if (m_configuration == DISABLED)
115  {
117  "timestamp disabled but option enabled");
118  }
119  else if (m_configuration == ENABLED)
120  {
122  "timestamp enabled but option disabled");
123  }
124 
125  NS_LOG_INFO (h);
126  if (who == SENDER)
127  {
128  if (h.GetFlags () & TcpHeader::SYN)
129  {
131  {
133  "timestamp disabled but option enabled");
134  }
135  else if (m_configuration == ENABLED_SENDER)
136  {
138  "timestamp enabled but option disabled");
139  }
140  }
141  else
142  {
143  if (m_configuration != ENABLED)
144  {
146  "timestamp disabled but option enabled");
147  }
148  }
149  }
150  else if (who == RECEIVER)
151  {
152  if (h.GetFlags () & TcpHeader::SYN)
153  {
154  // Sender has not sent timestamp, so implementation should disable ts
156  {
158  "sender has not ts, but receiver sent anyway");
159  }
160  else if (m_configuration == ENABLED_SENDER)
161  {
163  "receiver has not ts enabled but sent anyway");
164  }
165  }
166  else
167  {
168  if (m_configuration != ENABLED)
169  {
171  "timestamp disabled but option enabled");
172  }
173  }
174  }
175 }
176 
177 void
179 {
180  if (who == SENDER)
181  {
182 
183  }
184  else if (who == RECEIVER)
185  {
186 
187  }
188 }
189 
190 // TimestampValueTestCase
192 {
193 public:
194  TimestampValueTestCase (double startTime, double timeToWait,
195  std::string name);
196 
197 private:
198  virtual void DoRun (void);
199  virtual void DoTeardown (void);
200 
201  void Check ();
202  void Init ();
203 
204  double m_startTime;
205  double m_timeToWait;
206  double m_initValue;
207 };
208 
210  double timeToWait,
211  std::string name)
212  : TestCase (name)
213 {
215  m_timeToWait = timeToWait;
216 }
217 
218 void
220 {
225 
226  Simulator::Run ();
227 }
228 
229 void
231 {
233 }
234 
235 void
237 {
239 }
240 
241 void
243 {
244  uint32_t lastValue = TcpOptionTS::NowToTsValue ();
245 
247  MilliSeconds (1), "Different TS values");
248 
250  MilliSeconds (1), "Estimating Wrong RTT");
251 }
252 
253 static class TcpTimestampTestSuite : public TestSuite
254 {
255 public:
257  : TestSuite ("tcp-timestamp", UNIT)
258  {
263  AddTestCase (new TimestampValueTestCase (0.0, 0.01, "Value Check"), TestCase::QUICK);
264  AddTestCase (new TimestampValueTestCase (3.0, 0.5, "Value Check"), TestCase::QUICK);
265  AddTestCase (new TimestampValueTestCase (5.5, 1.0, "Value Check"), TestCase::QUICK);
266  AddTestCase (new TimestampValueTestCase (6.0, 2.0, "Value Check"), TestCase::QUICK);
267  AddTestCase (new TimestampValueTestCase (2.4, 0.7, "Value Check"), TestCase::QUICK);
268 
269  }
270 
272 
273 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
AttributeValue implementation for Boolean.
Definition: boolean.h:34
static Time ElapsedTimeFromTsValue(uint32_t echoTime)
Estimate the Time elapsed from a TS echo value.
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
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
static void Run(void)
Run the simulation.
Definition: simulator.cc:201
#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
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
Definition: conf.py:1
encapsulates test code
Definition: test.h:1147
This test suite implements a Unit Test.
Definition: test.h:1343
ns3::TcpTimestampTestSuite g_tcpTimestampTestSuite
TimestampTestCase(TimestampTestCase::Configuration conf)
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1238
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
virtual void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
double startTime
TimestampValueTestCase(double startTime, double timeToWait, std::string name)
#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
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition: test.h:373
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:165
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
static uint32_t NowToTsValue()
Return an uint32_t value which represent "now".
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
General infrastructure for TCP testing.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:505