This documentation is not the
Latest Release
.
A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
tcp-wscaling-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 "ns3/test.h"
21
#include "
tcp-general-test.h
"
22
#include "ns3/node.h"
23
#include "ns3/log.h"
24
25
namespace
ns3
{
26
27
NS_LOG_COMPONENT_DEFINE
(
"WScalingTestSuite"
);
28
29
// TODO: Check the buffer size and scaling option value
30
class
WScalingTestCase
:
public
TcpGeneralTest
31
{
32
public
:
33
enum
Configuration
34
{
35
DISABLED
,
36
ENABLED_SENDER
,
37
ENABLED_RECEIVER
,
38
ENABLED
39
};
40
41
WScalingTestCase
(
WScalingTestCase::Configuration
conf
,
42
uint32_t maxRcvBufferSize,
43
uint32_t maxSndBufferSize, std::string name);
44
45
protected
:
46
virtual
Ptr<TcpSocketMsgBase>
CreateReceiverSocket
(
Ptr<Node>
node);
47
virtual
Ptr<TcpSocketMsgBase>
CreateSenderSocket
(
Ptr<Node>
node);
48
49
virtual
void
Tx
(
const
Ptr<const Packet>
p,
const
TcpHeader
&h,
SocketWho
who);
50
51
Configuration
m_configuration
;
52
uint32_t
m_maxRcvBufferSize
;
53
uint32_t
m_maxSndBufferSize
;
54
};
55
56
WScalingTestCase::WScalingTestCase
(
WScalingTestCase::Configuration
conf
,
57
uint32_t maxRcvBufferSize,
58
uint32_t maxSndBufferSize, std::string name)
59
:
TcpGeneralTest
(name)
60
{
61
m_configuration
= conf;
62
m_maxRcvBufferSize
= maxRcvBufferSize;
63
m_maxSndBufferSize
= maxSndBufferSize;
64
}
65
66
Ptr<TcpSocketMsgBase>
67
WScalingTestCase::CreateReceiverSocket
(
Ptr<Node>
node)
68
{
69
Ptr<TcpSocketMsgBase>
socket =
TcpGeneralTest::CreateReceiverSocket
(node);
70
71
switch
(
m_configuration
)
72
{
73
case
DISABLED
:
74
socket->SetAttribute (
"WindowScaling"
,
BooleanValue
(
false
));
75
break
;
76
77
case
ENABLED_RECEIVER
:
78
socket->SetAttribute (
"WindowScaling"
,
BooleanValue
(
true
));
79
break
;
80
81
case
ENABLED_SENDER
:
82
socket->SetAttribute (
"WindowScaling"
,
BooleanValue
(
false
));
83
break
;
84
85
case
ENABLED
:
86
socket->SetAttribute (
"WindowScaling"
,
BooleanValue
(
true
));
87
break
;
88
}
89
90
return
socket;
91
}
92
93
Ptr<TcpSocketMsgBase>
94
WScalingTestCase::CreateSenderSocket
(
Ptr<Node>
node)
95
{
96
Ptr<TcpSocketMsgBase>
socket =
TcpGeneralTest::CreateSenderSocket
(node);
97
98
switch
(
m_configuration
)
99
{
100
case
DISABLED
:
101
socket->SetAttribute (
"WindowScaling"
,
BooleanValue
(
false
));
102
break
;
103
104
case
ENABLED_RECEIVER
:
105
socket->SetAttribute (
"WindowScaling"
,
BooleanValue
(
false
));
106
break
;
107
108
case
ENABLED_SENDER
:
109
socket->SetAttribute (
"WindowScaling"
,
BooleanValue
(
true
));
110
break
;
111
112
case
ENABLED
:
113
socket->SetAttribute (
"WindowScaling"
,
BooleanValue
(
true
));
114
break
;
115
}
116
117
return
socket;
118
}
119
120
void
121
WScalingTestCase::Tx
(
const
Ptr<const Packet>
p,
const
TcpHeader
&h,
SocketWho
who)
122
{
123
NS_LOG_INFO
(h);
124
125
if
(! (h.
GetFlags
() &
TcpHeader::SYN
))
126
{
127
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::WINSCALE
),
false
,
128
"wscale present in non-SYN packets"
);
129
}
130
else
131
{
132
if
(
m_configuration
==
DISABLED
)
133
{
134
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::WINSCALE
),
false
,
135
"wscale disabled but option enabled"
);
136
}
137
else
if
(
m_configuration
==
ENABLED
)
138
{
139
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::WINSCALE
),
true
,
140
"wscale enabled but option disabled"
);
141
}
142
143
if
(who ==
SENDER
)
144
{
145
if
(
m_configuration
==
ENABLED_RECEIVER
)
146
{
147
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::WINSCALE
),
false
,
148
"wscale disabled but option enabled"
);
149
}
150
else
if
(
m_configuration
==
ENABLED_SENDER
)
151
{
152
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::WINSCALE
),
true
,
153
"wscale enabled but option disabled"
);
154
}
155
}
156
else
if
(who ==
RECEIVER
)
157
{
158
if
(
m_configuration
==
ENABLED_RECEIVER
)
159
{
160
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::WINSCALE
),
false
,
161
"sender has not ws, but receiver sent anyway"
);
162
}
163
else
if
(
m_configuration
==
ENABLED_SENDER
)
164
{
165
NS_TEST_ASSERT_MSG_EQ
(h.
HasOption
(
TcpOption::WINSCALE
),
false
,
166
"receiver has not ws enabled but sent anyway"
);
167
}
168
}
169
}
170
}
171
172
static
class
TcpWScalingTestSuite
:
public
TestSuite
173
{
174
public
:
175
TcpWScalingTestSuite
()
176
:
TestSuite
(
"tcp-wscaling"
,
UNIT
)
177
{
178
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED
, 200000, 65535,
"WS only server"
),
TestCase::QUICK
);
179
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED
, 65535, 65535,
"Window scaling not used, all enabled"
),
TestCase::QUICK
);
180
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::DISABLED
, 65535, 65535,
"WS disabled"
),
TestCase::QUICK
);
181
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED_SENDER
, 65535, 65535,
"WS enabled client"
),
TestCase::QUICK
);
182
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED_RECEIVER
, 65535, 65535,
"WS disabled client"
),
TestCase::QUICK
);
183
184
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED
, 65535, 200000,
"WS only client"
),
TestCase::QUICK
);
185
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED
, 131072, 65535,
"WS only server"
),
TestCase::QUICK
);
186
AddTestCase
(
new
WScalingTestCase
(
WScalingTestCase::ENABLED
, 65535, 131072,
"WS only client"
),
TestCase::QUICK
);
187
}
188
189
}
g_tcpWScalingTestSuite
;
190
191
}
// namespace ns3
192
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:73
ns3::TcpGeneralTest::RECEIVER
Receiver node.
Definition:
tcp-general-test.h:231
ns3::BooleanValue
AttributeValue implementation for Boolean.
Definition:
boolean.h:34
ns3::TcpHeader::GetFlags
uint8_t GetFlags() const
Get the flags.
Definition:
tcp-header.cc:161
ns3::WScalingTestCase::CreateSenderSocket
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
Definition:
tcp-wscaling-test.cc:94
ns3::TestCase::QUICK
Fast test.
Definition:
test.h:1152
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1333
ns3::TcpGeneralTest::CreateReceiverSocket
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
Definition:
tcp-general-test.cc:278
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:201
ns3::g_tcpWScalingTestSuite
ns3::TcpWScalingTestSuite g_tcpWScalingTestSuite
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition:
log.h:244
conf
Definition:
conf.py:1
ns3::TestSuite::UNIT
This test suite implements a Unit Test.
Definition:
test.h:1343
ns3::WScalingTestCase::DISABLED
Definition:
tcp-wscaling-test.cc:35
ns3::WScalingTestCase::m_configuration
Configuration m_configuration
Definition:
tcp-wscaling-test.cc:51
ns3::TcpWScalingTestSuite
Definition:
tcp-wscaling-test.cc:172
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition:
test.cc:297
ns3::WScalingTestCase::ENABLED_SENDER
Definition:
tcp-wscaling-test.cc:36
ns3::WScalingTestCase
Definition:
tcp-wscaling-test.cc:30
ns3::WScalingTestCase::Configuration
Configuration
Definition:
tcp-wscaling-test.cc:33
ns3::WScalingTestCase::WScalingTestCase
WScalingTestCase(WScalingTestCase::Configuration conf, uint32_t maxRcvBufferSize, uint32_t maxSndBufferSize, std::string name)
Definition:
tcp-wscaling-test.cc:56
NS_TEST_ASSERT_MSG_EQ
#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
ns3::TcpHeader::SYN
SYN.
Definition:
tcp-header.h:263
ns3::WScalingTestCase::m_maxSndBufferSize
uint32_t m_maxSndBufferSize
Definition:
tcp-wscaling-test.cc:53
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TcpHeader
Header for the Transmission Control Protocol.
Definition:
tcp-header.h:44
ns3::TcpGeneralTest::CreateSenderSocket
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
Definition:
tcp-general-test.cc:272
ns3::WScalingTestCase::CreateReceiverSocket
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
Definition:
tcp-wscaling-test.cc:67
ns3::WScalingTestCase::Tx
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
Definition:
tcp-wscaling-test.cc:121
ns3::WScalingTestCase::ENABLED_RECEIVER
Definition:
tcp-wscaling-test.cc:37
ns3::TcpGeneralTest::SocketWho
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
Definition:
tcp-general-test.h:228
ns3::TcpGeneralTest
General infrastructure for TCP testing.
Definition:
tcp-general-test.h:197
ns3::WScalingTestCase::m_maxRcvBufferSize
uint32_t m_maxRcvBufferSize
Definition:
tcp-wscaling-test.cc:52
ns3::TcpOption::WINSCALE
WINSCALE.
Definition:
tcp-option.h:58
tcp-general-test.h
ns3::TcpGeneralTest::SENDER
Sender node.
Definition:
tcp-general-test.h:230
ns3::TcpHeader::HasOption
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition:
tcp-header.cc:490
ns3::TcpWScalingTestSuite::TcpWScalingTestSuite
TcpWScalingTestSuite()
Definition:
tcp-wscaling-test.cc:175
ns3::WScalingTestCase::ENABLED
Definition:
tcp-wscaling-test.cc:38
src
internet
test
tcp-wscaling-test.cc
Generated on Wed Nov 11 2015 20:00:35 for ns-3 by
1.8.9.1