A Discrete-Event Network Simulator
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
32using namespace ns3;
33
34/**
35 * @ingroup internet-test
36 *
37 * @brief IPv6 Duplicate Address Detection Test
38 */
39class Ipv6DadTest : public TestCase
40{
41 public:
42 void DoRun() override;
44};
45
47 : TestCase("IPv6 Duplicate Address Detection")
48{
49}
50
51void
53{
54 // Create topology
55
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
91
92 Ipv6InterfaceAddress addr1 = ipv6node1->GetAddress(ifIndexNode1, 1);
93 Ipv6InterfaceAddress::State_e node1AddrState = addr1.GetState();
94 NS_TEST_ASSERT_MSG_EQ(node1AddrState,
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,
102 "Failed to detect duplicate address on node 2");
103
105}
106
107/**
108 * @ingroup internet-test
109 *
110 * @brief IPv6 Duplicate Address Detection TestSuite
111 */
113{
114 public:
116 : TestSuite("ipv6-duplicate-address-detection", Type::UNIT)
117 {
118 AddTestCase(new Ipv6DadTest, TestCase::Duration::QUICK);
119 }
120};
121
122static Ipv6DadTestSuite g_ipv6dadTestSuite; //!< Static variable for test initialization
IPv6 Duplicate Address Detection Test.
void DoRun() override
Implementation to actually run this TestCase.
IPv6 Duplicate Address Detection TestSuite.
aggregate IP/TCP/UDP functionality to existing Nodes.
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.
Ipv6InterfaceContainer AssignWithoutAddress(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer but do not assign any IPv6 addresses.
Describes an IPv6 address.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
IPv6 address associated with an interface.
Ipv6InterfaceAddress::State_e GetState() const
Get the address state.
State_e
State of an address associated with an interface.
@ INVALID
Invalid state (after a DAD failed)
Keep track of a set of IPv6 interfaces.
Describes an IPv6 prefix.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
Smart pointer class similar to boost::intrusive_ptr.
build a set of SimpleNetDevice objects
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
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
static constexpr auto UNIT
Definition test.h:1291
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 Ipv6DadTestSuite g_ipv6dadTestSuite
Static variable for test initialization.
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.