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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
ipv4-address-helper-test-suite.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008 University of Washington
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
#include "ns3/test.h"
20
#include "ns3/ipv4-address-generator.h"
21
#include "ns3/ipv4-address-helper.h"
22
#include "ns3/simulator.h"
23
24
using namespace
ns3;
25
26
class
NetworkAllocatorHelperTestCase
:
public
TestCase
27
{
28
public
:
29
NetworkAllocatorHelperTestCase
();
30
private
:
31
virtual
void
DoRun (
void
);
32
virtual
void
DoTeardown (
void
);
33
};
34
35
NetworkAllocatorHelperTestCase::NetworkAllocatorHelperTestCase
()
36
:
TestCase
(
"Make sure the network allocator part is working on some common network prefixes."
)
37
{
38
}
39
40
void
41
NetworkAllocatorHelperTestCase::DoTeardown
(
void
)
42
{
43
Ipv4AddressGenerator::Reset
();
44
Simulator::Destroy ();
45
}
46
void
47
NetworkAllocatorHelperTestCase::DoRun
(
void
)
48
{
49
Ipv4Address
address
;
50
Ipv4Address
network;
51
Ipv4AddressHelper
h;
52
53
h.
SetBase
(
"1.0.0.0"
,
"255.0.0.0"
);
54
network = h.
NewNetwork
();
55
NS_TEST_EXPECT_MSG_EQ
(network,
Ipv4Address
(
"2.0.0.0"
),
"100"
);
56
address = h.
NewAddress
();
57
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"2.0.0.1"
),
"101"
);
58
59
h.
SetBase
(
"0.1.0.0"
,
"255.255.0.0"
);
60
network = h.
NewNetwork
();
61
NS_TEST_EXPECT_MSG_EQ
(network,
Ipv4Address
(
"0.2.0.0"
),
"102"
);
62
address = h.
NewAddress
();
63
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"0.2.0.1"
),
"103"
);
64
65
h.
SetBase
(
"0.0.1.0"
,
"255.255.255.0"
);
66
network = h.
NewNetwork
();
67
NS_TEST_EXPECT_MSG_EQ
(network,
Ipv4Address
(
"0.0.2.0"
),
"104"
);
68
address = h.
NewAddress
();
69
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"0.0.2.1"
),
"105"
);
70
}
71
72
class
AddressAllocatorHelperTestCase
:
public
TestCase
73
{
74
public
:
75
AddressAllocatorHelperTestCase
();
76
private
:
77
virtual
void
DoRun
(
void
);
78
virtual
void
DoTeardown
(
void
);
79
};
80
81
AddressAllocatorHelperTestCase::AddressAllocatorHelperTestCase
()
82
:
TestCase
(
"Make sure the address allocator part is working"
)
83
{
84
}
85
86
void
87
AddressAllocatorHelperTestCase::DoTeardown
(
void
)
88
{
89
Ipv4AddressGenerator::Reset
();
90
Simulator::Destroy ();
91
}
92
93
void
94
AddressAllocatorHelperTestCase::DoRun
(
void
)
95
{
96
Ipv4Address
network;
97
Ipv4Address
address
;
98
Ipv4AddressHelper
h;
99
100
h.
SetBase
(
"1.0.0.0"
,
"255.0.0.0"
,
"0.0.0.3"
);
101
address = h.
NewAddress
();
102
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"1.0.0.3"
),
"200"
);
103
address = h.
NewAddress
();
104
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"1.0.0.4"
),
"201"
);
105
106
h.
SetBase
(
"0.1.0.0"
,
"255.255.0.0"
,
"0.0.0.3"
);
107
address = h.
NewAddress
();
108
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"0.1.0.3"
),
"202"
);
109
address = h.
NewAddress
();
110
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"0.1.0.4"
),
"203"
);
111
112
h.
SetBase
(
"0.0.1.0"
,
"255.255.255.0"
,
"0.0.0.3"
);
113
address = h.
NewAddress
();
114
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"0.0.1.3"
),
"204"
);
115
address = h.
NewAddress
();
116
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"0.0.1.4"
),
"205"
);
117
}
118
119
class
ResetAllocatorHelperTestCase
:
public
TestCase
120
{
121
public
:
122
ResetAllocatorHelperTestCase
();
123
virtual
void
DoRun
(
void
);
124
virtual
void
DoTeardown
(
void
);
125
};
126
127
ResetAllocatorHelperTestCase::ResetAllocatorHelperTestCase
()
128
:
TestCase
(
"Make sure the reset to base behavior is working"
)
129
{
130
}
131
132
void
133
ResetAllocatorHelperTestCase::DoRun
(
void
)
134
{
135
Ipv4Address
network;
136
Ipv4Address
address
;
137
Ipv4AddressHelper
h;
138
139
//
140
// We're going to use some of the same addresses allocated above,
141
// so reset the Ipv4AddressGenerator to make it forget we did.
142
//
143
144
h.
SetBase
(
"1.0.0.0"
,
"255.0.0.0"
,
"0.0.0.3"
);
145
address = h.
NewAddress
();
146
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"1.0.0.3"
),
"301"
);
147
address = h.
NewAddress
();
148
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"1.0.0.4"
),
"302"
);
149
network = h.
NewNetwork
();
150
NS_TEST_EXPECT_MSG_EQ
(network,
Ipv4Address
(
"2.0.0.0"
),
"303"
);
151
address = h.
NewAddress
();
152
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"2.0.0.3"
),
"304"
);
153
154
h.
SetBase
(
"0.1.0.0"
,
"255.255.0.0"
,
"0.0.0.3"
);
155
address = h.
NewAddress
();
156
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"0.1.0.3"
),
"305"
);
157
address = h.
NewAddress
();
158
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"0.1.0.4"
),
"306"
);
159
network = h.
NewNetwork
();
160
NS_TEST_EXPECT_MSG_EQ
(network,
Ipv4Address
(
"0.2.0.0"
),
"307"
);
161
address = h.
NewAddress
();
162
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"0.2.0.3"
),
"308"
);
163
164
h.
SetBase
(
"0.0.1.0"
,
"255.255.255.0"
,
"0.0.0.3"
);
165
address = h.
NewAddress
();
166
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"0.0.1.3"
),
"309"
);
167
address = h.
NewAddress
();
168
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"0.0.1.4"
),
"310"
);
169
network = h.
NewNetwork
();
170
NS_TEST_EXPECT_MSG_EQ
(network,
Ipv4Address
(
"0.0.2.0"
),
"311"
);
171
address = h.
NewAddress
();
172
NS_TEST_EXPECT_MSG_EQ
(address,
Ipv4Address
(
"0.0.2.3"
),
"312"
);
173
}
174
175
void
176
ResetAllocatorHelperTestCase::DoTeardown
(
void
)
177
{
178
Ipv4AddressGenerator::Reset
();
179
Simulator::Destroy ();
180
}
181
182
class
IpAddressHelperTestCasev4
:
public
TestCase
183
{
184
public
:
185
IpAddressHelperTestCasev4
();
186
virtual
~IpAddressHelperTestCasev4
();
187
188
private
:
189
virtual
void
DoRun
(
void
);
190
virtual
void
DoTeardown
(
void
);
191
};
192
193
IpAddressHelperTestCasev4::IpAddressHelperTestCasev4
()
194
:
TestCase
(
"IpAddressHelper Ipv4 test case (similar to IPv6)"
)
195
{
196
}
197
198
IpAddressHelperTestCasev4::~IpAddressHelperTestCasev4
()
199
{
200
}
201
202
void
203
IpAddressHelperTestCasev4::DoRun
(
void
)
204
{
205
Ipv4AddressHelper
ip1;
206
Ipv4Address
ipAddr1;
207
ipAddr1 = ip1.
NewAddress
();
208
// Ipv4AddressHelper that is unconfigured
209
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv4Address
(
"255.255.255.255"
),
"Ipv4AddressHelper failure"
);
210
211
ip1.
SetBase
(
"192.168.0.0"
,
"255.255.255.0"
);
212
ipAddr1 = ip1.
NewAddress
();
213
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv4Address
(
"192.168.0.1"
),
"Ipv4AddressHelper failure"
);
214
ipAddr1 = ip1.
NewAddress
();
215
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv4Address
(
"192.168.0.2"
),
"Ipv4AddressHelper failure"
);
216
ip1.
NewNetwork
();
217
ipAddr1 = ip1.
NewAddress
();
218
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv4Address
(
"192.168.1.1"
),
"Ipv4AddressHelper failure"
);
219
ip1.
NewNetwork
();
// 192.168.2
220
ip1.
NewNetwork
();
// 192.168.3
221
ip1.
NewNetwork
();
// 192.168.4
222
ipAddr1 = ip1.
NewAddress
();
// 4.1
223
ipAddr1 = ip1.
NewAddress
();
// 4.2
224
ipAddr1 = ip1.
NewAddress
();
// 4.3
225
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv4Address
(
"192.168.4.3"
),
"Ipv4AddressHelper failure"
);
226
227
// reset base to start at 192.168.0.100
228
ip1.
SetBase
(
"192.168.0.0"
,
"255.255.255.0"
,
"0.0.0.100"
);
229
ipAddr1 = ip1.
NewAddress
();
230
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv4Address
(
"192.168.0.100"
),
"Ipv4AddressHelper failure"
);
231
232
// rollover
233
ip1.
SetBase
(
"192.168.0.0"
,
"255.255.255.0"
,
"0.0.0.254"
);
234
ipAddr1 = ip1.
NewAddress
();
// .254
235
NS_TEST_ASSERT_MSG_EQ
(ipAddr1,
Ipv4Address
(
"192.168.0.254"
),
"Ipv4AddressHelper failure"
);
236
// The below will overflow and assert, so it is commented out
237
// ipAddr1 = ip1.NewAddress (); // .255
238
239
// create with arguments
240
Ipv4AddressHelper
ip2 =
Ipv4AddressHelper
(
"192.168.1.0"
,
"255.255.255.0"
,
"0.0.0.1"
);
241
// duplicate assignment
242
ip2.
NewNetwork
();
// 192.168.2
243
ip2.
NewNetwork
();
// 192.168.3
244
ip2.
NewNetwork
();
// 192.168.4
245
// Uncomment below, and 192.168.4.1 will crash since it was allocated above
246
// ipAddr1 = ip2.NewAddress (); // 4.1
247
248
}
249
250
void
251
IpAddressHelperTestCasev4::DoTeardown
(
void
)
252
{
253
Ipv4AddressGenerator::Reset
();
254
Simulator::Destroy ();
255
}
256
257
258
static
class
Ipv4AddressHelperTestSuite
:
public
TestSuite
259
{
260
public
:
261
Ipv4AddressHelperTestSuite
()
262
:
TestSuite
(
"ipv4-address-helper"
,
UNIT
)
263
{
264
AddTestCase
(
new
NetworkAllocatorHelperTestCase
(), TestCase::QUICK);
265
AddTestCase
(
new
AddressAllocatorHelperTestCase
(), TestCase::QUICK);
266
AddTestCase
(
new
ResetAllocatorHelperTestCase
(), TestCase::QUICK);
267
AddTestCase
(
new
IpAddressHelperTestCasev4
(), TestCase::QUICK);
268
}
269
}
g_ipv4AddressHelperTestSuite
;
IpAddressHelperTestCasev4
Definition:
ipv4-address-helper-test-suite.cc:182
ns3::Config::Reset
void Reset(void)
Definition:
config.cc:642
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1025
ResetAllocatorHelperTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
ipv4-address-helper-test-suite.cc:133
IpAddressHelperTestCasev4::IpAddressHelperTestCasev4
IpAddressHelperTestCasev4()
Definition:
ipv4-address-helper-test-suite.cc:193
ResetAllocatorHelperTestCase::ResetAllocatorHelperTestCase
ResetAllocatorHelperTestCase()
Definition:
ipv4-address-helper-test-suite.cc:127
ns3::TestCase
encapsulates test code
Definition:
test.h:849
ResetAllocatorHelperTestCase
Definition:
ipv4-address-helper-test-suite.cc:119
Ipv4AddressHelperTestSuite
Definition:
ipv4-address-helper-test-suite.cc:258
ns3::Ipv4AddressHelper::NewAddress
Ipv4Address NewAddress(void)
Increment the IP address counter used to allocate IP addresses.
Definition:
ipv4-address-helper.cc:98
IpAddressHelperTestCasev4::DoTeardown
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
Definition:
ipv4-address-helper-test-suite.cc:251
AddressAllocatorHelperTestCase::DoTeardown
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
Definition:
ipv4-address-helper-test-suite.cc:87
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:244
ResetAllocatorHelperTestCase::DoTeardown
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
Definition:
ipv4-address-helper-test-suite.cc:176
NetworkAllocatorHelperTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
ipv4-address-helper-test-suite.cc:47
AddressAllocatorHelperTestCase::AddressAllocatorHelperTestCase
AddressAllocatorHelperTestCase()
Definition:
ipv4-address-helper-test-suite.cc:81
g_ipv4AddressHelperTestSuite
Ipv4AddressHelperTestSuite g_ipv4AddressHelperTestSuite
NetworkAllocatorHelperTestCase::NetworkAllocatorHelperTestCase
NetworkAllocatorHelperTestCase()
Definition:
ipv4-address-helper-test-suite.cc:35
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition:
test.cc:172
Ipv4AddressHelperTestSuite::Ipv4AddressHelperTestSuite
Ipv4AddressHelperTestSuite()
Definition:
ipv4-address-helper-test-suite.cc:261
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:38
ns3::Ipv4AddressHelper::NewNetwork
Ipv4Address NewNetwork(void)
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
Definition:
ipv4-address-helper.cc:122
NetworkAllocatorHelperTestCase
Definition:
ipv4-address-helper-test-suite.cc:26
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition:
ipv4-address-helper.h:45
NetworkAllocatorHelperTestCase::DoTeardown
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
Definition:
ipv4-address-helper-test-suite.cc:41
first.address
tuple address
Definition:
first.py:37
ns3::TestSuite::UNIT
This test suite implements a Unit Test.
Definition:
test.h:1035
IpAddressHelperTestCasev4::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
ipv4-address-helper-test-suite.cc:203
AddressAllocatorHelperTestCase
Definition:
ipv4-address-helper-test-suite.cc:72
ns3::Ipv4AddressHelper::SetBase
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Definition:
ipv4-address-helper.cc:60
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:137
AddressAllocatorHelperTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
ipv4-address-helper-test-suite.cc:94
IpAddressHelperTestCasev4::~IpAddressHelperTestCasev4
virtual ~IpAddressHelperTestCasev4()
Definition:
ipv4-address-helper-test-suite.cc:198
src
internet
test
ipv4-address-helper-test-suite.cc
Generated on Sat Nov 16 2013 16:17:43 for ns-3 by
1.8.5