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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Pavel Boyko <boyko@iitp.ru>
18 */
19#include "ns3/dot11s-mac-header.h"
20#include "ns3/hwmp-rtable.h"
21#include "ns3/ie-dot11s-peer-management.h"
22#include "ns3/mgt-headers.h"
23#include "ns3/packet.h"
24#include "ns3/peer-link-frame.h"
25#include "ns3/simulator.h"
26#include "ns3/test.h"
27
28using namespace ns3;
29using namespace dot11s;
30
41struct MeshHeaderTest : public TestCase
42{
44 : TestCase("Dot11sMeshHeader roundtrip serialization")
45 {
46 }
47
48 void DoRun() override;
49};
50
51void
53{
54 {
55 MeshHeader a;
56 a.SetAddressExt(3);
57 a.SetAddr4(Mac48Address("11:22:33:44:55:66"));
58 a.SetAddr5(Mac48Address("11:00:33:00:55:00"));
59 a.SetAddr6(Mac48Address("00:22:00:44:00:66"));
60 a.SetMeshTtl(122);
61 a.SetMeshSeqno(321);
62 Ptr<Packet> packet = Create<Packet>();
63 packet->AddHeader(a);
64 MeshHeader b;
65 packet->RemoveHeader(b);
66 NS_TEST_ASSERT_MSG_EQ(a, b, "Mesh header roundtrip serialization works, 3 addresses");
67 }
68 {
69 MeshHeader a;
70 a.SetAddressExt(2);
71 a.SetAddr5(Mac48Address("11:00:33:00:55:00"));
72 a.SetAddr6(Mac48Address("00:22:00:44:00:66"));
73 a.SetMeshTtl(122);
74 a.SetMeshSeqno(321);
75 Ptr<Packet> packet = Create<Packet>();
76 packet->AddHeader(a);
77 MeshHeader b;
78 packet->RemoveHeader(b);
79 NS_TEST_ASSERT_MSG_EQ(a, b, "Mesh header roundtrip serialization works, 2 addresses");
80 }
81 {
82 MeshHeader a;
83 a.SetAddressExt(1);
84 a.SetAddr4(Mac48Address("11:22:33:44:55:66"));
85 a.SetMeshTtl(122);
86 a.SetMeshSeqno(321);
87 Ptr<Packet> packet = Create<Packet>();
88 packet->AddHeader(a);
89 MeshHeader b;
90 packet->RemoveHeader(b);
91 NS_TEST_ASSERT_MSG_EQ(a, b, "Mesh header roundtrip serialization works, 1 address");
92 }
93}
94
101{
102 public:
104 void DoRun() override;
105
106 private:
108 void TestLookup();
109
111 void TestAddPath();
113 void TestExpire();
114
116 void TestPrecursorAdd();
118 void TestPrecursorFind();
119
120 private:
128 std::vector<Mac48Address> precursors;
129};
130
132 : TestCase("HWMP routing table"),
133 dst("01:00:00:01:00:01"),
134 hop("01:00:00:01:00:03"),
135 iface(8010),
136 metric(10),
137 seqnum(1),
138 expire(Seconds(10))
139{
140 precursors.emplace_back("00:10:20:30:40:50");
141 precursors.emplace_back("00:11:22:33:44:55");
142 precursors.emplace_back("00:01:02:03:04:05");
143}
144
145void
147{
149
150 // Reactive path
152 NS_TEST_EXPECT_MSG_EQ((table->LookupReactive(dst) == correct), true, "Reactive lookup works");
154 NS_TEST_EXPECT_MSG_EQ(table->LookupReactive(dst).IsValid(), false, "Reactive lookup works");
155
156 // Proactive
158 NS_TEST_EXPECT_MSG_EQ((table->LookupProactive() == correct), true, "Proactive lookup works");
160 NS_TEST_EXPECT_MSG_EQ(table->LookupProactive().IsValid(), false, "Proactive lookup works");
161}
162
163void
165{
168}
169
170void
172{
173 // this is assumed to be called when path records are already expired
176 true,
177 "Reactive expiration works");
179 true,
180 "Proactive expiration works");
181
182 NS_TEST_EXPECT_MSG_EQ(table->LookupReactive(dst).IsValid(), false, "Reactive expiration works");
183 NS_TEST_EXPECT_MSG_EQ(table->LookupProactive().IsValid(), false, "Proactive expiration works");
184}
185
186void
188{
189 for (auto i = precursors.begin(); i != precursors.end(); i++)
190 {
191 table->AddPrecursor(dst, iface, *i, Seconds(100));
192 // Check that duplicates are filtered
193 table->AddPrecursor(dst, iface, *i, Seconds(100));
194 }
195}
196
197void
199{
201 NS_TEST_EXPECT_MSG_EQ(precursors.size(), precursorList.size(), "Precursors size works");
202 for (unsigned i = 0; i < precursors.size(); i++)
203 {
204 NS_TEST_EXPECT_MSG_EQ(precursorList[i].first, iface, "Precursors lookup works");
205 NS_TEST_EXPECT_MSG_EQ(precursorList[i].second, precursors[i], "Precursors lookup works");
206 }
207}
208
209void
211{
212 table = CreateObject<HwmpRtable>();
213
219
222}
223
224//-----------------------------------------------------------------------------
227{
229 : TestCase("PeerLinkFrames (open, confirm, close) unit tests")
230 {
231 }
232
233 void DoRun() override;
234};
235
236void
238{
239 {
242 fields.capability = 0;
243 fields.meshId = IeMeshId("qwertyuiop");
244 a.SetPlinkOpenStart(fields);
245 Ptr<Packet> packet = Create<Packet>();
246 packet->AddHeader(a);
248 packet->RemoveHeader(b);
249 NS_TEST_EXPECT_MSG_EQ(a, b, "PEER_LINK_OPEN works");
250 }
251 {
254 fields.capability = 0;
255 fields.aid = 1234;
256 a.SetPlinkConfirmStart(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_CONFIRM works");
262 }
263 {
266 fields.meshId = IeMeshId("qqq");
267 a.SetPlinkCloseStart(fields);
268 Ptr<Packet> packet = Create<Packet>();
269 packet->AddHeader(a);
271 packet->RemoveHeader(b);
272 NS_TEST_EXPECT_MSG_EQ(a, b, "PEER_LINK_CLOSE works");
273 }
274}
275
282{
283 public:
285};
286
288 : TestSuite("devices-mesh-dot11s", Type::UNIT)
289{
290 AddTestCase(new MeshHeaderTest, TestCase::Duration::QUICK);
291 AddTestCase(new HwmpRtableTest, TestCase::Duration::QUICK);
292 AddTestCase(new PeerLinkFrameStartTest, TestCase::Duration::QUICK);
293}
294
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
Definition: mac48-address.h:46
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
void DeleteReactivePath(Mac48Address destination)
Delete the reactive paths toward a destination.
Definition: hwmp-rtable.cc:161
LookupResult LookupReactive(Mac48Address destination)
Lookup path to destination.
Definition: hwmp-rtable.cc:172
LookupResult LookupReactiveExpired(Mac48Address destination)
Return all reactive paths, including expired.
Definition: hwmp-rtable.cc:189
PrecursorList GetPrecursors(Mac48Address destination)
Get the precursors list.
Definition: hwmp-rtable.cc:256
void DeleteProactivePath()
Delete all the proactive paths.
Definition: hwmp-rtable.cc:139
LookupResult LookupProactiveExpired()
Return all proactive paths, including expired.
Definition: hwmp-rtable.cc:218
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Definition: hwmp-rtable.h:82
LookupResult LookupProactive()
Find proactive path to tree root.
Definition: hwmp-rtable.cc:206
void AddPrecursor(Mac48Address destination, uint32_t precursorInterface, Mac48Address precursorAddress, Time lifetime)
Add a precursor.
Definition: hwmp-rtable.cc:106
void AddProactivePath(uint32_t metric, Mac48Address root, Mac48Address retransmitter, uint32_t interface, Time lifetime, uint32_t seqnum)
Add a proactive path.
Definition: hwmp-rtable.cc:89
void AddReactivePath(Mac48Address destination, Mac48Address retransmitter, uint32_t interface, uint32_t metric, Time lifetime, uint32_t seqnum)
Add a reactive path.
Definition: hwmp-rtable.cc:64
a IEEE 802.11 Mesh ID element (Section 8.4.2.101 of IEEE 802.11-2012)
Definition: ie-dot11s-id.h:37
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
#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:145
#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:252
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Definition: first.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Definition: second.py:1
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:49