A Discrete-Event Network Simulator
API
ipv6-address-generator-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 University of Washington
3 * Copyright (c) 2011 Atishay Jain
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/ipv6-address-generator.h"
20#include "ns3/simulation-singleton.h"
21#include "ns3/test.h"
22
23using namespace ns3;
24
32{
33 public:
35 void DoRun() override;
36 void DoTeardown() override;
37};
38
40 : TestCase("Make sure the network number allocator is working on some of network prefixes.")
41{
42}
43
44void
46{
48}
49
50void
52{
53 Ipv6Address network;
54
55 Ipv6AddressGenerator::Init(Ipv6Address("1::0:0:0"), Ipv6Prefix("FFFF::0"), Ipv6Address("::"));
56 network = Ipv6AddressGenerator::GetNetwork(Ipv6Prefix("FFFF::0"));
58 Ipv6Address("1::0:0:0"),
59 "network should equal the initialized network for given prefix");
60 network = Ipv6AddressGenerator::NextNetwork(Ipv6Prefix("FFFF::0"));
61 NS_TEST_EXPECT_MSG_EQ(network, Ipv6Address("2::0:0:0"), "network should equal next network");
62
63 Ipv6AddressGenerator::Init(Ipv6Address("0:1::0:0"),
64 Ipv6Prefix("FFFF:FFFF::0"),
65 Ipv6Address("::"));
66 network = Ipv6AddressGenerator::GetNetwork(Ipv6Prefix("FFFF:FFFF::0"));
68 Ipv6Address("0:1::0"),
69 "network should equal the initialized network for given prefix");
70 network = Ipv6AddressGenerator::NextNetwork(Ipv6Prefix("FFFF:FFFF::0"));
71 NS_TEST_EXPECT_MSG_EQ(network, Ipv6Address("0:2::0"), "network should equal next network");
72
73 Ipv6AddressGenerator::Init(Ipv6Address("0:0:1::0"),
74 Ipv6Prefix("FFFF:FFFF:FFFF::0"),
75 Ipv6Address("::0"));
76 network = Ipv6AddressGenerator::GetNetwork(Ipv6Prefix("FFFF:FFFF:FFFF::0"));
78 Ipv6Address("0:0:1::0"),
79 "network should equal the initialized network for given prefix");
80 network = Ipv6AddressGenerator::NextNetwork(Ipv6Prefix("FFFF:FFFF:FFFF::0"));
81 NS_TEST_EXPECT_MSG_EQ(network, Ipv6Address("0:0:2::0"), "network should equal next network");
82}
83
91{
92 public:
94
95 private:
96 void DoRun() override;
97 void DoTeardown() override;
98};
99
101 : TestCase("Sanity check on allocation of addresses")
102{
103}
104
105void
107{
109
110 Ipv6AddressGenerator::Init(Ipv6Address("2001::0"), Ipv6Prefix(64));
111 address = Ipv6AddressGenerator::GetNetwork(Ipv6Prefix(64));
113 Ipv6Address("2001::0"),
114 "address should equal the initialized address for given prefix");
115 Ipv6AddressGenerator::NextNetwork(Ipv6Prefix(64));
116 address = Ipv6AddressGenerator::GetNetwork(Ipv6Prefix(64));
118 Ipv6Address("2001:0:0:1::0"),
119 "address should equal the initialized address for given prefix");
120 address = Ipv6AddressGenerator::GetAddress(Ipv6Prefix(64));
122 Ipv6Address("2001:0:0:1::1"),
123 "address should equal the initialized address for given prefix");
124 address = Ipv6AddressGenerator::NextAddress(Ipv6Prefix(64));
126 Ipv6Address("2001:0:0:1::1"),
127 "address should equal the initialized address for given prefix");
128 address = Ipv6AddressGenerator::NextAddress(Ipv6Prefix(64));
130 Ipv6Address("2001:0:0:1::2"),
131 "address should equal the initialized address for given prefix");
132
133 Ipv6AddressGenerator::Init(Ipv6Address("1::"), Ipv6Prefix("FFFF::"), Ipv6Address("::3"));
134 address = Ipv6AddressGenerator::NextAddress(Ipv6Prefix(16));
136 Ipv6Address("1::3"),
137 "address should equal initialized address for given prefix");
138 address = Ipv6AddressGenerator::NextAddress(Ipv6Prefix(16));
139 NS_TEST_EXPECT_MSG_EQ(address, Ipv6Address("1::4"), "address should equal next address");
140}
141
142void
144{
146 Simulator::Destroy();
147}
148
156{
157 public:
159 void DoRun() override;
160 void DoTeardown() override;
161};
162
164 : TestCase("Make sure Network and address allocation play together.")
165{
166}
167
168void
170{
172 Simulator::Destroy();
173}
174
175void
177{
179 Ipv6Address network;
180
181 Ipv6AddressGenerator::Init(Ipv6Address("3::"), Ipv6Prefix("FFFF::"), Ipv6Address("::3"));
182 address = Ipv6AddressGenerator::NextAddress(Ipv6Prefix(16));
184 Ipv6Address("3::3"),
185 "address should equal initialized address for given prefix");
186 address = Ipv6AddressGenerator::NextAddress(Ipv6Prefix(16));
188 Ipv6Address("3::4"),
189 "address should equal next address for given prefix");
190
191 network = Ipv6AddressGenerator::NextNetwork(Ipv6Prefix("FFFF::"));
192 NS_TEST_EXPECT_MSG_EQ(network,
193 Ipv6Address("4::0"),
194 "address should equal next address for given prefix");
195 address = Ipv6AddressGenerator::NextAddress(Ipv6Prefix(16));
197 Ipv6Address("4::3"),
198 "address should equal next address for given prefix");
199}
200
208{
209 public:
211
212 private:
213 void DoRun() override;
214 void DoTeardown() override;
215};
216
218 : TestCase("A typical real-world example")
219{
220}
221
222void
224{
226}
227
228void
230{
232
233 Ipv6AddressGenerator::Init(Ipv6Address("2001:0AB8::"),
234 Ipv6Prefix("FFFF:FFFF:FFFF::0"),
235 Ipv6Address("::3"));
236 address = Ipv6AddressGenerator::NextAddress(Ipv6Prefix(48));
238 Ipv6Address("2001:0AB8::0:3"),
239 "address should equal initialized address for given prefix");
240 address = Ipv6AddressGenerator::NextAddress(Ipv6Prefix(48));
242 Ipv6Address("2001:0AB8::0:4"),
243 "address should equal next address for given prefix");
244 address = Ipv6AddressGenerator::NextAddress(Ipv6Prefix(48));
246 Ipv6Address("2001:0AB8::0:5"),
247 "address should equal next address for given prefix");
248 //
249 // Allocate the next network based on the prefix passed in, which should
250 // be 2001:0AB0:0001
251 //
252 Ipv6AddressGenerator::NextNetwork(Ipv6Prefix("FFFF:FFFF:FFFF::0"));
253 //
254 // reset first address to be allocated back to ::0:3
255 //
256 Ipv6AddressGenerator::InitAddress(Ipv6Address("::3"), Ipv6Prefix(48));
257 //
258 // The first address we should get is the network and address ORed
259 //
260 address = Ipv6AddressGenerator::NextAddress(Ipv6Prefix(48));
262 Ipv6Address("2001:0AB8:1::3"),
263 "address should equal initialized address for given prefix");
264}
265
273{
274 public:
276
277 private:
278 void DoRun() override;
279 void DoTeardown() override;
280};
281
283 : TestCase("Make sure that the address collision logic works.")
284{
285}
286
287void
289{
291 Simulator::Destroy();
292}
293
294void
296{
297 Ipv6AddressGenerator::AddAllocated("0::0:5");
298 Ipv6AddressGenerator::AddAllocated("0::0:10");
299 Ipv6AddressGenerator::AddAllocated("0::0:15");
300 Ipv6AddressGenerator::AddAllocated("0::0:20");
301
302 Ipv6AddressGenerator::AddAllocated("0::0:4");
303 Ipv6AddressGenerator::AddAllocated("0::0:3");
304 Ipv6AddressGenerator::AddAllocated("0::0:2");
305 Ipv6AddressGenerator::AddAllocated("0::0:1");
306
307 Ipv6AddressGenerator::AddAllocated("0::0:6");
308 Ipv6AddressGenerator::AddAllocated("0::0:7");
309 Ipv6AddressGenerator::AddAllocated("0::0:8");
310 Ipv6AddressGenerator::AddAllocated("0::0:9");
311
312 Ipv6AddressGenerator::AddAllocated("0::0:11");
313 Ipv6AddressGenerator::AddAllocated("0::0:12");
314 Ipv6AddressGenerator::AddAllocated("0::0:13");
315 Ipv6AddressGenerator::AddAllocated("0::0:14");
316
317 Ipv6AddressGenerator::AddAllocated("0::0:19");
318 Ipv6AddressGenerator::AddAllocated("0::0:18");
319 Ipv6AddressGenerator::AddAllocated("0::0:17");
320 Ipv6AddressGenerator::AddAllocated("0::0:16");
321
322 Ipv6AddressGenerator::TestMode();
323 bool added = Ipv6AddressGenerator::AddAllocated("0::0:21");
324 NS_TEST_EXPECT_MSG_EQ(added, true, "address should get allocated");
325
326 added = Ipv6AddressGenerator::AddAllocated("0::0:4");
327 NS_TEST_EXPECT_MSG_EQ(added, false, "address should not get allocated");
328
329 added = Ipv6AddressGenerator::AddAllocated("0::0:9");
330 NS_TEST_EXPECT_MSG_EQ(added, false, "address should not get allocated");
331
332 added = Ipv6AddressGenerator::AddAllocated("0::0:16");
333 NS_TEST_EXPECT_MSG_EQ(added, false, "address should not get allocated");
334
335 added = Ipv6AddressGenerator::AddAllocated("0::0:21");
336 NS_TEST_EXPECT_MSG_EQ(added, false, "address should not get allocated");
337}
338
346{
347 public:
349 : TestSuite("ipv6-address-generator")
350 {
351 AddTestCase(new NetworkNumber6AllocatorTestCase(), TestCase::QUICK);
352 AddTestCase(new AddressAllocator6TestCase(), TestCase::QUICK);
353 AddTestCase(new NetworkAndAddress6TestCase(), TestCase::QUICK);
354 AddTestCase(new ExampleAddress6GeneratorTestCase(), TestCase::QUICK);
355 AddTestCase(new AddressCollision6TestCase(), TestCase::QUICK);
356 }
357};
358
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
IPv6 example of an address generator Test.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
IPv6 network number and address allocator Test.
void DoRun() override
Implementation to actually run this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
IPv6 network number allocator Test.
void DoRun() override
Implementation to actually run this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
Describes an IPv6 address.
Definition: ipv6-address.h:50
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
void Reset()
Reset the initial value of every attribute as well as the value of every global to what they were bef...
Definition: config.cc:856
#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:251
static Ipv6AddressGeneratorTestSuite g_ipv6AddressGeneratorTestSuite
Static variable for test initialization.
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.