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 
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 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
virtual void DoRun()
Implementation to actually run this TestCase.
void TestExpire()
Test add path and try to lookup after entry has expired.
an EUI-48 address
Definition: mac48-address.h:44
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
void DeleteReactivePath(Mac48Address destination)
Delete the reactive paths toward a destination.
Definition: hwmp-rtable.cc:140
LookupResult LookupReactive(Mac48Address destination)
Lookup path to destination.
Definition: hwmp-rtable.cc:150
LookupResult LookupReactiveExpired(Mac48Address destination)
Return all reactive paths, including expired.
Definition: hwmp-rtable.cc:166
PrecursorList GetPrecursors(Mac48Address destination)
Get the precursors list.
Definition: hwmp-rtable.cc:223
void DeleteProactivePath()
Delete all the proactive paths.
Definition: hwmp-rtable.cc:120
LookupResult LookupProactiveExpired()
Return all proactive paths, including expired.
Definition: hwmp-rtable.cc:190
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Definition: hwmp-rtable.h:77
LookupResult LookupProactive()
Find proactive path to tree root.
Definition: hwmp-rtable.cc:179
void AddPrecursor(Mac48Address destination, uint32_t precursorInterface, Mac48Address precursorAddress, Time lifetime)
Add a precursor.
Definition: hwmp-rtable.cc:90
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
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
a IEEE 802.11 Mesh ID element (Section 8.4.2.101 of IEEE 802.11-2012)
Definition: ie-dot11s-id.h:36
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:141
#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:240
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
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()
Implementation to actually run this TestCase.
Route lookup result, return type of LookupXXX methods.
Definition: hwmp-rtable.h:45