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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "tcp-general-test.h"
9
10#include "ns3/log.h"
11#include "ns3/node.h"
12#include "ns3/tcp-header.h"
13#include "ns3/tcp-option-ts.h"
14
15using namespace ns3;
16
17NS_LOG_COMPONENT_DEFINE("TimestampTestSuite");
18
19/**
20 * \ingroup internet-test
21 *
22 * \brief TCP TimeStamp enabling Test.
23 */
25{
26 public:
27 /**
28 * TimeStamp configuration.
29 */
37
38 /**
39 * \brief Constructor.
40 * \param conf Test configuration.
41 */
43
44 protected:
47
48 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
49 void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
50
51 Configuration m_configuration; //!< Test configuration.
52};
53
59
62{
64
65 switch (m_configuration)
66 {
67 case DISABLED:
68 socket->SetAttribute("Timestamp", BooleanValue(false));
69 break;
70
72 socket->SetAttribute("Timestamp", BooleanValue(true));
73 break;
74
75 case ENABLED_SENDER:
76 socket->SetAttribute("Timestamp", BooleanValue(false));
77 break;
78
79 case ENABLED:
80 socket->SetAttribute("Timestamp", BooleanValue(true));
81 break;
82 }
83
84 return socket;
85}
86
89{
91
92 switch (m_configuration)
93 {
94 case DISABLED:
96 socket->SetAttribute("Timestamp", BooleanValue(false));
97 break;
98
99 case ENABLED_SENDER:
100 case ENABLED:
101 socket->SetAttribute("Timestamp", BooleanValue(true));
102 break;
103 }
104
105 return socket;
106}
107
108void
110{
112 {
114 false,
115 "timestamp disabled but option enabled");
116 }
117 else if (m_configuration == ENABLED)
118 {
120 true,
121 "timestamp enabled but option disabled");
122 }
123
124 NS_LOG_INFO(h);
125 if (who == SENDER)
126 {
127 if (h.GetFlags() & TcpHeader::SYN)
128 {
130 {
132 false,
133 "timestamp disabled but option enabled");
134 }
136 {
138 true,
139 "timestamp enabled but option disabled");
140 }
141 }
142 else
143 {
145 {
147 false,
148 "timestamp disabled but option enabled");
149 }
150 }
151 }
152 else if (who == RECEIVER)
153 {
154 if (h.GetFlags() & TcpHeader::SYN)
155 {
156 // Sender has not sent timestamp, so implementation should disable ts
158 {
160 false,
161 "sender has not ts, but receiver sent anyway");
162 }
164 {
166 false,
167 "receiver has not ts enabled but sent anyway");
168 }
169 }
170 else
171 {
173 {
175 false,
176 "timestamp disabled but option enabled");
177 }
178 }
179 }
180}
181
182void
184{
185 // if (who == SENDER)
186 // {
187 // }
188 // else if (who == RECEIVER)
189 // {
190 // }
191}
192
193/**
194 * \ingroup internet-test
195 *
196 * \brief TCP TimeStamp values Test.
197 */
199{
200 public:
201 /**
202 * \brief Constructor.
203 * \param startTime Start time (Seconds).
204 * \param timeToWait Time to wait (Seconds).
205 * \param name Test description.
206 */
207 TimestampValueTestCase(double startTime, double timeToWait, std::string name);
208
209 private:
210 void DoRun() override;
211 void DoTeardown() override;
212
213 /**
214 * \brief Perform the test checks.
215 */
216 void Check();
217 /**
218 * \brief Test initialization.
219 */
220 void Init();
221
222 double m_startTime; //!< Start time (Seconds).
223 double m_timeToWait; //!< Time to wait (Seconds).
224 double m_initValue; //!< Initialization value (Seconds).
225};
226
228 double timeToWait,
229 std::string name)
230 : TestCase(name)
231{
232 m_startTime = startTime;
233 m_timeToWait = timeToWait;
234}
235
236void
244
245void
250
251void
256
257void
272
273/**
274 * \ingroup internet-test
275 *
276 * \brief TCP TimeStamp TestSuite.
277 */
279{
280 public:
282 : TestSuite("tcp-timestamp", Type::UNIT)
283 {
284 AddTestCase(new TimestampTestCase(TimestampTestCase::DISABLED), TestCase::Duration::QUICK);
286 TestCase::Duration::QUICK);
288 TestCase::Duration::QUICK);
289 AddTestCase(new TimestampTestCase(TimestampTestCase::ENABLED), TestCase::Duration::QUICK);
290 AddTestCase(new TimestampValueTestCase(0.0, 0.01, "Value Check"),
291 TestCase::Duration::QUICK);
292 AddTestCase(new TimestampValueTestCase(3.0, 0.5, "Value Check"), TestCase::Duration::QUICK);
293 AddTestCase(new TimestampValueTestCase(5.5, 1.0, "Value Check"), TestCase::Duration::QUICK);
294 AddTestCase(new TimestampValueTestCase(6.0, 2.0, "Value Check"), TestCase::Duration::QUICK);
295 AddTestCase(new TimestampValueTestCase(2.4, 0.7, "Value Check"), TestCase::Duration::QUICK);
296 }
297};
298
299static 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).
AttributeValue implementation for Boolean.
Definition boolean.h:26
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
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:36
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
uint8_t GetFlags() const
Get the flags.
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:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:291
A suite of tests to run.
Definition test.h:1262
Type
Type of test.
Definition test.h:1269
static constexpr auto UNIT
Definition test.h:1280
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#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_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:327
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
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.