A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dot11s-test-suite.cc
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 namespace ns3 {
30 namespace dot11s {
31 
33 struct MeshHeaderTest : public TestCase
34 {
35  MeshHeaderTest () :
36  TestCase ("Dot11sMeshHeader roundtrip serialization")
37  {
38  }
39  void DoRun ();
40 };
41 
42 void
44 {
45  {
46  MeshHeader a;
47  a.SetAddressExt (3);
48  a.SetAddr4 (Mac48Address ("11:22:33:44:55:66"));
49  a.SetAddr5 (Mac48Address ("11:00:33:00:55:00"));
50  a.SetAddr6 (Mac48Address ("00:22:00:44:00:66"));
51  a.SetMeshTtl (122);
52  a.SetMeshSeqno (321);
53  Ptr<Packet> packet = Create<Packet> ();
54  packet->AddHeader (a);
55  MeshHeader b;
56  packet->RemoveHeader (b);
57  NS_TEST_ASSERT_MSG_EQ (a, b, "Mesh header roundtrip serialization works, 3 addresses");
58  }
59  {
60  MeshHeader a;
61  a.SetAddressExt (2);
62  a.SetAddr5 (Mac48Address ("11:00:33:00:55:00"));
63  a.SetAddr6 (Mac48Address ("00:22:00:44:00:66"));
64  a.SetMeshTtl (122);
65  a.SetMeshSeqno (321);
66  Ptr<Packet> packet = Create<Packet> ();
67  packet->AddHeader (a);
68  MeshHeader b;
69  packet->RemoveHeader (b);
70  NS_TEST_ASSERT_MSG_EQ (a, b, "Mesh header roundtrip serialization works, 2 addresses");
71  }
72  {
73  MeshHeader a;
74  a.SetAddressExt (1);
75  a.SetAddr4 (Mac48Address ("11:22:33:44:55:66"));
76  a.SetMeshTtl (122);
77  a.SetMeshSeqno (321);
78  Ptr<Packet> packet = Create<Packet> ();
79  packet->AddHeader (a);
80  MeshHeader b;
81  packet->RemoveHeader (b);
82  NS_TEST_ASSERT_MSG_EQ (a, b, "Mesh header roundtrip serialization works, 1 address");
83  }
84 }
85 //-----------------------------------------------------------------------------
87 class HwmpRtableTest : public TestCase
88 {
89 public:
90  HwmpRtableTest ();
91  virtual void DoRun ();
92 
93 private:
95  void TestLookup ();
100  void TestAddPath ();
101  void TestExpire ();
103 
107  void TestPrecursorAdd ();
108  void TestPrecursorFind ();
110 private:
111  Mac48Address dst;
112  Mac48Address hop;
113  uint32_t iface;
114  uint32_t metric;
115  uint32_t seqnum;
116  Time expire;
117  Ptr<HwmpRtable> table;
118  std::vector<Mac48Address> precursors;
119 };
120 
121 HwmpRtableTest::HwmpRtableTest () :
122  TestCase ("HWMP routing table"),
123  dst ("01:00:00:01:00:01"),
124  hop ("01:00:00:01:00:03"),
125  iface (8010),
126  metric (10),
127  seqnum (1),
128  expire (Seconds (10))
129 {
130  precursors.push_back (Mac48Address ("00:10:20:30:40:50"));
131  precursors.push_back (Mac48Address ("00:11:22:33:44:55"));
132  precursors.push_back (Mac48Address ("00:01:02:03:04:05"));
133 }
134 
135 void
137 {
138  HwmpRtable::LookupResult correct (hop, iface, metric, seqnum);
139 
140  // Reactive path
141  table->AddReactivePath (dst, hop, iface, metric, expire, seqnum);
142  NS_TEST_EXPECT_MSG_EQ ((table->LookupReactive (dst) == correct), true, "Reactive lookup works");
143  table->DeleteReactivePath (dst);
144  NS_TEST_EXPECT_MSG_EQ (table->LookupReactive (dst).IsValid (), false, "Reactive lookup works");
145 
146  // Proactive
147  table->AddProactivePath (metric, dst, hop, iface, expire, seqnum);
148  NS_TEST_EXPECT_MSG_EQ ((table->LookupProactive () == correct), true, "Proactive lookup works");
149  table->DeleteProactivePath (dst);
150  NS_TEST_EXPECT_MSG_EQ (table->LookupProactive ().IsValid (), false, "Proactive lookup works");
151 }
152 
153 void
154 HwmpRtableTest::TestAddPath ()
155 {
156  table->AddReactivePath (dst, hop, iface, metric, expire, seqnum);
157  table->AddProactivePath (metric, dst, hop, iface, expire, seqnum);
158 }
159 
160 void
161 HwmpRtableTest::TestExpire ()
162 {
163  // this is assumed to be called when path records are already expired
164  HwmpRtable::LookupResult correct (hop, iface, metric, seqnum);
165  NS_TEST_EXPECT_MSG_EQ ((table->LookupReactiveExpired (dst) == correct), true, "Reactive expiration works");
166  NS_TEST_EXPECT_MSG_EQ ((table->LookupProactiveExpired () == correct), true, "Proactive expiration works");
167 
168  NS_TEST_EXPECT_MSG_EQ (table->LookupReactive (dst).IsValid (), false, "Reactive expiration works");
169  NS_TEST_EXPECT_MSG_EQ (table->LookupProactive ().IsValid (), false, "Proactive expiration works");
170 }
171 
172 void
173 HwmpRtableTest::TestPrecursorAdd ()
174 {
175  for (std::vector<Mac48Address>::const_iterator i = precursors.begin (); i != precursors.end (); i++)
176  {
177  table->AddPrecursor (dst, iface, *i, Seconds (100));
178  // Check that duplicates are filtered
179  table->AddPrecursor (dst, iface, *i, Seconds (100));
180  }
181 }
182 
183 void
184 HwmpRtableTest::TestPrecursorFind ()
185 {
186  HwmpRtable::PrecursorList precursorList = table->GetPrecursors (dst);
187  NS_TEST_EXPECT_MSG_EQ (precursors.size (), precursorList.size (), "Precursors size works");
188  for (unsigned i = 0; i < precursors.size (); i++)
189  {
190  NS_TEST_EXPECT_MSG_EQ (precursorList[i].first, iface, "Precursors lookup works");
191  NS_TEST_EXPECT_MSG_EQ (precursorList[i].second, precursors[i], "Precursors lookup works");
192  }
193 }
194 
195 void
197 {
198  table = CreateObject<HwmpRtable> ();
199 
201  Simulator::Schedule (Seconds (1), &HwmpRtableTest::TestAddPath, this);
202  Simulator::Schedule (Seconds (2), &HwmpRtableTest::TestPrecursorAdd, this);
203  Simulator::Schedule (expire + Seconds (2), &HwmpRtableTest::TestExpire, this);
204  Simulator::Schedule (expire + Seconds (3), &HwmpRtableTest::TestPrecursorFind, this);
205 
206  Simulator::Run ();
208 }
209 //-----------------------------------------------------------------------------
212 {
214  TestCase ("PeerLinkFrames (open, confirm, close) unit tests")
215  {
216  }
217  virtual void DoRun ();
218 };
219 
220 void
222 {
223  {
226  fields.subtype = (uint8_t)(WifiActionHeader::PEER_LINK_OPEN);
227  fields.capability = 0;
228  fields.aid = 101;
229  fields.reasonCode = 12;
230  fields.meshId = IeMeshId ("qwertyuiop");
231  a.SetPlinkFrameStart (fields);
232  Ptr<Packet> packet = Create<Packet> ();
233  packet->AddHeader (a);
235  b.SetPlinkFrameSubtype ((uint8_t)(WifiActionHeader::PEER_LINK_OPEN));
236  packet->RemoveHeader (b);
237  NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_OPEN works");
238  }
239  {
242  fields.subtype = (uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM);
243  fields.capability = 0;
244  fields.aid = 1234;
245  fields.reasonCode = 12;
246  fields.meshId = IeMeshId ("qwerty");
247  a.SetPlinkFrameStart (fields);
248  Ptr<Packet> packet = Create<Packet> ();
249  packet->AddHeader (a);
251  b.SetPlinkFrameSubtype ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM));
252  packet->RemoveHeader (b);
253  NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_CONFIRM works");
254  }
255  {
258  fields.subtype = (uint8_t)(WifiActionHeader::PEER_LINK_CLOSE);
259  fields.capability = 0;
260  fields.aid = 10;
261  fields.meshId = IeMeshId ("qqq");
262  fields.reasonCode = 12;
263  a.SetPlinkFrameStart (fields);
264  Ptr<Packet> packet = Create<Packet> ();
265  packet->AddHeader (a);
267  b.SetPlinkFrameSubtype ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE));
268  packet->RemoveHeader (b);
269  NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_CLOSE works");
270  }
271 }
272 //-----------------------------------------------------------------------------
274 {
275 public:
276  Dot11sTestSuite ();
277 };
278 
279 Dot11sTestSuite::Dot11sTestSuite ()
280  : TestSuite ("devices-mesh-dot11s", UNIT)
281 {
282  AddTestCase (new MeshHeaderTest, TestCase::QUICK);
283  AddTestCase (new HwmpRtableTest, TestCase::QUICK);
284  AddTestCase (new PeerLinkFrameStartTest, TestCase::QUICK);
285 }
286 
287 static Dot11sTestSuite g_dot11sTestSuite;
288 }
289 }
uint32_t RemoveHeader(Header &header)
Definition: packet.cc:285
Built-in self test for FlameHeader.
keep track of time unit.
Definition: nstime.h:149
Unit test for HwmpRtable.
Route lookup result, return type of LookupXXX methods.
Definition: hwmp-rtable.h:44
A suite of tests to run.
Definition: test.h:962
static void Run(void)
Definition: simulator.cc:157
encapsulates test code
Definition: test.h:834
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Definition: simulator.h:820
void TestLookup()
Test Add apth and lookup path;.
a IEEE 802.11s Mesh ID 7.3.287 of 802.11s draft 3.0
Definition: ie-dot11s-id.h:34
virtual void DoRun()
Implementation to actually run this test case.
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Definition: hwmp-rtable.h:62
TestCase(std::string name)
Definition: test.cc:147
static void Destroy(void)
Definition: simulator.cc:121
an EUI-48 address
Definition: mac48-address.h:41
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
Mesh Control field, see IEEE 802.11s draft 3.0 section 7.1.3.5b.
void DoRun()
Implementation to actually run this test case.
void AddHeader(const Header &header)
Definition: packet.cc:270