A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
ipv6-address-duplication-test.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Universita' di Firenze
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7
*/
8
9
#include "ns3/boolean.h"
10
#include "ns3/icmpv6-l4-protocol.h"
11
#include "ns3/inet6-socket-address.h"
12
#include "ns3/internet-stack-helper.h"
13
#include "ns3/ipv6-address-helper.h"
14
#include "ns3/ipv6-l3-protocol.h"
15
#include "ns3/ipv6-routing-helper.h"
16
#include "ns3/ipv6-static-routing.h"
17
#include "ns3/log.h"
18
#include "ns3/node.h"
19
#include "ns3/simple-channel.h"
20
#include "ns3/simple-net-device-helper.h"
21
#include "ns3/simple-net-device.h"
22
#include "ns3/simulator.h"
23
#include "ns3/socket-factory.h"
24
#include "ns3/socket.h"
25
#include "ns3/test.h"
26
#include "ns3/udp-l4-protocol.h"
27
#include "ns3/udp-socket-factory.h"
28
29
#include <limits>
30
#include <string>
31
32
using namespace
ns3
;
33
34
/**
35
* @ingroup internet-test
36
*
37
* @brief IPv6 Duplicate Address Detection Test
38
*/
39
class
Ipv6DadTest
:
public
TestCase
40
{
41
public
:
42
void
DoRun
()
override
;
43
Ipv6DadTest
();
44
};
45
46
Ipv6DadTest::Ipv6DadTest
()
47
:
TestCase
(
"IPv6 Duplicate Address Detection"
)
48
{
49
}
50
51
void
52
Ipv6DadTest::DoRun
()
53
{
54
// Create topology
55
56
Ptr<Node>
Node1
=
CreateObject<Node>
();
57
Ptr<Node>
Node2
=
CreateObject<Node>
();
58
59
NodeContainer
nodes
(
Node1
,
Node2
);
60
61
SimpleNetDeviceHelper
helperChannel
;
62
helperChannel
.
SetNetDevicePointToPointMode
(
true
);
63
NetDeviceContainer
net
=
helperChannel
.Install(
nodes
);
64
65
InternetStackHelper
internetv6
;
66
internetv6
.
Install
(
nodes
);
67
68
Ipv6AddressHelper
ipv6helper
;
69
Ipv6InterfaceContainer
iic
=
ipv6helper
.AssignWithoutAddress(
net
);
70
71
Ptr<NetDevice>
device;
72
Ipv6InterfaceAddress
ipv6Addr
;
73
74
Ptr<Ipv6>
ipv6node1
;
75
int32_t
ifIndexNode1
;
76
ipv6node1
=
Node1
->GetObject<
Ipv6
>();
77
device =
net
.Get(0);
78
ifIndexNode1
=
ipv6node1
->GetInterfaceForDevice(device);
79
ipv6Addr
=
Ipv6InterfaceAddress
(
Ipv6Address
(
"2001:1::1"
),
Ipv6Prefix
(64));
80
ipv6node1
->AddAddress(
ifIndexNode1
,
ipv6Addr
);
81
82
Ptr<Ipv6>
ipv6node2
;
83
int32_t
ifIndexNode2
;
84
ipv6node2
=
Node2
->GetObject<
Ipv6
>();
85
device =
net
.Get(1);
86
ifIndexNode2
=
ipv6node2
->GetInterfaceForDevice(device);
87
ipv6Addr
=
Ipv6InterfaceAddress
(
Ipv6Address
(
"2001:1::1"
),
Ipv6Prefix
(64));
88
ipv6node2
->AddAddress(
ifIndexNode2
,
ipv6Addr
);
89
90
Simulator::Run
();
91
92
Ipv6InterfaceAddress
addr1
=
ipv6node1
->
GetAddress
(
ifIndexNode1
, 1);
93
Ipv6InterfaceAddress::State_e
node1AddrState
=
addr1
.GetState();
94
NS_TEST_ASSERT_MSG_EQ
(
node1AddrState
,
95
Ipv6InterfaceAddress::INVALID
,
96
"Failed to detect duplicate address on node 1"
);
97
98
Ipv6InterfaceAddress
addr2
=
ipv6node2
->
GetAddress
(
ifIndexNode2
, 1);
99
Ipv6InterfaceAddress::State_e
node2AddrState
=
addr2
.GetState();
100
NS_TEST_ASSERT_MSG_EQ
(
node2AddrState
,
101
Ipv6InterfaceAddress::INVALID
,
102
"Failed to detect duplicate address on node 2"
);
103
104
Simulator::Destroy
();
105
}
106
107
/**
108
* @ingroup internet-test
109
*
110
* @brief IPv6 Duplicate Address Detection TestSuite
111
*/
112
class
Ipv6DadTestSuite
:
public
TestSuite
113
{
114
public
:
115
Ipv6DadTestSuite
()
116
:
TestSuite
(
"ipv6-duplicate-address-detection"
,
Type
::
UNIT
)
117
{
118
AddTestCase
(
new
Ipv6DadTest
, TestCase::Duration::QUICK);
119
}
120
};
121
122
static
Ipv6DadTestSuite
g_ipv6dadTestSuite
;
//!< Static variable for test initialization
Ipv6DadTest
IPv6 Duplicate Address Detection Test.
Definition
ipv6-address-duplication-test.cc:40
Ipv6DadTest::Ipv6DadTest
Ipv6DadTest()
Definition
ipv6-address-duplication-test.cc:46
Ipv6DadTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
ipv6-address-duplication-test.cc:52
Ipv6DadTestSuite
IPv6 Duplicate Address Detection TestSuite.
Definition
ipv6-address-duplication-test.cc:113
Ipv6DadTestSuite::Ipv6DadTestSuite
Ipv6DadTestSuite()
Definition
ipv6-address-duplication-test.cc:115
int32_t
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition
internet-stack-helper.h:81
ns3::InternetStackHelper::Install
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Definition
internet-stack-helper.cc:359
ns3::Ipv6AddressHelper
Helper class to auto-assign global IPv6 unicast addresses.
Definition
ipv6-address-helper.h:73
ns3::Ipv6Address
Describes an IPv6 address.
Definition
ipv6-address.h:38
ns3::Ipv6
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition
ipv6.h:71
ns3::Ipv6InterfaceAddress
IPv6 address associated with an interface.
Definition
ipv6-interface-address.h:26
ns3::Ipv6InterfaceAddress::GetAddress
Ipv6Address GetAddress() const
Get the IPv6 address.
Definition
ipv6-interface-address.cc:78
ns3::Ipv6InterfaceAddress::State_e
State_e
State of an address associated with an interface.
Definition
ipv6-interface-address.h:33
ns3::Ipv6InterfaceAddress::INVALID
@ INVALID
Invalid state (after a DAD failed)
Definition
ipv6-interface-address.h:41
ns3::Ipv6InterfaceContainer
Keep track of a set of IPv6 interfaces.
Definition
ipv6-interface-container.h:29
ns3::Ipv6Prefix
Describes an IPv6 prefix.
Definition
ipv6-address.h:444
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition
net-device-container.h:32
ns3::NodeContainer
keep track of a set of node pointers.
Definition
node-container.h:29
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::SimpleNetDeviceHelper
build a set of SimpleNetDevice objects
Definition
simple-net-device-helper.h:28
ns3::SimpleNetDeviceHelper::SetNetDevicePointToPointMode
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
Definition
simple-net-device-helper.cc:54
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::TestSuite::UNIT
static constexpr auto UNIT
Definition
test.h:1291
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
NS_TEST_ASSERT_MSG_EQ
#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
g_ipv6dadTestSuite
static Ipv6DadTestSuite g_ipv6dadTestSuite
Static variable for test initialization.
Definition
ipv6-address-duplication-test.cc:122
nodes
NodeContainer nodes
Definition
lr-wpan-bootstrap.cc:43
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
internet
test
ipv6-address-duplication-test.cc
Generated on Mon Dec 15 2025 15:21:54 for ns-3 by
1.9.8