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
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 (std::vector<Mac48Address>::const_iterator i = precursors.begin(); i != precursors.end();
190 i++)
191 {
192 table->AddPrecursor(dst, iface, *i, Seconds(100));
193 // Check that duplicates are filtered
194 table->AddPrecursor(dst, iface, *i, Seconds(100));
195 }
196}
197
198void
200{
202 NS_TEST_EXPECT_MSG_EQ(precursors.size(), precursorList.size(), "Precursors size works");
203 for (unsigned i = 0; i < precursors.size(); i++)
204 {
205 NS_TEST_EXPECT_MSG_EQ(precursorList[i].first, iface, "Precursors lookup works");
206 NS_TEST_EXPECT_MSG_EQ(precursorList[i].second, precursors[i], "Precursors lookup works");
207 }
208}
209
210void
212{
213 table = CreateObject<HwmpRtable>();
214
215 Simulator::Schedule(Seconds(0), &HwmpRtableTest::TestLookup, this);
216 Simulator::Schedule(Seconds(1), &HwmpRtableTest::TestAddPath, this);
217 Simulator::Schedule(Seconds(2), &HwmpRtableTest::TestPrecursorAdd, this);
218 Simulator::Schedule(expire + Seconds(2), &HwmpRtableTest::TestExpire, this);
219 Simulator::Schedule(expire + Seconds(3), &HwmpRtableTest::TestPrecursorFind, this);
220
221 Simulator::Run();
222 Simulator::Destroy();
223}
224
225//-----------------------------------------------------------------------------
228{
230 : TestCase("PeerLinkFrames (open, confirm, close) unit tests")
231 {
232 }
233
234 void DoRun() override;
235};
236
237void
239{
240 {
243 fields.capability = 0;
244 fields.meshId = IeMeshId("qwertyuiop");
245 a.SetPlinkOpenStart(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_OPEN works");
251 }
252 {
255 fields.capability = 0;
256 fields.aid = 1234;
257 a.SetPlinkConfirmStart(fields);
258 Ptr<Packet> packet = Create<Packet>();
259 packet->AddHeader(a);
261 packet->RemoveHeader(b);
262 NS_TEST_EXPECT_MSG_EQ(a, b, "PEER_LINK_CONFIRM works");
263 }
264 {
267 fields.meshId = IeMeshId("qqq");
268 a.SetPlinkCloseStart(fields);
269 Ptr<Packet> packet = Create<Packet>();
270 packet->AddHeader(a);
272 packet->RemoveHeader(b);
273 NS_TEST_EXPECT_MSG_EQ(a, b, "PEER_LINK_CLOSE works");
274 }
275}
276
283{
284 public:
286};
287
289 : TestSuite("devices-mesh-dot11s", UNIT)
290{
291 AddTestCase(new MeshHeaderTest, TestCase::QUICK);
292 AddTestCase(new HwmpRtableTest, TestCase::QUICK);
293 AddTestCase(new PeerLinkFrameStartTest, TestCase::QUICK);
294}
295
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:1336
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