A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
31{
32 public:
34 void DoRun() override;
35 void DoTeardown() override;
36};
37
39 : TestCase("Make sure the network number allocator is working on some of network prefixes.")
40{
41}
42
43void
45{
47}
48
49void
51{
52 Ipv6Address network;
53
54 Ipv6AddressGenerator::Init(Ipv6Address("1::0:0:0"), Ipv6Prefix("FFFF::0"), Ipv6Address("::"));
55 network = Ipv6AddressGenerator::GetNetwork(Ipv6Prefix("FFFF::0"));
57 Ipv6Address("1::0:0:0"),
58 "network should equal the initialized network for given prefix");
60 NS_TEST_EXPECT_MSG_EQ(network, Ipv6Address("2::0:0:0"), "network should equal next network");
61
63 Ipv6Prefix("FFFF:FFFF::0"),
64 Ipv6Address("::"));
65 network = Ipv6AddressGenerator::GetNetwork(Ipv6Prefix("FFFF:FFFF::0"));
67 Ipv6Address("0:1::0"),
68 "network should equal the initialized network for given prefix");
69 network = Ipv6AddressGenerator::NextNetwork(Ipv6Prefix("FFFF:FFFF::0"));
70 NS_TEST_EXPECT_MSG_EQ(network, Ipv6Address("0:2::0"), "network should equal next network");
71
73 Ipv6Prefix("FFFF:FFFF:FFFF::0"),
74 Ipv6Address("::0"));
75 network = Ipv6AddressGenerator::GetNetwork(Ipv6Prefix("FFFF:FFFF:FFFF::0"));
77 Ipv6Address("0:0:1::0"),
78 "network should equal the initialized network for given prefix");
79 network = Ipv6AddressGenerator::NextNetwork(Ipv6Prefix("FFFF:FFFF:FFFF::0"));
80 NS_TEST_EXPECT_MSG_EQ(network, Ipv6Address("0:0:2::0"), "network should equal next network");
81}
82
89{
90 public:
92
93 private:
94 void DoRun() override;
95 void DoTeardown() override;
96};
97
99 : TestCase("Sanity check on allocation of addresses")
100{
101}
102
103void
105{
106 Ipv6Address address;
107
110 NS_TEST_EXPECT_MSG_EQ(address,
111 Ipv6Address("2001::0"),
112 "address should equal the initialized address for given prefix");
115 NS_TEST_EXPECT_MSG_EQ(address,
116 Ipv6Address("2001:0:0:1::0"),
117 "address should equal the initialized address for given prefix");
119 NS_TEST_EXPECT_MSG_EQ(address,
120 Ipv6Address("2001:0:0:1::1"),
121 "address should equal the initialized address for given prefix");
123 NS_TEST_EXPECT_MSG_EQ(address,
124 Ipv6Address("2001:0:0:1::1"),
125 "address should equal the initialized address for given prefix");
127 NS_TEST_EXPECT_MSG_EQ(address,
128 Ipv6Address("2001:0:0:1::2"),
129 "address should equal the initialized address for given prefix");
130
133 NS_TEST_EXPECT_MSG_EQ(address,
134 Ipv6Address("1::3"),
135 "address should equal initialized address for given prefix");
137 NS_TEST_EXPECT_MSG_EQ(address, Ipv6Address("1::4"), "address should equal next address");
138}
139
140void
142{
145}
146
153{
154 public:
156 void DoRun() override;
157 void DoTeardown() override;
158};
159
161 : TestCase("Make sure Network and address allocation play together.")
162{
163}
164
165void
167{
170}
171
172void
174{
175 Ipv6Address address;
176 Ipv6Address network;
177
180 NS_TEST_EXPECT_MSG_EQ(address,
181 Ipv6Address("3::3"),
182 "address should equal initialized address for given prefix");
184 NS_TEST_EXPECT_MSG_EQ(address,
185 Ipv6Address("3::4"),
186 "address should equal next address for given prefix");
187
189 NS_TEST_EXPECT_MSG_EQ(network,
190 Ipv6Address("4::0"),
191 "address should equal next address for given prefix");
193 NS_TEST_EXPECT_MSG_EQ(address,
194 Ipv6Address("4::3"),
195 "address should equal next address for given prefix");
196}
197
204{
205 public:
207
208 private:
209 void DoRun() override;
210 void DoTeardown() override;
211};
212
214 : TestCase("A typical real-world example")
215{
216}
217
218void
220{
222}
223
224void
226{
227 Ipv6Address address;
228
230 Ipv6Prefix("FFFF:FFFF:FFFF::0"),
231 Ipv6Address("::3"));
233 NS_TEST_EXPECT_MSG_EQ(address,
234 Ipv6Address("2001:0AB8::0:3"),
235 "address should equal initialized address for given prefix");
237 NS_TEST_EXPECT_MSG_EQ(address,
238 Ipv6Address("2001:0AB8::0:4"),
239 "address should equal next address for given prefix");
241 NS_TEST_EXPECT_MSG_EQ(address,
242 Ipv6Address("2001:0AB8::0:5"),
243 "address should equal next address for given prefix");
244 //
245 // Allocate the next network based on the prefix passed in, which should
246 // be 2001:0AB0:0001
247 //
248 Ipv6AddressGenerator::NextNetwork(Ipv6Prefix("FFFF:FFFF:FFFF::0"));
249 //
250 // reset first address to be allocated back to ::0:3
251 //
253 //
254 // The first address we should get is the network and address ORed
255 //
257 NS_TEST_EXPECT_MSG_EQ(address,
258 Ipv6Address("2001:0AB8:1::3"),
259 "address should equal initialized address for given prefix");
260}
261
268{
269 public:
271
272 private:
273 void DoRun() override;
274 void DoTeardown() override;
275};
276
278 : TestCase("Make sure that the address collision logic works.")
279{
280}
281
282void
284{
287}
288
289void
291{
296
301
306
311
316
318 bool added = Ipv6AddressGenerator::AddAllocated("0::0:21");
319 NS_TEST_EXPECT_MSG_EQ(added, true, "address should get allocated");
320
321 added = Ipv6AddressGenerator::AddAllocated("0::0:4");
322 NS_TEST_EXPECT_MSG_EQ(added, false, "address should not get allocated");
323
324 added = Ipv6AddressGenerator::AddAllocated("0::0:9");
325 NS_TEST_EXPECT_MSG_EQ(added, false, "address should not get allocated");
326
327 added = Ipv6AddressGenerator::AddAllocated("0::0:16");
328 NS_TEST_EXPECT_MSG_EQ(added, false, "address should not get allocated");
329
330 added = Ipv6AddressGenerator::AddAllocated("0::0:21");
331 NS_TEST_EXPECT_MSG_EQ(added, false, "address should not get allocated");
332}
333
340{
341 public:
343 : TestSuite("ipv6-address-generator")
344 {
350 }
351};
352
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.
static void Init(const Ipv6Address net, const Ipv6Prefix prefix, const Ipv6Address interfaceId="::1")
Initialise the base network and interfaceId for the generator.
static void TestMode()
Used to turn off fatal errors and assertions, for testing.
static Ipv6Address NextAddress(const Ipv6Prefix prefix)
Allocate the next Ipv6Address for the configured network and prefix.
static Ipv6Address GetNetwork(const Ipv6Prefix prefix)
Get the current network of the given Ipv6Prefix.
static void InitAddress(const Ipv6Address interfaceId, const Ipv6Prefix prefix)
Set the interfaceId for the given Ipv6Prefix.
static bool AddAllocated(const Ipv6Address addr)
Add the Ipv6Address to the list of IPv6 entries.
static Ipv6Address GetAddress(const Ipv6Prefix prefix)
Get the Ipv6Address that will be allocated upon NextAddress ()
static Ipv6Address NextNetwork(const Ipv6Prefix prefix)
Get the next network according to the given Ipv6Prefix.
static void Reset()
Reset the networks and Ipv6Address to zero.
Describes an IPv6 address.
Definition: ipv6-address.h:49
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
#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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.