A Discrete-Event Network Simulator
API
mesh-information-element-vector-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 
20 #include "ns3/mesh-information-element-vector.h"
21 #include "ns3/test.h"
22 // All information elements:
23 #include "ns3/ie-dot11s-beacon-timing.h"
24 #include "ns3/ie-dot11s-configuration.h"
25 #include "ns3/ie-dot11s-id.h"
26 #include "ns3/ie-dot11s-metric-report.h"
27 #include "ns3/ie-dot11s-peer-management.h"
28 #include "ns3/ie-dot11s-peering-protocol.h"
29 #include "ns3/ie-dot11s-perr.h"
30 #include "ns3/ie-dot11s-prep.h"
31 #include "ns3/ie-dot11s-preq.h"
32 #include "ns3/ie-dot11s-rann.h"
33 
34 using namespace ns3;
35 
48 {
50  : TestCase("Serialization test for all mesh information elements"){};
51  void DoRun() override;
52 };
53 
54 void
56 {
58  {
59  // Mesh ID test
60  Ptr<dot11s::IeMeshId> meshId = Create<dot11s::IeMeshId>("qwerty");
61  vector.AddInformationElement(meshId);
62  }
63  {
64  Ptr<dot11s::IeConfiguration> config = Create<dot11s::IeConfiguration>();
65  vector.AddInformationElement(config);
66  }
67  {
68  Ptr<dot11s::IeLinkMetricReport> report = Create<dot11s::IeLinkMetricReport>(123456);
69  vector.AddInformationElement(report);
70  }
71  {
72  Ptr<dot11s::IePeerManagement> peerMan1 = Create<dot11s::IePeerManagement>();
73  peerMan1->SetPeerOpen(1);
74  Ptr<dot11s::IePeerManagement> peerMan2 = Create<dot11s::IePeerManagement>();
75  peerMan2->SetPeerConfirm(1, 2);
76  Ptr<dot11s::IePeerManagement> peerMan3 = Create<dot11s::IePeerManagement>();
77  peerMan3->SetPeerClose(1, 2, dot11s::REASON11S_MESH_CAPABILITY_POLICY_VIOLATION);
78  vector.AddInformationElement(peerMan1);
79  vector.AddInformationElement(peerMan2);
80  vector.AddInformationElement(peerMan3);
81  }
82  {
83  Ptr<dot11s::IeBeaconTiming> beaconTiming = Create<dot11s::IeBeaconTiming>();
84  beaconTiming->AddNeighboursTimingElementUnit(1, Seconds(1.0), Seconds(4.0));
85  beaconTiming->AddNeighboursTimingElementUnit(2, Seconds(2.0), Seconds(3.0));
86  beaconTiming->AddNeighboursTimingElementUnit(3, Seconds(3.0), Seconds(2.0));
87  beaconTiming->AddNeighboursTimingElementUnit(4, Seconds(4.0), Seconds(1.0));
88  vector.AddInformationElement(beaconTiming);
89  }
90  {
91  Ptr<dot11s::IeRann> rann = Create<dot11s::IeRann>();
92  rann->SetFlags(1);
93  rann->SetHopcount(2);
94  rann->SetTTL(4);
95  rann->DecrementTtl();
96  NS_TEST_ASSERT_MSG_EQ(rann->GetTtl(), 3, "SetTtl works");
97  rann->SetOriginatorAddress(Mac48Address("11:22:33:44:55:66"));
98  rann->SetDestSeqNumber(5);
99  rann->SetMetric(6);
100  rann->IncrementMetric(2);
101  NS_TEST_ASSERT_MSG_EQ(rann->GetMetric(), 8, "SetMetric works");
102  vector.AddInformationElement(rann);
103  }
104  {
105  Ptr<dot11s::IePreq> preq = Create<dot11s::IePreq>();
106  preq->SetHopcount(0);
107  preq->SetTTL(1);
108  preq->SetPreqID(2);
109  preq->SetOriginatorAddress(Mac48Address("11:22:33:44:55:66"));
110  preq->SetOriginatorSeqNumber(3);
111  preq->SetLifetime(4);
112  preq->AddDestinationAddressElement(false, false, Mac48Address("11:11:11:11:11:11"), 5);
113  preq->AddDestinationAddressElement(false, false, Mac48Address("22:22:22:22:22:22"), 6);
114  vector.AddInformationElement(preq);
115  }
116  {
117  Ptr<dot11s::IePrep> prep = Create<dot11s::IePrep>();
118  prep->SetFlags(12);
119  prep->SetHopcount(11);
120  prep->SetTtl(10);
121  prep->SetDestinationAddress(Mac48Address("11:22:33:44:55:66"));
122  prep->SetDestinationSeqNumber(123);
123  prep->SetLifetime(5000);
124  prep->SetMetric(4321);
125  prep->SetOriginatorAddress(Mac48Address("33:00:22:00:11:00"));
126  prep->SetOriginatorSeqNumber(666);
127  vector.AddInformationElement(prep);
128  }
129  {
130  Ptr<dot11s::IePerr> perr = Create<dot11s::IePerr>();
132  dest.destination = Mac48Address("11:22:33:44:55:66");
133  dest.seqnum = 1;
134  perr->AddAddressUnit(dest);
135  dest.destination = Mac48Address("10:20:30:40:50:60");
136  dest.seqnum = 2;
137  perr->AddAddressUnit(dest);
138  dest.destination = Mac48Address("01:02:03:04:05:06");
139  dest.seqnum = 3;
140  perr->AddAddressUnit(dest);
141  vector.AddInformationElement(perr);
142  }
143  Ptr<Packet> packet = Create<Packet>();
144  packet->AddHeader(vector);
145  uint32_t size = vector.GetSerializedSize();
146  MeshInformationElementVector resultVector;
147  packet->RemoveHeader(resultVector, size);
148  NS_TEST_ASSERT_MSG_EQ(vector,
149  resultVector,
150  "Roundtrip serialization of all known information elements works");
151 }
152 
158 class MeshTestSuite : public TestSuite
159 {
160  public:
161  MeshTestSuite();
162 };
163 
165  : TestSuite("devices-mesh", UNIT)
166 {
167  AddTestCase(new MeshInformationElementVectorBist, TestCase::QUICK);
168 }
169 
an EUI-48 address
Definition: mac48-address.h:46
bool AddInformationElement(Ptr< WifiInformationElement > element)
add an IE, if maxSize has exceeded, returns false
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
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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:301
A suite of tests to run.
Definition: test.h:1256
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
static MeshTestSuite g_meshTestSuite
the test suite
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Built-in self test for MeshInformationElementVector and all IE.
void DoRun() override
Implementation to actually run this TestCase.
structure of unreachable destination - address and sequence number
Definition: hwmp-protocol.h:89
Mac48Address destination
destination address
Definition: hwmp-protocol.h:90