A Discrete-Event Network Simulator
API
ipv6-address-helper-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 University of Washington
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#include "ns3/internet-stack-helper.h"
19#include "ns3/ipv4-address-helper.h"
20#include "ns3/ipv6-address-generator.h"
21#include "ns3/ipv6-address-helper.h"
22#include "ns3/log.h"
23#include "ns3/net-device-container.h"
24#include "ns3/node-container.h"
25#include "ns3/simple-net-device.h"
26#include "ns3/test.h"
27
28using namespace ns3;
29
37{
38 public:
41
42 private:
43 void DoRun() override;
44 void DoTeardown() override;
45};
46
48 : TestCase("IpAddressHelper Ipv6 test case")
49{
50}
51
53{
54}
55
56void
58{
60 Ipv6Address ipAddr1;
61 ipAddr1 = ip1.NewAddress();
62 // Ipv6AddressHelper that is unconfigured
63 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db8::1"), "Ipv6AddressHelper failure");
64 ipAddr1 = ip1.NewAddress();
65 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db8::2"), "Ipv6AddressHelper failure");
66 ip1.NewNetwork();
67 ipAddr1 = ip1.NewAddress();
69 Ipv6Address("2001:db8:0:1:0:0:0:1"),
70 "Ipv6AddressHelper failure");
71
72 // Reset
73 ip1.SetBase(Ipv6Address("2001:db81::"), Ipv6Prefix(32), Ipv6Address("::1"));
74 ipAddr1 = ip1.NewAddress();
75 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db81::1"), "Ipv6AddressHelper failure");
76 // Skip a few addresses
77 ip1.SetBase(Ipv6Address("2001:db81::"), Ipv6Prefix(32), Ipv6Address("::15"));
78 ipAddr1 = ip1.NewAddress();
79 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db81::15"), "Ipv6AddressHelper failure");
80 ipAddr1 = ip1.NewAddress();
81 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db81::16"), "Ipv6AddressHelper failure");
82 // Skip a some more addresses
83 ip1.SetBase(Ipv6Address("2001:db81::"), Ipv6Prefix(32), Ipv6Address("::ff"));
84 ipAddr1 = ip1.NewAddress();
85 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db81::ff"), "Ipv6AddressHelper failure");
86 ipAddr1 = ip1.NewAddress();
87 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db81::100"), "Ipv6AddressHelper failure");
88 // Increment network
89 ip1.NewNetwork();
90 ipAddr1 = ip1.NewAddress();
91 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db82::ff"), "Ipv6AddressHelper failure");
92
93 // Reset
94 ip1.SetBase(Ipv6Address("2001:dddd::"), Ipv6Prefix(64), Ipv6Address("::1"));
95 ipAddr1 = ip1.NewAddress(); // ::1
96 ipAddr1 = ip1.NewAddress(); // ::2
97 ipAddr1 = ip1.NewAddress(); // ::3
98 ip1.NewNetwork(); // 0:1
99 ip1.NewNetwork(); // 0:2
100 ipAddr1 = ip1.NewAddress(); // ::1 again
101 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:dddd:0:2::1"), "Ipv6AddressHelper failure");
102
103 // Set again
104 ip1.SetBase(Ipv6Address("2001:db82::"), Ipv6Prefix(32));
105 ipAddr1 = ip1.NewAddress();
106 NS_TEST_ASSERT_MSG_EQ(ipAddr1, Ipv6Address("2001:db82::1"), "Ipv6AddressHelper failure");
107
108 // Reset again
109 ip1.SetBase(Ipv6Address("2001:f00d:cafe:00ff::"), Ipv6Prefix(64), Ipv6Address("::1"));
110 ip1.NewNetwork(); // "2001:f00d:cafe:0100::"
111 ipAddr1 = ip1.NewAddress(); // ::1 again
112 NS_TEST_ASSERT_MSG_EQ(ipAddr1,
113 Ipv6Address("2001:f00d:cafe:0100::1"),
114 "Ipv6AddressHelper failure");
115
116 // Test container assignment
118 n.Create(2);
119
120 /* Install IPv4/IPv6 stack */
121 InternetStackHelper internetv6;
122 internetv6.SetIpv4StackInstall(false);
123 internetv6.Install(n);
124
126 Ptr<SimpleNetDevice> s1 = CreateObject<SimpleNetDevice>();
127 s1->SetAddress(Mac48Address::Allocate());
128 n.Get(0)->AddDevice(s1);
129
130 Ptr<SimpleNetDevice> s2 = CreateObject<SimpleNetDevice>();
131 s2->SetAddress(Mac48Address::Allocate());
132 n.Get(1)->AddDevice(s2);
133 d.Add(s1);
134 d.Add(s2);
135
136 ip1.SetBase(Ipv6Address("2001:00aa::"), Ipv6Prefix(56));
138 ic = ip1.Assign(d);
139
140 // Check that d got intended addresses
143 // Interface 0 is loopback, interface 1 is s1, and the 0th addr is linklocal
144 // so we look at address (1,1)
145 d1addr = n.Get(0)->GetObject<Ipv6>()->GetAddress(1, 1);
147 Ipv6Address("2001:00aa:0000:0000:0200:00ff:fe00:0001"),
148 "Ipv6AddressHelper failure");
149 // Look also at the interface container (device 0, address 1)
151 Ipv6Address("2001:00aa:0000:0000:0200:00ff:fe00:0001"),
152 "Ipv6AddressHelper failure");
153 d2addr = n.Get(1)->GetObject<Ipv6>()->GetAddress(1, 1);
154 // Look at second container
156 Ipv6Address("2001:00aa:0000:0000:0200:00ff:fe00:0002"),
157 "Ipv6AddressHelper failure");
158 // Look also at the interface container (device 0, address 1)
160 Ipv6Address("2001:00aa:0000:0000:0200:00ff:fe00:0002"),
161 "Ipv6AddressHelper failure");
162}
163
164void
166{
168 Simulator::Destroy();
169}
170
178{
179 public:
181};
182
184 : TestSuite("ipv6-address-helper", UNIT)
185{
186 AddTestCase(new IpAddressHelperTestCasev6, TestCase::QUICK);
187}
188
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...
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.
Definition: ipv6-address.h:50
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
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.
Definition: ipv6-address.h:456
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:138
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
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_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:144
static Ipv6AddressHelperTestSuite ipv6AddressHelperTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.