A Discrete-Event Network Simulator
API
ipv6-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) 2012 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/ipv6-address-helper.h"
20 #include "ns3/ipv6-address-generator.h"
21 #include "ns3/ipv4-address-helper.h"
22 #include "ns3/simple-net-device.h"
23 #include "ns3/net-device-container.h"
24 #include "ns3/node-container.h"
25 #include "ns3/internet-stack-helper.h"
26 #include "ns3/test.h"
27 #include "ns3/log.h"
28 
29 using namespace ns3;
30 
38 {
39 public:
41  virtual ~IpAddressHelperTestCasev6 ();
42 
43 private:
44  virtual void DoRun (void);
45  virtual void DoTeardown (void);
46 };
47 
49  : TestCase ("IpAddressHelper Ipv6 test case")
50 {
51 }
52 
54 {
55 }
56 
57 void
59 {
61  Ipv6Address ipAddr1;
62  ipAddr1 = ip1.NewAddress ();
63  // Ipv6AddressHelper that is unconfigured
64  NS_TEST_ASSERT_MSG_EQ (ipAddr1, Ipv6Address ("2001:db8::1"), "Ipv6AddressHelper failure");
65  ipAddr1 = ip1.NewAddress ();
66  NS_TEST_ASSERT_MSG_EQ (ipAddr1, Ipv6Address ("2001:db8::2"), "Ipv6AddressHelper failure");
67  ip1.NewNetwork ();
68  ipAddr1 = ip1.NewAddress ();
69  NS_TEST_ASSERT_MSG_EQ (ipAddr1, Ipv6Address ("2001:db8:0:1:0:0:0:1"), "Ipv6AddressHelper failure");
70 
71  // Reset
72  ip1.SetBase (Ipv6Address ("2001:db81::"), Ipv6Prefix (32), Ipv6Address ("::1"));
73  ipAddr1 = ip1.NewAddress ();
74  NS_TEST_ASSERT_MSG_EQ (ipAddr1, Ipv6Address ("2001:db81::1"), "Ipv6AddressHelper failure");
75  // Skip a few addresses
76  ip1.SetBase (Ipv6Address ("2001:db81::"), Ipv6Prefix (32), Ipv6Address ("::15"));
77  ipAddr1 = ip1.NewAddress ();
78  NS_TEST_ASSERT_MSG_EQ (ipAddr1, Ipv6Address ("2001:db81::15"), "Ipv6AddressHelper failure");
79  ipAddr1 = ip1.NewAddress ();
80  NS_TEST_ASSERT_MSG_EQ (ipAddr1, Ipv6Address ("2001:db81::16"), "Ipv6AddressHelper failure");
81  // Skip a some more addresses
82  ip1.SetBase (Ipv6Address ("2001:db81::"), Ipv6Prefix (32), Ipv6Address ("::ff"));
83  ipAddr1 = ip1.NewAddress ();
84  NS_TEST_ASSERT_MSG_EQ (ipAddr1, Ipv6Address ("2001:db81::ff"), "Ipv6AddressHelper failure");
85  ipAddr1 = ip1.NewAddress ();
86  NS_TEST_ASSERT_MSG_EQ (ipAddr1, Ipv6Address ("2001:db81::100"), "Ipv6AddressHelper failure");
87  // Increment network
88  ip1.NewNetwork ();
89  ipAddr1 = ip1.NewAddress ();
90  NS_TEST_ASSERT_MSG_EQ (ipAddr1, Ipv6Address ("2001:db82::ff"), "Ipv6AddressHelper failure");
91 
92  // Reset
93  ip1.SetBase (Ipv6Address ("2001:dddd::"), Ipv6Prefix (64), Ipv6Address ("::1"));
94  ipAddr1 = ip1.NewAddress (); // ::1
95  ipAddr1 = ip1.NewAddress (); // ::2
96  ipAddr1 = ip1.NewAddress (); // ::3
97  ip1.NewNetwork (); // 0:1
98  ip1.NewNetwork (); // 0:2
99  ipAddr1 = ip1.NewAddress (); // ::1 again
100  NS_TEST_ASSERT_MSG_EQ (ipAddr1, Ipv6Address ("2001:dddd:0:2::1"), "Ipv6AddressHelper failure");
101 
102  // Set again
103  ip1.SetBase (Ipv6Address ("2001:db82::"), Ipv6Prefix (32));
104  ipAddr1 = ip1.NewAddress ();
105  NS_TEST_ASSERT_MSG_EQ (ipAddr1, Ipv6Address ("2001:db82::1"), "Ipv6AddressHelper failure");
106 
107  // Reset again
108  ip1.SetBase (Ipv6Address ("2001:f00d:cafe:00ff::"), Ipv6Prefix (64), Ipv6Address ("::1"));
109  ip1.NewNetwork (); // "2001:f00d:cafe:0100::"
110  ipAddr1 = ip1.NewAddress (); // ::1 again
111  NS_TEST_ASSERT_MSG_EQ (ipAddr1, Ipv6Address ("2001:f00d:cafe:0100::1"), "Ipv6AddressHelper failure");
112 
113  // Test container assignment
115  n.Create (2);
116 
117  /* Install IPv4/IPv6 stack */
118  InternetStackHelper internetv6;
119  internetv6.SetIpv4StackInstall (false);
120  internetv6.Install (n);
121 
123  Ptr<SimpleNetDevice> s1 = CreateObject<SimpleNetDevice> ();
124  s1->SetAddress (Mac48Address::Allocate ());
125  n.Get (0)->AddDevice (s1);
126 
127  Ptr<SimpleNetDevice> s2 = CreateObject<SimpleNetDevice> ();
128  s2->SetAddress (Mac48Address::Allocate ());
129  n.Get (1)->AddDevice (s2);
130  d.Add (s1);
131  d.Add (s2);
132 
133  ip1.SetBase (Ipv6Address ("2001:00aa::"), Ipv6Prefix (56));
135  ic = ip1.Assign (d);
136 
137  // Check that d got intended addresses
138  Ipv6InterfaceAddress d1addr;
139  Ipv6InterfaceAddress d2addr;
140  // Interface 0 is loopback, interface 1 is s1, and the 0th addr is linklocal
141  // so we look at address (1,1)
142  d1addr = n.Get (0)->GetObject <Ipv6> ()->GetAddress (1, 1);
143  NS_TEST_ASSERT_MSG_EQ (d1addr.GetAddress (), Ipv6Address ("2001:00aa:0000:0000:0200:00ff:fe00:0001"), "Ipv6AddressHelper failure");
144  // Look also at the interface container (device 0, address 1)
145  NS_TEST_ASSERT_MSG_EQ (ic.GetAddress (0,1), Ipv6Address ("2001:00aa:0000:0000:0200:00ff:fe00:0001"), "Ipv6AddressHelper failure");
146  d2addr = n.Get (1)->GetObject <Ipv6> ()->GetAddress (1, 1);
147  // Look at second container
148  NS_TEST_ASSERT_MSG_EQ (d2addr.GetAddress (), Ipv6Address ("2001:00aa:0000:0000:0200:00ff:fe00:0002"), "Ipv6AddressHelper failure");
149  // Look also at the interface container (device 0, address 1)
150  NS_TEST_ASSERT_MSG_EQ (ic.GetAddress (1,1), Ipv6Address ("2001:00aa:0000:0000:0200:00ff:fe00:0002"), "Ipv6AddressHelper failure");
151 }
152 
153 void
155 {
157  Simulator::Destroy ();
158 }
159 
160 
168 {
169 public:
171 };
172 
174  : TestSuite ("ipv6-address-helper", UNIT)
175 {
176  AddTestCase (new IpAddressHelperTestCasev6, TestCase::QUICK);
177 }
178 
Ipv6Address GetAddress() const
Get the IPv6 address.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
virtual void DoRun(void)
Implementation to actually run this TestCase.
Keep track of a set of IPv6 interfaces.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:81
A suite of tests to run.
Definition: test.h:1342
IPv6 address associated with an interface.
aggregate IP/TCP/UDP functionality to existing Nodes.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
encapsulates test code
Definition: test.h:1155
IPv6 AddressHelper TestSuite.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
static Ipv6AddressHelperTestSuite ipv6AddressHelperTestSuite
Static variable for test initialization.
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install.
#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:168
holds a vector of ns3::NetDevice pointers
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
void Reset(void)
Reset the initial value of every attribute as well as the value of every global to what they were bef...
Definition: config.cc:757
Helper class to auto-assign global IPv6 unicast addresses.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Describes an IPv6 address.
Definition: ipv6-address.h:49
virtual void SetAddress(Address address)
Set the address of this interface.
Ipv6Address NewAddress(Address addr)
Allocate a new Ipv6Address.
Describes an IPv6 prefix.
Definition: ipv6-address.h:428
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
void NewNetwork(void)
Allocate a new network.