A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-option-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 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 "ns3/core-module.h"
20#include "ns3/tcp-option-ts.h"
21#include "ns3/tcp-option-winscale.h"
22#include "ns3/tcp-option.h"
23#include "ns3/test.h"
24
25#include <string.h>
26
27using namespace ns3;
28
35{
36 public:
42 TcpOptionWSTestCase(std::string name, uint8_t scale);
43
47 void TestSerialize();
51 void TestDeserialize();
52
53 private:
54 void DoRun() override;
55 void DoTeardown() override;
56
57 uint8_t m_scale;
59};
60
61TcpOptionWSTestCase::TcpOptionWSTestCase(std::string name, uint8_t scale)
62 : TestCase(name)
63{
64 m_scale = scale;
65}
66
67void
69{
72}
73
74void
76{
78
79 opt.SetScale(m_scale);
80 NS_TEST_EXPECT_MSG_EQ(m_scale, opt.GetScale(), "Scale isn't saved correctly");
81
83
85}
86
87void
89{
91
93 uint8_t kind = start.PeekU8();
94
95 NS_TEST_EXPECT_MSG_EQ(kind, TcpOption::WINSCALE, "Different kind found");
96
97 opt.Deserialize(start);
98
99 NS_TEST_EXPECT_MSG_EQ(m_scale, opt.GetScale(), "Different scale found");
100}
101
102void
104{
105}
106
113{
114 public:
119 TcpOptionTSTestCase(std::string name);
120
124 void TestSerialize();
128 void TestDeserialize();
129
130 private:
131 void DoRun() override;
132 void DoTeardown() override;
133
137};
138
140 : TestCase(name)
141{
142 m_timestamp = 0;
143 m_echo = 0;
144}
145
146void
148{
149 Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable>();
150
151 for (uint32_t i = 0; i < 1000; ++i)
152 {
153 m_timestamp = x->GetInteger();
154 m_echo = x->GetInteger();
157 }
158}
159
160void
162{
163 TcpOptionTS opt;
164
166 opt.SetEcho(m_echo);
167
168 NS_TEST_EXPECT_MSG_EQ(m_timestamp, opt.GetTimestamp(), "TS isn't saved correctly");
169 NS_TEST_EXPECT_MSG_EQ(m_echo, opt.GetEcho(), "echo isn't saved correctly");
170
172
173 opt.Serialize(m_buffer.Begin());
174}
175
176void
178{
179 TcpOptionTS opt;
180
182 uint8_t kind = start.PeekU8();
183
184 NS_TEST_EXPECT_MSG_EQ(kind, TcpOption::TS, "Different kind found");
185
186 opt.Deserialize(start);
187
188 NS_TEST_EXPECT_MSG_EQ(m_timestamp, opt.GetTimestamp(), "Different TS found");
189 NS_TEST_EXPECT_MSG_EQ(m_echo, opt.GetEcho(), "Different echo found");
190}
191
192void
194{
195}
196
203{
204 public:
206 : TestSuite("tcp-option", Type::UNIT)
207 {
208 for (uint8_t i = 0; i < 15; ++i)
209 {
210 AddTestCase(new TcpOptionWSTestCase("Testing window scale value", i),
211 TestCase::Duration::QUICK);
212 }
213 AddTestCase(new TcpOptionTSTestCase("Testing serialization of random values for timestamp"),
214 TestCase::Duration::QUICK);
215 }
216};
217
TCP TimeStamp option Test.
void TestSerialize()
Serialization test.
uint32_t m_timestamp
TimeStamp.
uint32_t m_echo
Echoed TimeStamp.
Buffer m_buffer
Buffer.
void TestDeserialize()
Deserialization test.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
TcpOptionTSTestCase(std::string name)
Constructor.
TCP options TestSuite.
TCP Window Scaling option Test.
void TestSerialize()
Serialization test.
void TestDeserialize()
Deserialization test.
uint8_t m_scale
Window scaling.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
Buffer m_buffer
Buffer.
void DoRun() override
Implementation to actually run this TestCase.
TcpOptionWSTestCase(std::string name, uint8_t scale)
Constructor.
iterator in a Buffer instance
Definition: buffer.h:100
automatically resized byte buffer
Definition: buffer.h:94
void AddAtStart(uint32_t start)
Definition: buffer.cc:314
Buffer::Iterator Begin() const
Definition: buffer.h:1074
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
@ WINSCALE
WINSCALE.
Definition: tcp-option.h:61
Defines the TCP option of kind 8 (timestamp option) as in RFC 1323
Definition: tcp-option-ts.h:37
void SetTimestamp(uint32_t ts)
Set the timestamp stored in the Option.
uint32_t GetSerializedSize() const override
Returns number of bytes required for Option serialization.
uint32_t GetTimestamp() const
Get the timestamp stored in the Option.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the Option from a buffer iterator.
uint32_t GetEcho() const
Get the timestamp echo stored in the Option.
void Serialize(Buffer::Iterator start) const override
Serialize the Option to a buffer iterator.
void SetEcho(uint32_t ts)
Set the timestamp echo stored in the Option.
Defines the TCP option of kind 3 (window scale option) as in RFC 1323
uint8_t GetScale() const
Get the scale value (uint8_t)
uint32_t GetSerializedSize() const override
Returns number of bytes required for Option serialization.
void Serialize(Buffer::Iterator start) const override
Serialize the Option to a buffer iterator.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the Option from a buffer iterator.
void SetScale(uint8_t scale)
Set the scale option.
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:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:252
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::StringValue attribute value declarations.
static TcpOptionTestSuite g_TcpOptionTestSuite
Static variable for test initialization.