A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-timestamp-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 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-general-test.h"
20
21#include "ns3/log.h"
22#include "ns3/node.h"
23#include "ns3/tcp-header.h"
24#include "ns3/tcp-option-ts.h"
25
26using namespace ns3;
27
28NS_LOG_COMPONENT_DEFINE("TimestampTestSuite");
29
30/**
31 * \ingroup internet-test
32 *
33 * \brief TCP TimeStamp enabling Test.
34 */
36{
37 public:
38 /**
39 * TimeStamp configuration.
40 */
42 {
47 };
48
49 /**
50 * \brief Constructor.
51 * \param conf Test configuration.
52 */
54
55 protected:
58
59 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
60 void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
61
62 Configuration m_configuration; //!< Test configuration.
63};
64
66 : TcpGeneralTest("Testing the TCP Timestamp option")
67{
69}
70
73{
75
76 switch (m_configuration)
77 {
78 case DISABLED:
79 socket->SetAttribute("Timestamp", BooleanValue(false));
80 break;
81
83 socket->SetAttribute("Timestamp", BooleanValue(true));
84 break;
85
86 case ENABLED_SENDER:
87 socket->SetAttribute("Timestamp", BooleanValue(false));
88 break;
89
90 case ENABLED:
91 socket->SetAttribute("Timestamp", BooleanValue(true));
92 break;
93 }
94
95 return socket;
96}
97
100{
102
103 switch (m_configuration)
104 {
105 case DISABLED:
106 case ENABLED_RECEIVER:
107 socket->SetAttribute("Timestamp", BooleanValue(false));
108 break;
109
110 case ENABLED_SENDER:
111 case ENABLED:
112 socket->SetAttribute("Timestamp", BooleanValue(true));
113 break;
114 }
115
116 return socket;
117}
118
119void
121{
123 {
125 false,
126 "timestamp disabled but option enabled");
127 }
128 else if (m_configuration == ENABLED)
129 {
131 true,
132 "timestamp enabled but option disabled");
133 }
134
135 NS_LOG_INFO(h);
136 if (who == SENDER)
137 {
138 if (h.GetFlags() & TcpHeader::SYN)
139 {
141 {
143 false,
144 "timestamp disabled but option enabled");
145 }
147 {
149 true,
150 "timestamp enabled but option disabled");
151 }
152 }
153 else
154 {
156 {
158 false,
159 "timestamp disabled but option enabled");
160 }
161 }
162 }
163 else if (who == RECEIVER)
164 {
165 if (h.GetFlags() & TcpHeader::SYN)
166 {
167 // Sender has not sent timestamp, so implementation should disable ts
169 {
171 false,
172 "sender has not ts, but receiver sent anyway");
173 }
175 {
177 false,
178 "receiver has not ts enabled but sent anyway");
179 }
180 }
181 else
182 {
184 {
186 false,
187 "timestamp disabled but option enabled");
188 }
189 }
190 }
191}
192
193void
195{
196 // if (who == SENDER)
197 // {
198 // }
199 // else if (who == RECEIVER)
200 // {
201 // }
202}
203
204/**
205 * \ingroup internet-test
206 *
207 * \brief TCP TimeStamp values Test.
208 */
210{
211 public:
212 /**
213 * \brief Constructor.
214 * \param startTime Start time (Seconds).
215 * \param timeToWait Time to wait (Seconds).
216 * \param name Test description.
217 */
218 TimestampValueTestCase(double startTime, double timeToWait, std::string name);
219
220 private:
221 void DoRun() override;
222 void DoTeardown() override;
223
224 /**
225 * \brief Perform the test checks.
226 */
227 void Check();
228 /**
229 * \brief Test initialization.
230 */
231 void Init();
232
233 double m_startTime; //!< Start time (Seconds).
234 double m_timeToWait; //!< Time to wait (Seconds).
235 double m_initValue; //!< Initialization value (Seconds).
236};
237
239 double timeToWait,
240 std::string name)
241 : TestCase(name)
242{
243 m_startTime = startTime;
244 m_timeToWait = timeToWait;
245}
246
247void
249{
252
254}
255
256void
258{
260}
261
262void
264{
266}
267
268void
270{
272
275 MilliSeconds(1),
276 "Different TS values");
277
280 MilliSeconds(1),
281 "Estimating Wrong RTT");
282}
283
284/**
285 * \ingroup internet-test
286 *
287 * \brief TCP TimeStamp TestSuite.
288 */
290{
291 public:
293 : TestSuite("tcp-timestamp", Type::UNIT)
294 {
295 AddTestCase(new TimestampTestCase(TimestampTestCase::DISABLED), TestCase::Duration::QUICK);
297 TestCase::Duration::QUICK);
299 TestCase::Duration::QUICK);
300 AddTestCase(new TimestampTestCase(TimestampTestCase::ENABLED), TestCase::Duration::QUICK);
301 AddTestCase(new TimestampValueTestCase(0.0, 0.01, "Value Check"),
302 TestCase::Duration::QUICK);
303 AddTestCase(new TimestampValueTestCase(3.0, 0.5, "Value Check"), TestCase::Duration::QUICK);
304 AddTestCase(new TimestampValueTestCase(5.5, 1.0, "Value Check"), TestCase::Duration::QUICK);
305 AddTestCase(new TimestampValueTestCase(6.0, 2.0, "Value Check"), TestCase::Duration::QUICK);
306 AddTestCase(new TimestampValueTestCase(2.4, 0.7, "Value Check"), TestCase::Duration::QUICK);
307 }
308};
309
310static TcpTimestampTestSuite g_tcpTimestampTestSuite; //!< Static variable for test initialization
TCP TimeStamp TestSuite.
TCP TimeStamp enabling Test.
Configuration m_configuration
Test configuration.
void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet transmitted down to IP layer.
TimestampTestCase(TimestampTestCase::Configuration conf)
Constructor.
void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet received from IP layer.
Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node) override
Create and install the socket to install on the sender.
Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node) override
Create and install the socket to install on the receiver.
Configuration
TimeStamp configuration.
TCP TimeStamp values Test.
void DoRun() override
Implementation to actually run this TestCase.
TimestampValueTestCase(double startTime, double timeToWait, std::string name)
Constructor.
double m_timeToWait
Time to wait (Seconds).
double m_startTime
Start time (Seconds).
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void Check()
Perform the test checks.
void Init()
Test initialization.
double m_initValue
Initialization value (Seconds).
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
General infrastructure for TCP testing.
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
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.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:47
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:478
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:148
static Time ElapsedTimeFromTsValue(uint32_t echoTime)
Estimate the Time elapsed from a TS echo value.
static uint32_t NowToTsValue()
Return an uint32_t value which represent "now".
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:302
A suite of tests to run.
Definition: test.h:1273
Type
Type of test.
Definition: test.h:1280
static constexpr auto UNIT
Definition: test.h:1291
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#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:145
#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:338
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1331
Definition: conf.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpTimestampTestSuite g_tcpTimestampTestSuite
Static variable for test initialization.