A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dot11s-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Pavel Boyko <boyko@iitp.ru>
7 */
8#include "ns3/dot11s-mac-header.h"
9#include "ns3/hwmp-rtable.h"
10#include "ns3/ie-dot11s-peer-management.h"
11#include "ns3/mgt-headers.h"
12#include "ns3/packet.h"
13#include "ns3/peer-link-frame.h"
14#include "ns3/simulator.h"
15#include "ns3/test.h"
16
17using namespace ns3;
18using namespace dot11s;
19
20/**
21 * \ingroup mesh-test
22 * \defgroup dot11s-test dot11s sub-module tests
23 */
24
25/**
26 * \ingroup dot11s-test
27 *
28 * \brief Built-in self test for MeshHeader
29 */
30struct MeshHeaderTest : public TestCase
31{
33 : TestCase("Dot11sMeshHeader roundtrip serialization")
34 {
35 }
36
37 void DoRun() override;
38};
39
40void
42{
43 {
44 MeshHeader a;
45 a.SetAddressExt(3);
46 a.SetAddr4(Mac48Address("11:22:33:44:55:66"));
47 a.SetAddr5(Mac48Address("11:00:33:00:55:00"));
48 a.SetAddr6(Mac48Address("00:22:00:44:00:66"));
49 a.SetMeshTtl(122);
50 a.SetMeshSeqno(321);
51 Ptr<Packet> packet = Create<Packet>();
52 packet->AddHeader(a);
53 MeshHeader b;
54 packet->RemoveHeader(b);
55 NS_TEST_ASSERT_MSG_EQ(a, b, "Mesh header roundtrip serialization works, 3 addresses");
56 }
57 {
58 MeshHeader a;
59 a.SetAddressExt(2);
60 a.SetAddr5(Mac48Address("11:00:33:00:55:00"));
61 a.SetAddr6(Mac48Address("00:22:00:44:00:66"));
62 a.SetMeshTtl(122);
63 a.SetMeshSeqno(321);
64 Ptr<Packet> packet = Create<Packet>();
65 packet->AddHeader(a);
66 MeshHeader b;
67 packet->RemoveHeader(b);
68 NS_TEST_ASSERT_MSG_EQ(a, b, "Mesh header roundtrip serialization works, 2 addresses");
69 }
70 {
71 MeshHeader a;
72 a.SetAddressExt(1);
73 a.SetAddr4(Mac48Address("11:22:33:44:55:66"));
74 a.SetMeshTtl(122);
75 a.SetMeshSeqno(321);
76 Ptr<Packet> packet = Create<Packet>();
77 packet->AddHeader(a);
78 MeshHeader b;
79 packet->RemoveHeader(b);
80 NS_TEST_ASSERT_MSG_EQ(a, b, "Mesh header roundtrip serialization works, 1 address");
81 }
82}
83
84/**
85 * \ingroup mesh-test
86 *
87 * \brief Unit test for HwmpRtable
88 */
90{
91 public:
93 void DoRun() override;
94
95 private:
96 /// Test Add apth and lookup path;
97 void TestLookup();
98
99 /// Test add path and try to lookup after entry has expired
100 void TestAddPath();
101 /// Test add path and try to lookup after entry has expired
102 void TestExpire();
103
104 /// Test add precursors and find precursor list in rtable
105 void TestPrecursorAdd();
106 /// Test add precursors and find precursor list in rtable
107 void TestPrecursorFind();
108
109 private:
110 Mac48Address dst; ///< destination address
111 Mac48Address hop; ///< hop address
112 uint32_t iface; ///< interface
113 uint32_t metric; ///< metric
114 uint32_t seqnum; ///< sequence number
115 Time expire; ///< expiration time
117 std::vector<Mac48Address> precursors; ///< precursors
118};
119
121 : TestCase("HWMP routing table"),
122 dst("01:00:00:01:00:01"),
123 hop("01:00:00:01:00:03"),
124 iface(8010),
125 metric(10),
126 seqnum(1),
127 expire(Seconds(10))
128{
129 precursors.emplace_back("00:10:20:30:40:50");
130 precursors.emplace_back("00:11:22:33:44:55");
131 precursors.emplace_back("00:01:02:03:04:05");
132}
133
134void
136{
138
139 // Reactive path
140 table->AddReactivePath(dst, hop, iface, metric, expire, seqnum);
141 NS_TEST_EXPECT_MSG_EQ((table->LookupReactive(dst) == correct), true, "Reactive lookup works");
142 table->DeleteReactivePath(dst);
143 NS_TEST_EXPECT_MSG_EQ(table->LookupReactive(dst).IsValid(), false, "Reactive lookup works");
144
145 // Proactive
146 table->AddProactivePath(metric, dst, hop, iface, expire, seqnum);
147 NS_TEST_EXPECT_MSG_EQ((table->LookupProactive() == correct), true, "Proactive lookup works");
148 table->DeleteProactivePath(dst);
149 NS_TEST_EXPECT_MSG_EQ(table->LookupProactive().IsValid(), false, "Proactive lookup works");
150}
151
152void
154{
155 table->AddReactivePath(dst, hop, iface, metric, expire, seqnum);
156 table->AddProactivePath(metric, dst, hop, iface, expire, seqnum);
157}
158
159void
161{
162 // this is assumed to be called when path records are already expired
164 NS_TEST_EXPECT_MSG_EQ((table->LookupReactiveExpired(dst) == correct),
165 true,
166 "Reactive expiration works");
167 NS_TEST_EXPECT_MSG_EQ((table->LookupProactiveExpired() == correct),
168 true,
169 "Proactive expiration works");
170
171 NS_TEST_EXPECT_MSG_EQ(table->LookupReactive(dst).IsValid(), false, "Reactive expiration works");
172 NS_TEST_EXPECT_MSG_EQ(table->LookupProactive().IsValid(), false, "Proactive expiration works");
173}
174
175void
177{
178 for (auto i = precursors.begin(); i != precursors.end(); i++)
179 {
180 table->AddPrecursor(dst, iface, *i, Seconds(100));
181 // Check that duplicates are filtered
182 table->AddPrecursor(dst, iface, *i, Seconds(100));
183 }
184}
185
186void
188{
189 HwmpRtable::PrecursorList precursorList = table->GetPrecursors(dst);
190 NS_TEST_EXPECT_MSG_EQ(precursors.size(), precursorList.size(), "Precursors size works");
191 for (unsigned i = 0; i < precursors.size(); i++)
192 {
193 NS_TEST_EXPECT_MSG_EQ(precursorList[i].first, iface, "Precursors lookup works");
194 NS_TEST_EXPECT_MSG_EQ(precursorList[i].second, precursors[i], "Precursors lookup works");
195 }
196}
197
198void
212
213//-----------------------------------------------------------------------------
214/// Built-in self test for PeerLinkFrameStart
216{
218 : TestCase("PeerLinkFrames (open, confirm, close) unit tests")
219 {
220 }
221
222 void DoRun() override;
223};
224
225void
227{
228 {
231 fields.capability = 0;
232 fields.meshId = IeMeshId("qwertyuiop");
233 a.SetPlinkOpenStart(fields);
234 Ptr<Packet> packet = Create<Packet>();
235 packet->AddHeader(a);
237 packet->RemoveHeader(b);
238 NS_TEST_EXPECT_MSG_EQ(a, b, "PEER_LINK_OPEN works");
239 }
240 {
243 fields.capability = 0;
244 fields.aid = 1234;
245 a.SetPlinkConfirmStart(fields);
246 Ptr<Packet> packet = Create<Packet>();
247 packet->AddHeader(a);
249 packet->RemoveHeader(b);
250 NS_TEST_EXPECT_MSG_EQ(a, b, "PEER_LINK_CONFIRM works");
251 }
252 {
255 fields.meshId = IeMeshId("qqq");
256 a.SetPlinkCloseStart(fields);
257 Ptr<Packet> packet = Create<Packet>();
258 packet->AddHeader(a);
260 packet->RemoveHeader(b);
261 NS_TEST_EXPECT_MSG_EQ(a, b, "PEER_LINK_CLOSE works");
262 }
263}
264
265/**
266 * \ingroup mesh-test
267 *
268 * \brief Dot11s Test Suite
269 */
271{
272 public:
274};
275
277 : TestSuite("devices-mesh-dot11s", Type::UNIT)
278{
279 AddTestCase(new MeshHeaderTest, TestCase::Duration::QUICK);
280 AddTestCase(new HwmpRtableTest, TestCase::Duration::QUICK);
281 AddTestCase(new PeerLinkFrameStartTest, TestCase::Duration::QUICK);
282}
283
284static Dot11sTestSuite g_dot11sTestSuite; ///< the test suite
Dot11s Test Suite.
Unit test for HwmpRtable.
Mac48Address dst
destination address
Ptr< HwmpRtable > table
tab;e
uint32_t iface
interface
void TestLookup()
Test Add apth and lookup path;.
void TestAddPath()
Test add path and try to lookup after entry has expired.
std::vector< Mac48Address > precursors
precursors
uint32_t seqnum
sequence number
void DoRun() override
Implementation to actually run this TestCase.
void TestPrecursorFind()
Test add precursors and find precursor list in rtable.
void TestPrecursorAdd()
Test add precursors and find precursor list in rtable.
uint32_t metric
metric
Time expire
expiration time
Mac48Address hop
hop address
void TestExpire()
Test add path and try to lookup after entry has expired.
an EUI-48 address
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
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
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Definition hwmp-rtable.h:71
a IEEE 802.11 Mesh ID element (Section 8.4.2.101 of IEEE 802.11-2012)
Mesh Control field, see Section 8.2.4.7.3 IEEE 802.11-2012.
void SetAddr6(Mac48Address address)
Set extended address 6.
void SetMeshSeqno(uint32_t seqno)
Set four-byte mesh sequence number.
void SetMeshTtl(uint8_t TTL)
Set mesh TTL subfield corresponding to the remaining number of hops the MSDU/MMPDU is forwarded.
void SetAddressExt(uint8_t num_of_addresses)
Set Address Extension Mode.
void SetAddr5(Mac48Address address)
Set extended address 5.
void SetAddr4(Mac48Address address)
Set extended address 4.
static Dot11sTestSuite g_dot11sTestSuite
the test suite
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#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
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition test.h:241
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Definition first.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Built-in self test for MeshHeader.
void DoRun() override
Implementation to actually run this TestCase.
Route lookup result, return type of LookupXXX methods.
Definition hwmp-rtable.h:38