A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-address-helper-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#include "ns3/internet-stack-helper.h"
8#include "ns3/ipv4-address-helper.h"
9#include "ns3/ipv6-address-generator.h"
10#include "ns3/ipv6-address-helper.h"
11#include "ns3/log.h"
12#include "ns3/net-device-container.h"
13#include "ns3/node-container.h"
14#include "ns3/simple-net-device.h"
15#include "ns3/test.h"
16
17using namespace ns3;
18
19/**
20 * \ingroup internet-test
21 *
22 * \brief IPv6 AddressHelper Test
23 */
25{
26 public:
29
30 private:
31 void DoRun() override;
32 void DoTeardown() override;
33};
34
36 : TestCase("IpAddressHelper Ipv6 test case")
37{
38}
39
43
44void
46{
48 Ipv6Address ipAddr1;
49 ipAddr1 = ip1.NewAddress();
50 // Ipv6AddressHelper that is unconfigured
51 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db8::1"), "Ipv6AddressHelper failure");
52 ipAddr1 = ip1.NewAddress();
53 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db8::2"), "Ipv6AddressHelper failure");
54 ip1.NewNetwork();
55 ipAddr1 = ip1.NewAddress();
57 Ipv6Address("2001:db8:0:1:0:0:0:1"),
58 "Ipv6AddressHelper failure");
59
60 // Reset
61 ip1.SetBase(Ipv6Address("2001:db81::"), Ipv6Prefix(32), Ipv6Address("::1"));
62 ipAddr1 = ip1.NewAddress();
63 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db81::1"), "Ipv6AddressHelper failure");
64 // Skip a few addresses
65 ip1.SetBase(Ipv6Address("2001:db81::"), Ipv6Prefix(32), Ipv6Address("::15"));
66 ipAddr1 = ip1.NewAddress();
67 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db81::15"), "Ipv6AddressHelper failure");
68 ipAddr1 = ip1.NewAddress();
69 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db81::16"), "Ipv6AddressHelper failure");
70 // Skip a some more addresses
71 ip1.SetBase(Ipv6Address("2001:db81::"), Ipv6Prefix(32), Ipv6Address("::ff"));
72 ipAddr1 = ip1.NewAddress();
73 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db81::ff"), "Ipv6AddressHelper failure");
74 ipAddr1 = ip1.NewAddress();
75 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db81::100"), "Ipv6AddressHelper failure");
76 // Increment network
77 ip1.NewNetwork();
78 ipAddr1 = ip1.NewAddress();
79 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db82::ff"), "Ipv6AddressHelper failure");
80
81 // Reset
82 ip1.SetBase(Ipv6Address("2001:dddd::"), Ipv6Prefix(64), Ipv6Address("::1"));
83 ipAddr1 = ip1.NewAddress(); // ::1
84 ipAddr1 = ip1.NewAddress(); // ::2
85 ipAddr1 = ip1.NewAddress(); // ::3
86 ip1.NewNetwork(); // 0:1
87 ip1.NewNetwork(); // 0:2
88 ipAddr1 = ip1.NewAddress(); // ::1 again
89 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:dddd:0:2::1"), "Ipv6AddressHelper failure");
90
91 // Set again
92 ip1.SetBase(Ipv6Address("2001:db82::"), Ipv6Prefix(32));
93 ipAddr1 = ip1.NewAddress();
94 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db82::1"), "Ipv6AddressHelper failure");
95
96 // Reset again
97 ip1.SetBase(Ipv6Address("2001:f00d:cafe:00ff::"), Ipv6Prefix(64), Ipv6Address("::1"));
98 ip1.NewNetwork(); // "2001:f00d:cafe:0100::"
99 ipAddr1 = ip1.NewAddress(); // ::1 again
100 NS_TEST_ASSERT_MSG_EQ(ipAddr1,
101 Ipv6Address("2001:f00d:cafe:0100::1"),
102 "Ipv6AddressHelper failure");
103
104 // Test container assignment
106 n.Create(2);
107
108 /* Install IPv4/IPv6 stack */
109 InternetStackHelper internetv6;
110 internetv6.SetIpv4StackInstall(false);
111 internetv6.Install(n);
112
115 s1->SetAddress(Mac48Address::Allocate());
116 n.Get(0)->AddDevice(s1);
117
119 s2->SetAddress(Mac48Address::Allocate());
120 n.Get(1)->AddDevice(s2);
121 d.Add(s1);
122 d.Add(s2);
123
124 ip1.SetBase(Ipv6Address("2001:00aa::"), Ipv6Prefix(56));
126 ic = ip1.Assign(d);
127
128 // Check that d got intended addresses
131 // Interface 0 is loopback, interface 1 is s1, and the 0th addr is linklocal
132 // so we look at address (1,1)
133 d1addr = n.Get(0)->GetObject<Ipv6>()->GetAddress(1, 1);
135 Ipv6Address("2001:00aa:0000:0000:0200:00ff:fe00:0001"),
136 "Ipv6AddressHelper failure");
137 // Look also at the interface container (device 0, address 1)
139 Ipv6Address("2001:00aa:0000:0000:0200:00ff:fe00:0001"),
140 "Ipv6AddressHelper failure");
141 d2addr = n.Get(1)->GetObject<Ipv6>()->GetAddress(1, 1);
142 // Look at second container
144 Ipv6Address("2001:00aa:0000:0000:0200:00ff:fe00:0002"),
145 "Ipv6AddressHelper failure");
146 // Look also at the interface container (device 0, address 1)
148 Ipv6Address("2001:00aa:0000:0000:0200:00ff:fe00:0002"),
149 "Ipv6AddressHelper failure");
150}
151
152void
158
159/**
160 * \ingroup internet-test
161 *
162 * \brief IPv6 AddressHelper TestSuite
163 */
165{
166 public:
168};
169
171 : TestSuite("ipv6-address-helper", Type::UNIT)
172{
173 AddTestCase(new IpAddressHelperTestCasev6, TestCase::Duration::QUICK);
174}
175
177 ipv6AddressHelperTestSuite; //!< Static variable for test initialization
void DoRun() override
Implementation to actually run this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
aggregate IP/TCP/UDP functionality to existing Nodes.
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
static void Reset()
Reset the networks and Ipv6Address to zero.
Helper class to auto-assign global IPv6 unicast addresses.
Ipv6Address NewAddress(Address addr)
Allocate a new Ipv6Address.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
void NewNetwork()
Allocate a new network.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Describes an IPv6 address.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
IPv6 address associated with an interface.
Ipv6Address GetAddress() const
Get the IPv6 address.
Keep track of a set of IPv6 interfaces.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Describes an IPv6 prefix.
static Mac48Address Allocate()
Allocate a new Mac48Address.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition node.cc:124
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:134
static Ipv6AddressHelperTestSuite ipv6AddressHelperTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.