A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
sixlowpan-nd-rovr-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Boh Jie Qi <jieqiboh5836@gmail.com>
7 */
8
9#include "ns3/core-module.h"
10#include "ns3/internet-module.h"
11#include "ns3/internet-stack-helper.h"
12#include "ns3/simple-net-device-helper.h"
13#include "ns3/simple-net-device.h"
14#include "ns3/sixlowpan-module.h"
15#include "ns3/sixlowpan-nd-protocol.h"
16#include "ns3/test.h"
17
18#include <fstream>
19#include <limits>
20#include <regex>
21#include <string>
22
23namespace ns3
24{
25/**
26 * @ingroup sixlowpan-nd-rovr-tests
27 *
28 * @brief Test successful registration of varying numbers of 6LNs with 1 6LBR
29 */
31{
32 public:
34 : TestCase("2 6LNs with different ROVR attempt to register the same address")
35 {
36 }
37
38 void DoRun() override
39 {
40 // Create nodes
42 nodes.Create(2);
43 Ptr<Node> lbrNode = nodes.Get(0);
44 Ptr<Node> lnNode = nodes.Get(1);
45
46 // Install SimpleNetDevice instead of LrWpan
47 SimpleNetDeviceHelper simpleNetDeviceHelper;
48 NetDeviceContainer simpleNetDevices = simpleNetDeviceHelper.Install(nodes);
49
50 // Install IPv6 stack
51 InternetStackHelper internetv6;
52 internetv6.Install(nodes);
53
54 // Install 6LoWPAN
55 SixLowPanHelper sixlowpan;
56 NetDeviceContainer devices = sixlowpan.Install(simpleNetDevices);
57
58 // Install 6LoWPAN-ND
59 sixlowpan.InstallSixLowPanNdBorderRouter(devices.Get(0), "2001::");
60 sixlowpan.SetAdvertisedPrefix(devices.Get(0), Ipv6Prefix("2001::", 64));
61
62 sixlowpan.InstallSixLowPanNdNode(devices.Get(1)); // 6LN
63
64 Ptr<SixLowPanNdProtocol> lnNdProtocol = lnNode->GetObject<SixLowPanNdProtocol>();
65 lnNdProtocol->TraceConnectWithoutContext(
66 "NaRx",
68
69 // Derive link-local addresses from MAC addresses rather than hardcoding them.
70 Address lnMac = simpleNetDevices.Get(1)->GetAddress();
71 Address lbrMac = simpleNetDevices.Get(0)->GetAddress();
74
75 // Use a zeroed ROVR — deliberately different from the node's actual ROVR (derived from its
76 // EUI-64) to trigger a duplicate-address conflict on the 6LBR.
77 std::vector<uint8_t> conflictingRovr(16, 0);
78
79 // Registration lifetime of 5 minutes (300s), matching the minimum ARO value.
80 constexpr uint16_t regLifetimeMinutes = 5;
81
84 lnNode->GetObject<SixLowPanNdProtocol>(),
85 lnLLaddr, // address to register
86 lbrLLaddr, // destination (6LBR link-local)
87 lbrMac, // destination MAC
88 regLifetimeMinutes,
89 conflictingRovr,
90 devices.Get(1));
91
95
97 true,
98 "Should have received at least one NA packet");
99
100 Ptr<Packet> lastNa = m_naPacketsReceived.back();
101
102 Icmpv6NA naHdr;
105 bool hasEaro = false;
106
107 bool isValid =
108 SixLowPanNdProtocol::ParseAndValidateNaEaroPacket(lastNa, naHdr, tlla, earo, hasEaro);
109 NS_TEST_ASSERT_MSG_EQ(isValid, true, "Packet should be valid NA with EARO");
110
112 static_cast<uint8_t>(SixLowPanNdProtocol::DUPLICATE_ADDRESS),
113 "NA EARO status should be DUPLICATE_ADDRESS");
114 }
115
116 private:
117 std::vector<Ptr<Packet>> m_naPacketsReceived; //!< Container for NA packets received during test
118
119 /**
120 * @brief Callback sink for NA packet reception trace events
121 * @param pkt Received NA packet
122 */
124 {
125 m_naPacketsReceived.push_back(pkt);
126 }
127};
128
129/**
130 * @ingroup sixlowpan-nd-rovr-tests
131 *
132 * @brief 6LoWPAN-ND TestSuite
133 */
135{
136 public:
138 : TestSuite("sixlowpan-nd-rovr-test", Type::UNIT)
139 {
141 }
142};
143
144static SixLowPanNdRovrTestSuite
145 g_sixlowpanndrovrTestSuite; //!< Static variable for test initialization
146} // namespace ns3
a polymophic address class
Definition address.h:114
ICMPv6 Neighbor Advertisement header.
ICMPv6 Extended Address Registration Option header RFC 8505.
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...
Describes an IPv6 address.
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Address mac)
Make the autoconfigured link-local IPv6 address from a Mac address.
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.
Definition ptr.h:70
build a set of SimpleNetDevice objects
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static void Run()
Run the simulation.
Definition simulator.cc:161
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
Setup a sixlowpan stack to be used as a shim between IPv6 and a generic NetDevice.
Ipv6InterfaceContainer InstallSixLowPanNdNode(NetDeviceContainer c)
Install the SixLoWPAN-ND stack, associate it with a NetDevice, and set it as a 6LN.
NetDeviceContainer Install(NetDeviceContainer c)
Install the SixLoWPAN stack on top of an existing NetDevice.
void SetAdvertisedPrefix(const Ptr< NetDevice > nd, Ipv6Prefix prefix)
Add a new prefix to be advertised by 6LoWPAN-ND.
Ipv6InterfaceContainer InstallSixLowPanNdBorderRouter(NetDeviceContainer c, Ipv6Address baseAddr)
Install the SixLoWPAN-ND stack, associate it with a NetDevice, and set it as a 6LBR.
An optimization of the ND protocol for 6LoWPANs.
void SendSixLowPanNsWithEaro(Ipv6Address addrToRegister, Ipv6Address dst, Address dstMac, uint16_t time, const std::vector< uint8_t > &rovr, Ptr< NetDevice > sixDevice)
Send a NS for 6LoWPAN ND (+ EARO, SLLAO).
static bool ParseAndValidateNaEaroPacket(Ptr< Packet > p, Icmpv6NA &naHdr, Icmpv6OptionLinkLayerAddress &tlla, Icmpv6OptionSixLowPanExtendedAddressRegistration &earo, bool &hasEaro)
Parses NA packet and populates params, returning true if packet is valid.
@ DUPLICATE_ADDRESS
Duplicate Address.
Test successful registration of varying numbers of 6LNs with 1 6LBR.
std::vector< Ptr< Packet > > m_naPacketsReceived
Container for NA packets received during test.
void DoRun() override
Implementation to actually run this TestCase.
void NaRxSink(Ptr< Packet > pkt)
Callback sink for NA packet reception trace events.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1273
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:690
#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:133
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static SixLowPanNdRovrTestSuite g_sixlowpanndrovrTestSuite
Static variable for test initialization.