A Discrete-Event Network Simulator
API
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
42struct MeshHeaderTest : public TestCase
43{
45 : TestCase("Dot11sMeshHeader roundtrip serialization")
46 {
47 }
48
49 void DoRun() override;
50};
51
52void
54{
55 {
56 MeshHeader a;
57 a.SetAddressExt(3);
58 a.SetAddr4(Mac48Address("11:22:33:44:55:66"));
59 a.SetAddr5(Mac48Address("11:00:33:00:55:00"));
60 a.SetAddr6(Mac48Address("00:22:00:44:00:66"));
61 a.SetMeshTtl(122);
62 a.SetMeshSeqno(321);
63 Ptr<Packet> packet = Create<Packet>();
64 packet->AddHeader(a);
65 MeshHeader b;
66 packet->RemoveHeader(b);
67 NS_TEST_ASSERT_MSG_EQ(a, b, "Mesh header roundtrip serialization works, 3 addresses");
68 }
69 {
70 MeshHeader a;
71 a.SetAddressExt(2);
72 a.SetAddr5(Mac48Address("11:00:33:00:55:00"));
73 a.SetAddr6(Mac48Address("00:22:00:44:00: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, 2 addresses");
81 }
82 {
83 MeshHeader a;
84 a.SetAddressExt(1);
85 a.SetAddr4(Mac48Address("11:22:33:44:55:66"));
86 a.SetMeshTtl(122);
87 a.SetMeshSeqno(321);
88 Ptr<Packet> packet = Create<Packet>();
89 packet->AddHeader(a);
90 MeshHeader b;
91 packet->RemoveHeader(b);
92 NS_TEST_ASSERT_MSG_EQ(a, b, "Mesh header roundtrip serialization works, 1 address");
93 }
94}
95
103{
104 public:
106 void DoRun() override;
107
108 private:
110 void TestLookup();
111
113 void TestAddPath();
115 void TestExpire();
116
118 void TestPrecursorAdd();
120 void TestPrecursorFind();
121
122 private:
130 std::vector<Mac48Address> precursors;
131};
132
134 : TestCase("HWMP routing table"),
135 dst("01:00:00:01:00:01"),
136 hop("01:00:00:01:00:03"),
137 iface(8010),
138 metric(10),
139 seqnum(1),
140 expire(Seconds(10))
141{
142 precursors.emplace_back("00:10:20:30:40:50");
143 precursors.emplace_back("00:11:22:33:44:55");
144 precursors.emplace_back("00:01:02:03:04:05");
145}
146
147void
149{
151
152 // Reactive path
154 NS_TEST_EXPECT_MSG_EQ((table->LookupReactive(dst) == correct), true, "Reactive lookup works");
156 NS_TEST_EXPECT_MSG_EQ(table->LookupReactive(dst).IsValid(), false, "Reactive lookup works");
157
158 // Proactive
160 NS_TEST_EXPECT_MSG_EQ((table->LookupProactive() == correct), true, "Proactive lookup works");
162 NS_TEST_EXPECT_MSG_EQ(table->LookupProactive().IsValid(), false, "Proactive lookup works");
163}
164
165void
167{
170}
171
172void
174{
175 // this is assumed to be called when path records are already expired
178 true,
179 "Reactive expiration works");
181 true,
182 "Proactive expiration works");
183
184 NS_TEST_EXPECT_MSG_EQ(table->LookupReactive(dst).IsValid(), false, "Reactive expiration works");
185 NS_TEST_EXPECT_MSG_EQ(table->LookupProactive().IsValid(), false, "Proactive expiration works");
186}
187
188void
190{
191 for (std::vector<Mac48Address>::const_iterator i = precursors.begin(); i != precursors.end();
192 i++)
193 {
194 table->AddPrecursor(dst, iface, *i, Seconds(100));
195 // Check that duplicates are filtered
196 table->AddPrecursor(dst, iface, *i, Seconds(100));
197 }
198}
199
200void
202{
204 NS_TEST_EXPECT_MSG_EQ(precursors.size(), precursorList.size(), "Precursors size works");
205 for (unsigned i = 0; i < precursors.size(); i++)
206 {
207 NS_TEST_EXPECT_MSG_EQ(precursorList[i].first, iface, "Precursors lookup works");
208 NS_TEST_EXPECT_MSG_EQ(precursorList[i].second, precursors[i], "Precursors lookup works");
209 }
210}
211
212void
214{
215 table = CreateObject<HwmpRtable>();
216
217 Simulator::Schedule(Seconds(0), &HwmpRtableTest::TestLookup, this);
218 Simulator::Schedule(Seconds(1), &HwmpRtableTest::TestAddPath, this);
219 Simulator::Schedule(Seconds(2), &HwmpRtableTest::TestPrecursorAdd, this);
220 Simulator::Schedule(expire + Seconds(2), &HwmpRtableTest::TestExpire, this);
221 Simulator::Schedule(expire + Seconds(3), &HwmpRtableTest::TestPrecursorFind, this);
222
223 Simulator::Run();
224 Simulator::Destroy();
225}
226
227//-----------------------------------------------------------------------------
230{
232 : TestCase("PeerLinkFrames (open, confirm, close) unit tests")
233 {
234 }
235
236 void DoRun() override;
237};
238
239void
241{
242 {
245 fields.capability = 0;
246 fields.meshId = IeMeshId("qwertyuiop");
247 a.SetPlinkOpenStart(fields);
248 Ptr<Packet> packet = Create<Packet>();
249 packet->AddHeader(a);
251 packet->RemoveHeader(b);
252 NS_TEST_EXPECT_MSG_EQ(a, b, "PEER_LINK_OPEN works");
253 }
254 {
257 fields.capability = 0;
258 fields.aid = 1234;
259 a.SetPlinkConfirmStart(fields);
260 Ptr<Packet> packet = Create<Packet>();
261 packet->AddHeader(a);
263 packet->RemoveHeader(b);
264 NS_TEST_EXPECT_MSG_EQ(a, b, "PEER_LINK_CONFIRM works");
265 }
266 {
269 fields.meshId = IeMeshId("qqq");
270 a.SetPlinkCloseStart(fields);
271 Ptr<Packet> packet = Create<Packet>();
272 packet->AddHeader(a);
274 packet->RemoveHeader(b);
275 NS_TEST_EXPECT_MSG_EQ(a, b, "PEER_LINK_CLOSE works");
276 }
277}
278
286{
287 public:
289};
290
292 : TestSuite("devices-mesh-dot11s", UNIT)
293{
294 AddTestCase(new MeshHeaderTest, TestCase::QUICK);
295 AddTestCase(new HwmpRtableTest, TestCase::QUICK);
296 AddTestCase(new PeerLinkFrameStartTest, TestCase::QUICK);
297}
298
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
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:294
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:268
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
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:257
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:81
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:38
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:144
#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:251
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
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:48