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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "ns3/core-module.h"
9#include "ns3/tcp-option-ts.h"
10#include "ns3/tcp-option-winscale.h"
11#include "ns3/tcp-option.h"
12#include "ns3/test.h"
13
14#include <string.h>
15
16using namespace ns3;
17
18/**
19 * @ingroup internet-test
20 *
21 * @brief TCP Window Scaling option Test
22 */
24{
25 public:
26 /**
27 * @brief Constructor.
28 * @param name Test description.
29 * @param scale Window scaling.
30 */
31 TcpOptionWSTestCase(std::string name, uint8_t scale);
32
33 /**
34 * @brief Serialization test.
35 */
36 void TestSerialize();
37 /**
38 * @brief Deserialization test.
39 */
40 void TestDeserialize();
41
42 private:
43 void DoRun() override;
44 void DoTeardown() override;
45
46 uint8_t m_scale; //!< Window scaling.
47 Buffer m_buffer; //!< Buffer.
48};
49
50TcpOptionWSTestCase::TcpOptionWSTestCase(std::string name, uint8_t scale)
51 : TestCase(name)
52{
53 m_scale = scale;
54}
55
56void
62
63void
65{
67
68 opt.SetScale(m_scale);
69 NS_TEST_EXPECT_MSG_EQ(m_scale, opt.GetScale(), "Scale isn't saved correctly");
70
72
74}
75
76void
78{
80
82 uint8_t kind = start.PeekU8();
83
84 NS_TEST_EXPECT_MSG_EQ(kind, TcpOption::WINSCALE, "Different kind found");
85
86 opt.Deserialize(start);
87
88 NS_TEST_EXPECT_MSG_EQ(m_scale, opt.GetScale(), "Different scale found");
89}
90
91void
95
96/**
97 * @ingroup internet-test
98 *
99 * @brief TCP TimeStamp option Test
100 */
102{
103 public:
104 /**
105 * @brief Constructor.
106 * @param name Test description.
107 */
108 TcpOptionTSTestCase(std::string name);
109
110 /**
111 * @brief Serialization test.
112 */
113 void TestSerialize();
114 /**
115 * @brief Deserialization test.
116 */
117 void TestDeserialize();
118
119 private:
120 void DoRun() override;
121 void DoTeardown() override;
122
123 uint32_t m_timestamp; //!< TimeStamp.
124 uint32_t m_echo; //!< Echoed TimeStamp.
125 Buffer m_buffer; //!< Buffer.
126};
127
129 : TestCase(name)
130{
131 m_timestamp = 0;
132 m_echo = 0;
133}
134
135void
137{
139
140 for (uint32_t i = 0; i < 1000; ++i)
141 {
142 m_timestamp = x->GetInteger();
143 m_echo = x->GetInteger();
146 }
147}
148
149void
151{
152 TcpOptionTS opt;
153
155 opt.SetEcho(m_echo);
156
157 NS_TEST_EXPECT_MSG_EQ(m_timestamp, opt.GetTimestamp(), "TS isn't saved correctly");
158 NS_TEST_EXPECT_MSG_EQ(m_echo, opt.GetEcho(), "echo isn't saved correctly");
159
161
162 opt.Serialize(m_buffer.Begin());
163}
164
165void
167{
168 TcpOptionTS opt;
169
171 uint8_t kind = start.PeekU8();
172
173 NS_TEST_EXPECT_MSG_EQ(kind, TcpOption::TS, "Different kind found");
174
175 opt.Deserialize(start);
176
177 NS_TEST_EXPECT_MSG_EQ(m_timestamp, opt.GetTimestamp(), "Different TS found");
178 NS_TEST_EXPECT_MSG_EQ(m_echo, opt.GetEcho(), "Different echo found");
179}
180
181void
185
186/**
187 * @ingroup internet-test
188 *
189 * @brief TCP options TestSuite
190 */
192{
193 public:
195 : TestSuite("tcp-option", Type::UNIT)
196 {
197 for (uint8_t i = 0; i < 15; ++i)
198 {
199 AddTestCase(new TcpOptionWSTestCase("Testing window scale value", i),
200 TestCase::Duration::QUICK);
201 }
202 AddTestCase(new TcpOptionTSTestCase("Testing serialization of random values for timestamp"),
203 TestCase::Duration::QUICK);
204 }
205};
206
207static TcpOptionTestSuite g_TcpOptionTestSuite; //!< Static variable for test initialization
TCP TimeStamp option Test.
void TestSerialize()
Serialization test.
uint32_t m_timestamp
TimeStamp.
uint32_t m_echo
Echoed TimeStamp.
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.
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:89
automatically resized byte buffer
Definition buffer.h:83
void AddAtStart(uint32_t start)
Definition buffer.cc:303
Buffer::Iterator Begin() const
Definition buffer.h:1063
Smart pointer class similar to boost::intrusive_ptr.
@ WINSCALE
WINSCALE.
Definition tcp-option.h:50
Defines the TCP option of kind 8 (timestamp option) as in RFC 1323
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:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:241
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.