A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
internet
test
ipv6-extension-header-test-suite.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License version 2 as
5
* published by the Free Software Foundation;
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
*
16
* Author: Fabian Mauchle <fabian.mauchle@hsr.ch>
17
*/
18
19
#include "ns3/test.h"
20
#include "ns3/ipv6-extension-header.h"
21
#include "ns3/ipv6-option-header.h"
22
23
using namespace
ns3
;
24
25
// ===========================================================================
26
// An empty option field must be filled with pad1 or padN header so theshape
27
// extension header's size is a multiple of 8.
28
//
29
// 0 31
30
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31
// | Extension Destination Header | |
32
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ PadN Header +
33
// | |
34
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35
// ===========================================================================
36
43
class
TestEmptyOptionField
:
public
TestCase
44
{
45
public
:
46
TestEmptyOptionField
() :
TestCase
(
"TestEmptyOptionField"
) {}
47
48
virtual
void
DoRun
()
49
{
50
Ipv6ExtensionDestinationHeader
header;
51
NS_TEST_EXPECT_MSG_EQ
(header.
GetSerializedSize
() % 8, 0,
"length of extension header is not a multiple of 8"
);
52
53
Buffer
buf;
54
buf.
AddAtStart
(header.
GetSerializedSize
());
55
header.
Serialize
(buf.Begin ());
56
57
const
uint8_t*
data
= buf.PeekData ();
58
NS_TEST_EXPECT_MSG_EQ
(*(
data
+2), 1,
"padding is missing"
);
//expecting a padN header
59
}
60
};
61
62
// ===========================================================================
63
// An option without alignment requirement must not be padded
64
//
65
// 0 31
66
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67
// | Extension Destination Header | OptionWithoutAlignmentHeader..|
68
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69
// |..OptionWithoutAlignmentHeader | PadN Header |
70
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71
// ===========================================================================
72
79
class
OptionWithoutAlignmentHeader
:
public
Ipv6OptionHeader
80
{
81
public
:
82
static
const
uint8_t TYPE = 42;
83
84
virtual
uint32_t
GetSerializedSize
()
const
85
{
86
return
4;
87
}
88
89
virtual
void
Serialize
(
Buffer::Iterator
start
)
const
90
{
91
start
.WriteU8 (TYPE);
92
start
.WriteU8 (GetSerializedSize ()-2);
93
start
.WriteU16 (0);
94
}
95
};
96
97
104
class
TestOptionWithoutAlignment
:
public
TestCase
105
{
106
public
:
107
TestOptionWithoutAlignment
() :
TestCase
(
"TestOptionWithoutAlignment"
) {}
108
109
virtual
void
DoRun
()
110
{
111
Ipv6ExtensionDestinationHeader
header;
112
OptionWithoutAlignmentHeader
optionHeader;
113
header.
AddOption
(optionHeader);
114
115
116
NS_TEST_EXPECT_MSG_EQ
(header.
GetSerializedSize
() % 8, 0,
"length of extension header is not a multiple of 8"
);
117
118
Buffer
buf;
119
buf.
AddAtStart
(header.
GetSerializedSize
());
120
header.
Serialize
(buf.Begin ());
121
122
const
uint8_t*
data
= buf.PeekData ();
123
NS_TEST_EXPECT_MSG_EQ
(*(
data
+2),
OptionWithoutAlignmentHeader::TYPE
,
"option without alignment is not first in header field"
);
124
}
125
};
126
127
// ===========================================================================
128
// An option with alignment requirement must be padded accordingly (padding to
129
// a total size multiple of 8 is allowed)
130
//
131
// 0 31
132
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
133
// | Extension Destination Header | PadN Header |
134
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
135
// | OptionWithAlignmentHeader |
136
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
137
// | PadN Header | |
138
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
139
// | Ipv6OptionJumbogramHeader |
140
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
141
// ===========================================================================
142
149
class
OptionWithAlignmentHeader
:
public
Ipv6OptionHeader
150
{
151
public
:
152
static
const
uint8_t TYPE = 73;
153
154
virtual
uint32_t
GetSerializedSize
()
const
155
{
156
return
4;
157
}
158
159
virtual
void
Serialize
(
Buffer::Iterator
start
)
const
160
{
161
start
.WriteU8 (TYPE);
162
start
.WriteU8 (GetSerializedSize ()-2);
163
start
.WriteU16 (0);
164
}
165
166
virtual
Alignment
GetAlignment
()
const
167
{
168
return
(
Alignment
){ 4,0};
169
}
170
};
171
172
179
class
TestOptionWithAlignment
:
public
TestCase
180
{
181
public
:
182
TestOptionWithAlignment
() :
TestCase
(
"TestOptionWithAlignment"
) {}
183
184
virtual
void
DoRun
()
185
{
186
Ipv6ExtensionDestinationHeader
header;
187
OptionWithAlignmentHeader
optionHeader;
188
header.
AddOption
(optionHeader);
189
Ipv6OptionJumbogramHeader
jumboHeader;
//has an alignment of 4n+2
190
header.
AddOption
(jumboHeader);
191
192
NS_TEST_EXPECT_MSG_EQ
(header.
GetSerializedSize
() % 8, 0,
"length of extension header is not a multiple of 8"
);
193
194
Buffer
buf;
195
buf.
AddAtStart
(header.
GetSerializedSize
());
196
header.
Serialize
(buf.Begin ());
197
198
const
uint8_t*
data
= buf.PeekData ();
199
NS_TEST_EXPECT_MSG_EQ
(*(
data
+2), 1,
"padding is missing"
);
//expecting a padN header
200
NS_TEST_EXPECT_MSG_EQ
(*(
data
+4),
OptionWithAlignmentHeader::TYPE
,
"option with alignment is not padded correctly"
);
201
NS_TEST_EXPECT_MSG_EQ
(*(
data
+8), 1,
"padding is missing"
);
//expecting a padN header
202
NS_TEST_EXPECT_MSG_EQ
(*(
data
+10), jumboHeader.
GetType
(),
"option with alignment is not padded correctly"
);
203
}
204
};
205
206
// ===========================================================================
207
// An option with an alignment that exactly matches the gap must not be padded
208
// (padding to a total size multiple of 8 is allowed)
209
//
210
// 0 31
211
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
212
// | Extension Destination Header | |
213
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
214
// | Ipv6OptionJumbogramHeader |
215
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
216
// | OptionWithAlignmentHeader |
217
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
218
// | PadN Header |
219
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
220
// ===========================================================================
221
228
class
TestFulfilledAlignment
:
public
TestCase
229
{
230
public
:
231
TestFulfilledAlignment
() :
TestCase
(
"TestCorrectAlignment"
) {}
232
233
virtual
void
DoRun
()
234
{
235
Ipv6ExtensionDestinationHeader
header;
236
Ipv6OptionJumbogramHeader
jumboHeader;
//has an alignment of 4n+2
237
header.
AddOption
(jumboHeader);
238
OptionWithAlignmentHeader
optionHeader;
239
header.
AddOption
(optionHeader);
240
241
NS_TEST_EXPECT_MSG_EQ
(header.
GetSerializedSize
() % 8, 0,
"length of extension header is not a multiple of 8"
);
242
243
Buffer
buf;
244
buf.
AddAtStart
(header.
GetSerializedSize
());
245
header.
Serialize
(buf.Begin ());
246
247
const
uint8_t*
data
= buf.PeekData ();
248
NS_TEST_EXPECT_MSG_EQ
(*(
data
+2), jumboHeader.
GetType
(),
"option with fulfilled alignment is padded anyway"
);
249
NS_TEST_EXPECT_MSG_EQ
(*(
data
+8),
OptionWithAlignmentHeader::TYPE
,
"option with fulfilled alignment is padded anyway"
);
250
}
251
};
252
259
class
Ipv6ExtensionHeaderTestSuite
:
public
TestSuite
260
{
261
public
:
262
Ipv6ExtensionHeaderTestSuite
()
263
:
TestSuite
(
"ipv6-extension-header"
, UNIT)
264
{
265
AddTestCase (
new
TestEmptyOptionField
,
TestCase::QUICK
);
266
AddTestCase (
new
TestOptionWithoutAlignment
,
TestCase::QUICK
);
267
AddTestCase (
new
TestOptionWithAlignment
,
TestCase::QUICK
);
268
AddTestCase (
new
TestFulfilledAlignment
,
TestCase::QUICK
);
269
270
}
271
};
272
273
static
Ipv6ExtensionHeaderTestSuite
ipv6ExtensionHeaderTestSuite
;
ns3::Buffer::AddAtStart
void AddAtStart(uint32_t start)
Definition:
buffer.cc:309
Ipv6ExtensionHeaderTestSuite
IPv6 extensions TestSuite.
Definition:
ipv6-extension-header-test-suite.cc:259
OptionWithAlignmentHeader::GetSerializedSize
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Definition:
ipv6-extension-header-test-suite.cc:154
ns3::Ipv6OptionHeader
Header for IPv6 Option.
Definition:
ipv6-option-header.h:36
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1342
ns3::Buffer
automatically resized byte buffer
Definition:
buffer.h:92
visualizer.core.start
def start()
Definition:
core.py:1844
TestOptionWithoutAlignment::TestOptionWithoutAlignment
TestOptionWithoutAlignment()
Definition:
ipv6-extension-header-test-suite.cc:107
TestFulfilledAlignment::TestFulfilledAlignment
TestFulfilledAlignment()
Definition:
ipv6-extension-header-test-suite.cc:231
NS_TEST_EXPECT_MSG_EQ
#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:285
OptionWithoutAlignmentHeader::TYPE
static const uint8_t TYPE
Option type.
Definition:
ipv6-extension-header-test-suite.cc:82
ns3::TestCase
encapsulates test code
Definition:
test.h:1155
OptionWithAlignmentHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Definition:
ipv6-extension-header-test-suite.cc:159
ipv6ExtensionHeaderTestSuite
static Ipv6ExtensionHeaderTestSuite ipv6ExtensionHeaderTestSuite
Static variable for test initialization.
Definition:
ipv6-extension-header-test-suite.cc:273
OptionWithAlignmentHeader
IPv6 extensions Test: Option with alignment.
Definition:
ipv6-extension-header-test-suite.cc:149
ns3::Ipv6OptionHeader::Alignment
represents the alignment requirements of an option header
Definition:
ipv6-option-header.h:47
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:98
data
uint8_t data[writeSize]
Definition:
socket-bound-tcp-static-routing.cc:53
OptionWithAlignmentHeader::GetAlignment
virtual Alignment GetAlignment() const
Get the Alignment requirement of this option header.
Definition:
ipv6-extension-header-test-suite.cc:166
TestOptionWithoutAlignment::DoRun
virtual void DoRun()
Implementation to actually run this TestCase.
Definition:
ipv6-extension-header-test-suite.cc:109
ns3::Ipv6OptionJumbogramHeader
Header of IPv6 Option Jumbogram.
Definition:
ipv6-option-header.h:271
TestFulfilledAlignment::DoRun
virtual void DoRun()
Implementation to actually run this TestCase.
Definition:
ipv6-extension-header-test-suite.cc:233
ns3::Ipv6OptionHeader::GetType
uint8_t GetType() const
Get the type of the option.
Definition:
ipv6-option-header.cc:63
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ipv6ExtensionDestinationHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Definition:
ipv6-extension-header.cc:299
ns3::OptionField::AddOption
void AddOption(Ipv6OptionHeader const &option)
Serialize the option, prepending pad1 or padn option as necessary.
Definition:
ipv6-extension-header.cc:170
TestOptionWithAlignment::DoRun
virtual void DoRun()
Implementation to actually run this TestCase.
Definition:
ipv6-extension-header-test-suite.cc:184
ns3::TestCase::QUICK
Fast test.
Definition:
test.h:1160
TestOptionWithAlignment
IPv6 extensions Test: Test the option with alignment.
Definition:
ipv6-extension-header-test-suite.cc:179
TestEmptyOptionField::TestEmptyOptionField
TestEmptyOptionField()
Definition:
ipv6-extension-header-test-suite.cc:46
OptionWithoutAlignmentHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Definition:
ipv6-extension-header-test-suite.cc:89
Ipv6ExtensionHeaderTestSuite::Ipv6ExtensionHeaderTestSuite
Ipv6ExtensionHeaderTestSuite()
Definition:
ipv6-extension-header-test-suite.cc:262
ns3::Ipv6ExtensionDestinationHeader
Header of IPv6 Extension Destination.
Definition:
ipv6-extension-header.h:280
ns3::Ipv6ExtensionDestinationHeader::GetSerializedSize
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Definition:
ipv6-extension-header.cc:294
TestOptionWithAlignment::TestOptionWithAlignment
TestOptionWithAlignment()
Definition:
ipv6-extension-header-test-suite.cc:182
OptionWithAlignmentHeader::TYPE
static const uint8_t TYPE
Option Type.
Definition:
ipv6-extension-header-test-suite.cc:152
OptionWithoutAlignmentHeader
IPv6 extensions Test: Option without alignment.
Definition:
ipv6-extension-header-test-suite.cc:79
TestFulfilledAlignment
IPv6 extensions Test: Test an option already aligned.
Definition:
ipv6-extension-header-test-suite.cc:228
TestEmptyOptionField::DoRun
virtual void DoRun()
Implementation to actually run this TestCase.
Definition:
ipv6-extension-header-test-suite.cc:48
TestEmptyOptionField
IPv6 extensions Test: Empty option field.
Definition:
ipv6-extension-header-test-suite.cc:43
OptionWithoutAlignmentHeader::GetSerializedSize
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Definition:
ipv6-extension-header-test-suite.cc:84
TestOptionWithoutAlignment
IPv6 extensions Test: Test the option without alignment.
Definition:
ipv6-extension-header-test-suite.cc:104
Generated on Wed Nov 7 2018 10:01:57 for ns-3 by
1.8.14