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 
33 struct MeshHeaderTest : public TestCase
34 {
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 ();
96 
97  // Test add path and try to lookup after entry has expired
98  void TestAddPath ();
99  void TestExpire ();
100 
101  // Test add precursors and find precursor list in rtable
102  void TestPrecursorAdd ();
103  void TestPrecursorFind ();
104 
105 private:
108  uint32_t iface;
109  uint32_t metric;
110  uint32_t seqnum;
113  std::vector<Mac48Address> precursors;
114 };
115 
117  TestCase ("HWMP routing table"),
118  dst ("01:00:00:01:00:01"),
119  hop ("01:00:00:01:00:03"),
120  iface (8010),
121  metric (10),
122  seqnum (1),
123  expire (Seconds (10))
124 {
125  precursors.push_back (Mac48Address ("00:10:20:30:40:50"));
126  precursors.push_back (Mac48Address ("00:11:22:33:44:55"));
127  precursors.push_back (Mac48Address ("00:01:02:03:04:05"));
128 }
129 
130 void
132 {
134 
135  // Reactive path
137  NS_TEST_EXPECT_MSG_EQ ((table->LookupReactive (dst) == correct), true, "Reactive lookup works");
139  NS_TEST_EXPECT_MSG_EQ (table->LookupReactive (dst).IsValid (), false, "Reactive lookup works");
140 
141  // Proactive
143  NS_TEST_EXPECT_MSG_EQ ((table->LookupProactive () == correct), true, "Proactive lookup works");
145  NS_TEST_EXPECT_MSG_EQ (table->LookupProactive ().IsValid (), false, "Proactive lookup works");
146 }
147 
148 void
150 {
153 }
154 
155 void
157 {
158  // this is assumed to be called when path records are already expired
160  NS_TEST_EXPECT_MSG_EQ ((table->LookupReactiveExpired (dst) == correct), true, "Reactive expiration works");
161  NS_TEST_EXPECT_MSG_EQ ((table->LookupProactiveExpired () == correct), true, "Proactive expiration works");
162 
163  NS_TEST_EXPECT_MSG_EQ (table->LookupReactive (dst).IsValid (), false, "Reactive expiration works");
164  NS_TEST_EXPECT_MSG_EQ (table->LookupProactive ().IsValid (), false, "Proactive expiration works");
165 }
166 
167 void
169 {
170  for (std::vector<Mac48Address>::const_iterator i = precursors.begin (); i != precursors.end (); i++)
171  {
172  table->AddPrecursor (dst, iface, *i, Seconds (100));
173  // Check that duplicates are filtered
174  table->AddPrecursor (dst, iface, *i, Seconds (100));
175  }
176 }
177 
178 void
180 {
182  NS_TEST_EXPECT_MSG_EQ (precursors.size (), precursorList.size (), "Precursors size works");
183  for (unsigned i = 0; i < precursors.size (); i++)
184  {
185  NS_TEST_EXPECT_MSG_EQ (precursorList[i].first, iface, "Precursors lookup works");
186  NS_TEST_EXPECT_MSG_EQ (precursorList[i].second, precursors[i], "Precursors lookup works");
187  }
188 }
189 
190 void
192 {
193  table = CreateObject<HwmpRtable> ();
194 
195  Simulator::Schedule (Seconds (0), &HwmpRtableTest::TestLookup, this);
196  Simulator::Schedule (Seconds (1), &HwmpRtableTest::TestAddPath, this);
197  Simulator::Schedule (Seconds (2), &HwmpRtableTest::TestPrecursorAdd, this);
198  Simulator::Schedule (expire + Seconds (2), &HwmpRtableTest::TestExpire, this);
199  Simulator::Schedule (expire + Seconds (3), &HwmpRtableTest::TestPrecursorFind, this);
200 
201  Simulator::Run ();
202  Simulator::Destroy ();
203 }
204 //-----------------------------------------------------------------------------
207 {
209  TestCase ("PeerLinkFrames (open, confirm, close) unit tests")
210  {
211  }
212  virtual void DoRun ();
213 };
214 
215 void
217 {
218  {
221  fields.capability = 0;
222  fields.meshId = IeMeshId ("qwertyuiop");
223  a.SetPlinkOpenStart (fields);
224  Ptr<Packet> packet = Create<Packet> ();
225  packet->AddHeader (a);
227  packet->RemoveHeader (b);
228  NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_OPEN works");
229  }
230  {
233  fields.capability = 0;
234  fields.aid = 1234;
235  a.SetPlinkConfirmStart (fields);
236  Ptr<Packet> packet = Create<Packet> ();
237  packet->AddHeader (a);
239  packet->RemoveHeader (b);
240  NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_CONFIRM works");
241  }
242  {
245  fields.meshId = IeMeshId ("qqq");
246  a.SetPlinkCloseStart (fields);
247  Ptr<Packet> packet = Create<Packet> ();
248  packet->AddHeader (a);
250  packet->RemoveHeader (b);
251  NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_CLOSE works");
252  }
253 }
254 //-----------------------------------------------------------------------------
256 {
257 public:
258  Dot11sTestSuite ();
259 };
260 
262  : TestSuite ("devices-mesh-dot11s", UNIT)
263 {
264  AddTestCase (new MeshHeaderTest, TestCase::QUICK);
265  AddTestCase (new HwmpRtableTest, TestCase::QUICK);
266  AddTestCase (new PeerLinkFrameStartTest, TestCase::QUICK);
267 }
268 
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Definition: second.py:1
Route lookup result, return type of LookupXXX methods.
Definition: hwmp-rtable.h:44
A suite of tests to run.
Definition: test.h:1333
#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:278
LookupResult LookupReactiveExpired(Mac48Address destination)
Return all reactive paths, including expired.
Definition: hwmp-rtable.cc:159
Unit test for HwmpRtable.
void TestLookup()
Test Add apth and lookup path;.
void SetMeshSeqno(uint32_t seqno)
encapsulates test code
Definition: test.h:1147
a IEEE 802.11s Mesh ID 7.3.287 of 802.11s draft 3.0
Definition: ie-dot11s-id.h:34
bool IsValid() const
True for valid route.
Definition: hwmp-rtable.cc:239
void SetAddressExt(uint8_t num_of_addresses)
LookupResult LookupReactive(Mac48Address destination)
Lookup path to destination.
Definition: hwmp-rtable.cc:144
void SetMeshTtl(uint8_t TTL)
std::vector< std::pair< uint32_t, Mac48Address > > PrecursorList
Path precursor = {MAC, interface ID}.
Definition: hwmp-rtable.h:62
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
#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:161
PrecursorList GetPrecursors(Mac48Address destination)
Definition: hwmp-rtable.cc:210
void AddPrecursor(Mac48Address destination, uint32_t precursorInterface, Mac48Address precursorAddress, Time lifetime)
Definition: hwmp-rtable.cc:88
virtual void DoRun()
Implementation to actually run this TestCase.
void SetAddr6(Mac48Address address)
LookupResult LookupProactiveExpired()
Return all proactive paths, including expired.
Definition: hwmp-rtable.cc:180
void SetAddr4(Mac48Address address)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void AddReactivePath(Mac48Address destination, Mac48Address retransmitter, uint32_t interface, uint32_t metric, Time lifetime, uint32_t seqnum)
Definition: hwmp-rtable.cc:59
void DoRun()
Implementation to actually run this TestCase.
void SetAddr5(Mac48Address address)
an EUI-48 address
Definition: mac48-address.h:43
static Dot11sTestSuite g_dot11sTestSuite
Ptr< HwmpRtable > table
Built-in self test for FlameHeader.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
std::vector< Mac48Address > precursors
Mesh Control field, see IEEE 802.11s draft 3.0 section 7.1.3.5b.
void DeleteReactivePath(Mac48Address destination)
Definition: hwmp-rtable.cc:135
void AddProactivePath(uint32_t metric, Mac48Address root, Mac48Address retransmitter, uint32_t interface, Time lifetime, uint32_t seqnum)
Definition: hwmp-rtable.cc:77
Definition: first.py:1
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:257
LookupResult LookupProactive()
Find proactive path to tree root. Note that calling this method has side effect of deleting expired p...
Definition: hwmp-rtable.cc:170