A Discrete-Event Network Simulator
API
dot11s-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Pavel Boyko <boyko@iitp.ru>
19  */
20 #include "ns3/test.h"
21 #include "ns3/packet.h"
22 #include "ns3/simulator.h"
23 #include "ns3/mgt-headers.h"
24 #include "ns3/dot11s-mac-header.h"
25 #include "ns3/hwmp-rtable.h"
26 #include "ns3/peer-link-frame.h"
27 #include "ns3/ie-dot11s-peer-management.h"
28 
29 using namespace ns3;
30 using namespace dot11s;
31 
44 struct MeshHeaderTest : public TestCase
45 {
47  TestCase ("Dot11sMeshHeader roundtrip serialization")
48  {
49  }
50  void DoRun ();
51 };
52 
53 void
55 {
56  {
57  MeshHeader a;
58  a.SetAddressExt (3);
59  a.SetAddr4 (Mac48Address ("11:22:33:44:55:66"));
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, 3 addresses");
69  }
70  {
71  MeshHeader a;
72  a.SetAddressExt (2);
73  a.SetAddr5 (Mac48Address ("11:00:33:00:55:00"));
74  a.SetAddr6 (Mac48Address ("00:22:00:44:00:66"));
75  a.SetMeshTtl (122);
76  a.SetMeshSeqno (321);
77  Ptr<Packet> packet = Create<Packet> ();
78  packet->AddHeader (a);
79  MeshHeader b;
80  packet->RemoveHeader (b);
81  NS_TEST_ASSERT_MSG_EQ (a, b, "Mesh header roundtrip serialization works, 2 addresses");
82  }
83  {
84  MeshHeader a;
85  a.SetAddressExt (1);
86  a.SetAddr4 (Mac48Address ("11:22:33:44:55:66"));
87  a.SetMeshTtl (122);
88  a.SetMeshSeqno (321);
89  Ptr<Packet> packet = Create<Packet> ();
90  packet->AddHeader (a);
91  MeshHeader b;
92  packet->RemoveHeader (b);
93  NS_TEST_ASSERT_MSG_EQ (a, b, "Mesh header roundtrip serialization works, 1 address");
94  }
95 }
96 
103 class HwmpRtableTest : public TestCase
104 {
105 public:
106  HwmpRtableTest ();
107  virtual void DoRun ();
108 
109 private:
111  void TestLookup ();
112 
114  void TestAddPath ();
116  void TestExpire ();
117 
119  void TestPrecursorAdd ();
121  void TestPrecursorFind ();
122 
123 private:
126  uint32_t iface;
127  uint32_t metric;
128  uint32_t seqnum;
131  std::vector<Mac48Address> precursors;
132 };
133 
135  TestCase ("HWMP routing table"),
136  dst ("01:00:00:01:00:01"),
137  hop ("01:00:00:01:00:03"),
138  iface (8010),
139  metric (10),
140  seqnum (1),
141  expire (Seconds (10))
142 {
143  precursors.push_back (Mac48Address ("00:10:20:30:40:50"));
144  precursors.push_back (Mac48Address ("00:11:22:33:44:55"));
145  precursors.push_back (Mac48Address ("00:01:02:03:04:05"));
146 }
147 
148 void
150 {
152 
153  // Reactive path
155  NS_TEST_EXPECT_MSG_EQ ((table->LookupReactive (dst) == correct), true, "Reactive lookup works");
157  NS_TEST_EXPECT_MSG_EQ (table->LookupReactive (dst).IsValid (), false, "Reactive lookup works");
158 
159  // Proactive
161  NS_TEST_EXPECT_MSG_EQ ((table->LookupProactive () == correct), true, "Proactive lookup works");
163  NS_TEST_EXPECT_MSG_EQ (table->LookupProactive ().IsValid (), false, "Proactive lookup works");
164 }
165 
166 void
168 {
171 }
172 
173 void
175 {
176  // this is assumed to be called when path records are already expired
178  NS_TEST_EXPECT_MSG_EQ ((table->LookupReactiveExpired (dst) == correct), true, "Reactive expiration works");
179  NS_TEST_EXPECT_MSG_EQ ((table->LookupProactiveExpired () == correct), true, "Proactive expiration works");
180 
181  NS_TEST_EXPECT_MSG_EQ (table->LookupReactive (dst).IsValid (), false, "Reactive expiration works");
182  NS_TEST_EXPECT_MSG_EQ (table->LookupProactive ().IsValid (), false, "Proactive expiration works");
183 }
184 
185 void
187 {
188  for (std::vector<Mac48Address>::const_iterator i = precursors.begin (); i != precursors.end (); i++)
189  {
190  table->AddPrecursor (dst, iface, *i, Seconds (100));
191  // Check that duplicates are filtered
192  table->AddPrecursor (dst, iface, *i, Seconds (100));
193  }
194 }
195 
196 void
198 {
200  NS_TEST_EXPECT_MSG_EQ (precursors.size (), precursorList.size (), "Precursors size works");
201  for (unsigned i = 0; i < precursors.size (); i++)
202  {
203  NS_TEST_EXPECT_MSG_EQ (precursorList[i].first, iface, "Precursors lookup works");
204  NS_TEST_EXPECT_MSG_EQ (precursorList[i].second, precursors[i], "Precursors lookup works");
205  }
206 }
207 
208 void
210 {
211  table = CreateObject<HwmpRtable> ();
212 
213  Simulator::Schedule (Seconds (0), &HwmpRtableTest::TestLookup, this);
214  Simulator::Schedule (Seconds (1), &HwmpRtableTest::TestAddPath, this);
215  Simulator::Schedule (Seconds (2), &HwmpRtableTest::TestPrecursorAdd, this);
216  Simulator::Schedule (expire + Seconds (2), &HwmpRtableTest::TestExpire, this);
217  Simulator::Schedule (expire + Seconds (3), &HwmpRtableTest::TestPrecursorFind, this);
218 
219  Simulator::Run ();
220  Simulator::Destroy ();
221 }
222 //-----------------------------------------------------------------------------
225 {
227  TestCase ("PeerLinkFrames (open, confirm, close) unit tests")
228  {
229  }
230  virtual void DoRun ();
231 };
232 
233 void
235 {
236  {
239  fields.capability = 0;
240  fields.meshId = IeMeshId ("qwertyuiop");
241  a.SetPlinkOpenStart (fields);
242  Ptr<Packet> packet = Create<Packet> ();
243  packet->AddHeader (a);
245  packet->RemoveHeader (b);
246  NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_OPEN works");
247  }
248  {
251  fields.capability = 0;
252  fields.aid = 1234;
253  a.SetPlinkConfirmStart (fields);
254  Ptr<Packet> packet = Create<Packet> ();
255  packet->AddHeader (a);
257  packet->RemoveHeader (b);
258  NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_CONFIRM works");
259  }
260  {
263  fields.meshId = IeMeshId ("qqq");
264  a.SetPlinkCloseStart (fields);
265  Ptr<Packet> packet = Create<Packet> ();
266  packet->AddHeader (a);
268  packet->RemoveHeader (b);
269  NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_CLOSE works");
270  }
271 }
279 {
280 public:
281  Dot11sTestSuite ();
282 };
283 
285  : TestSuite ("devices-mesh-dot11s", UNIT)
286 {
287  AddTestCase (new MeshHeaderTest, TestCase::QUICK);
288  AddTestCase (new HwmpRtableTest, TestCase::QUICK);
289  AddTestCase (new PeerLinkFrameStartTest, TestCase::QUICK);
290 }
291 
ns3::dot11s::HwmpRtable::DeleteReactivePath
void DeleteReactivePath(Mac48Address destination)
Delete the reactive paths toward a destination.
Definition: hwmp-rtable.cc:140
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
HwmpRtableTest::TestPrecursorFind
void TestPrecursorFind()
Test add precursors and find precursor list in rtable.
Definition: dot11s-test-suite.cc:197
first
Definition: first.py:1
MeshHeaderTest::DoRun
void DoRun()
Implementation to actually run this TestCase.
Definition: dot11s-test-suite.cc:54
ns3::dot11s::HwmpRtable::AddReactivePath
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:59
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
HwmpRtableTest::TestAddPath
void TestAddPath()
Test add path and try to lookup after entry has expired.
Definition: dot11s-test-suite.cc:167
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
HwmpRtableTest::seqnum
uint32_t seqnum
sequence number
Definition: dot11s-test-suite.cc:128
HwmpRtableTest::TestLookup
void TestLookup()
Test Add apth and lookup path;.
Definition: dot11s-test-suite.cc:149
ns3::dot11s::HwmpRtable::LookupResult
Route lookup result, return type of LookupXXX methods.
Definition: hwmp-rtable.h:45
MeshHeaderTest
Built-in self test for MeshHeader.
Definition: dot11s-test-suite.cc:45
ns3::dot11s::IeMeshId
a IEEE 802.11 Mesh ID element (Section 8.4.2.101 of IEEE 802.11-2012)
Definition: ie-dot11s-id.h:36
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
ns3::dot11s::HwmpRtable::AddProactivePath
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:78
ns3::dot11s::HwmpRtable::DeleteProactivePath
void DeleteProactivePath()
Delete all the proactive paths.
Definition: hwmp-rtable.cc:120
ns3::dot11s::MeshHeader
Mesh Control field, see Section 8.2.4.7.3 IEEE 802.11-2012.
Definition: dot11s-mac-header.h:38
ns3::TestCase
encapsulates test code
Definition: test.h:1154
HwmpRtableTest::HwmpRtableTest
HwmpRtableTest()
Definition: dot11s-test-suite.cc:134
Dot11sTestSuite::Dot11sTestSuite
Dot11sTestSuite()
Definition: dot11s-test-suite.cc:284
HwmpRtableTest::TestPrecursorAdd
void TestPrecursorAdd()
Test add precursors and find precursor list in rtable.
Definition: dot11s-test-suite.cc:186
ns3::Ptr< Packet >
HwmpRtableTest::expire
Time expire
expiration time
Definition: dot11s-test-suite.cc:129
HwmpRtableTest::DoRun
virtual void DoRun()
Implementation to actually run this TestCase.
Definition: dot11s-test-suite.cc:209
ns3::dot11s::HwmpRtable::LookupReactiveExpired
LookupResult LookupReactiveExpired(Mac48Address destination)
Return all reactive paths, including expired.
Definition: hwmp-rtable.cc:166
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
ns3::dot11s::HwmpRtable::LookupResult::IsValid
bool IsValid() const
Definition: hwmp-rtable.cc:253
NS_TEST_EXPECT_MSG_EQ
#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:283
HwmpRtableTest::dst
Mac48Address dst
destination address
Definition: dot11s-test-suite.cc:124
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::dot11s::HwmpRtable::GetPrecursors
PrecursorList GetPrecursors(Mac48Address destination)
Get the precursors list.
Definition: hwmp-rtable.cc:223
ns3::dot11s::HwmpRtable::LookupReactive
LookupResult LookupReactive(Mac48Address destination)
Lookup path to destination.
Definition: hwmp-rtable.cc:150
second
Definition: second.py:1
ns3::dot11s::MeshHeader::SetAddressExt
void SetAddressExt(uint8_t num_of_addresses)
Set Address Extension Mode.
Definition: dot11s-mac-header.cc:104
HwmpRtableTest::hop
Mac48Address hop
hop address
Definition: dot11s-test-suite.cc:125
ns3::dot11s::HwmpRtable::AddPrecursor
void AddPrecursor(Mac48Address destination, uint32_t precursorInterface, Mac48Address precursorAddress, Time lifetime)
Add a precursor.
Definition: hwmp-rtable.cc:90
ns3::dot11s::HwmpRtable::LookupProactiveExpired
LookupResult LookupProactiveExpired()
Return all proactive paths, including expired.
Definition: hwmp-rtable.cc:190
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1344
ns3::dot11s::MeshHeader::SetAddr4
void SetAddr4(Mac48Address address)
Set extended address 4.
Definition: dot11s-mac-header.cc:54
NS_TEST_ASSERT_MSG_EQ
#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:166
ns3::dot11s::MeshHeader::SetMeshTtl
void SetMeshTtl(uint8_t TTL)
Set mesh TTL subfield corresponding to the remaining number of hops the MSDU/MMPDU is forwarded.
Definition: dot11s-mac-header.cc:94
HwmpRtableTest
Unit test for HwmpRtable.
Definition: dot11s-test-suite.cc:104
HwmpRtableTest::TestExpire
void TestExpire()
Test add path and try to lookup after entry has expired.
Definition: dot11s-test-suite.cc:174
ns3::dot11s::HwmpRtable::LookupProactive
LookupResult LookupProactive()
Find proactive path to tree root.
Definition: hwmp-rtable.cc:179
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
HwmpRtableTest::table
Ptr< HwmpRtable > table
tab;e
Definition: dot11s-test-suite.cc:130
HwmpRtableTest::precursors
std::vector< Mac48Address > precursors
precursors
Definition: dot11s-test-suite.cc:131
ns3::dot11s::HwmpRtable::PrecursorList
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Definition: hwmp-rtable.h:77
ns3::dot11s::MeshHeader::SetAddr5
void SetAddr5(Mac48Address address)
Set extended address 5.
Definition: dot11s-mac-header.cc:59
g_dot11sTestSuite
static Dot11sTestSuite g_dot11sTestSuite
the test suite
Definition: dot11s-test-suite.cc:292
ns3::dot11s::MeshHeader::SetMeshSeqno
void SetMeshSeqno(uint32_t seqno)
Set four-byte mesh sequence number.
Definition: dot11s-mac-header.cc:84
HwmpRtableTest::metric
uint32_t metric
metric
Definition: dot11s-test-suite.cc:127
Dot11sTestSuite
Dot11s Test Suite.
Definition: dot11s-test-suite.cc:279
ns3::dot11s::MeshHeader::SetAddr6
void SetAddr6(Mac48Address address)
Set extended address 6.
Definition: dot11s-mac-header.cc:64
MeshHeaderTest::MeshHeaderTest
MeshHeaderTest()
Definition: dot11s-test-suite.cc:46
HwmpRtableTest::iface
uint32_t iface
interface
Definition: dot11s-test-suite.cc:126