A Discrete-Event Network Simulator
API
mesh-information-element-vector-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 
21 #include "ns3/test.h"
22 #include "ns3/mesh-information-element-vector.h"
23 // All information elements:
24 #include "ns3/ie-dot11s-beacon-timing.h"
25 #include "ns3/ie-dot11s-configuration.h"
26 #include "ns3/ie-dot11s-id.h"
27 #include "ns3/ie-dot11s-metric-report.h"
28 #include "ns3/ie-dot11s-peer-management.h"
29 #include "ns3/ie-dot11s-peering-protocol.h"
30 #include "ns3/ie-dot11s-perr.h"
31 #include "ns3/ie-dot11s-prep.h"
32 #include "ns3/ie-dot11s-preq.h"
33 #include "ns3/ie-dot11s-rann.h"
34 
35 using namespace ns3;
36 
49 {
51  TestCase ("Serialization test for all mesh information elements")
52  {
53  };
54  void DoRun ();
55 };
56 
57 void
59 {
61  {
62  //Mesh ID test
63  Ptr<dot11s::IeMeshId> meshId = Create<dot11s::IeMeshId> ("qwerty");
64  vector.AddInformationElement (meshId);
65  }
66  {
67  Ptr<dot11s::IeConfiguration> config = Create<dot11s::IeConfiguration> ();
68  vector.AddInformationElement (config);
69  }
70  {
71  Ptr<dot11s::IeLinkMetricReport> report = Create<dot11s::IeLinkMetricReport> (123456);
72  vector.AddInformationElement (report);
73  }
74  {
75  Ptr<dot11s::IePeerManagement> peerMan1 = Create<dot11s::IePeerManagement> ();
76  peerMan1->SetPeerOpen (1);
77  Ptr<dot11s::IePeerManagement> peerMan2 = Create<dot11s::IePeerManagement> ();
78  peerMan2->SetPeerConfirm (1, 2);
79  Ptr<dot11s::IePeerManagement> peerMan3 = Create<dot11s::IePeerManagement> ();
81  vector.AddInformationElement (peerMan1);
82  vector.AddInformationElement (peerMan2);
83  vector.AddInformationElement (peerMan3);
84  }
85  {
86  Ptr<dot11s::IeBeaconTiming> beaconTiming = Create<dot11s::IeBeaconTiming> ();
87  beaconTiming->AddNeighboursTimingElementUnit (1, Seconds (1.0), Seconds (4.0));
88  beaconTiming->AddNeighboursTimingElementUnit (2, Seconds (2.0), Seconds (3.0));
89  beaconTiming->AddNeighboursTimingElementUnit (3, Seconds (3.0), Seconds (2.0));
90  beaconTiming->AddNeighboursTimingElementUnit (4, Seconds (4.0), Seconds (1.0));
91  vector.AddInformationElement (beaconTiming);
92  }
93  {
94  Ptr<dot11s::IeRann> rann = Create<dot11s::IeRann> ();
95  rann->SetFlags (1);
96  rann->SetHopcount (2);
97  rann->SetTTL (4);
98  rann->DecrementTtl ();
99  NS_TEST_ASSERT_MSG_EQ (rann->GetTtl (), 3, "SetTtl works");
100  rann->SetOriginatorAddress (Mac48Address ("11:22:33:44:55:66"));
101  rann->SetDestSeqNumber (5);
102  rann->SetMetric (6);
103  rann->IncrementMetric (2);
104  NS_TEST_ASSERT_MSG_EQ (rann->GetMetric (), 8, "SetMetric works");
105  vector.AddInformationElement (rann);
106  }
107  {
108  Ptr<dot11s::IePreq> preq = Create<dot11s::IePreq> ();
109  preq->SetHopcount (0);
110  preq->SetTTL (1);
111  preq->SetPreqID (2);
112  preq->SetOriginatorAddress (Mac48Address ("11:22:33:44:55:66"));
113  preq->SetOriginatorSeqNumber (3);
114  preq->SetLifetime (4);
115  preq->AddDestinationAddressElement (false, false, Mac48Address ("11:11:11:11:11:11"), 5);
116  preq->AddDestinationAddressElement (false, false, Mac48Address ("22:22:22:22:22:22"), 6);
117  vector.AddInformationElement (preq);
118  }
119  {
120  Ptr<dot11s::IePrep> prep = Create<dot11s::IePrep> ();
121  prep->SetFlags (12);
122  prep->SetHopcount (11);
123  prep->SetTtl (10);
124  prep->SetDestinationAddress (Mac48Address ("11:22:33:44:55:66"));
125  prep->SetDestinationSeqNumber (123);
126  prep->SetLifetime (5000);
127  prep->SetMetric (4321);
128  prep->SetOriginatorAddress (Mac48Address ("33:00:22:00:11:00"));
129  prep->SetOriginatorSeqNumber (666);
130  vector.AddInformationElement (prep);
131  }
132  {
133  Ptr<dot11s::IePerr> perr = Create<dot11s::IePerr> ();
135  dest.destination = Mac48Address ("11:22:33:44:55:66");
136  dest.seqnum = 1;
137  perr->AddAddressUnit (dest);
138  dest.destination = Mac48Address ("10:20:30:40:50:60");
139  dest.seqnum = 2;
140  perr->AddAddressUnit (dest);
141  dest.destination = Mac48Address ("01:02:03:04:05:06");
142  dest.seqnum = 3;
143  perr->AddAddressUnit (dest);
144  vector.AddInformationElement (perr);
145  }
146  Ptr<Packet> packet = Create<Packet> ();
147  packet->AddHeader (vector);
148  uint32_t size = vector.GetSerializedSize ();
149  MeshInformationElementVector resultVector;
150  packet->RemoveHeader (resultVector, size);
151  NS_TEST_ASSERT_MSG_EQ (vector, resultVector, "Roundtrip serialization of all known information elements works");
152 }
153 
160 class MeshTestSuite : public TestSuite
161 {
162 public:
163  MeshTestSuite ();
164 };
165 
167  : TestSuite ("devices-mesh", UNIT)
168 {
169  AddTestCase (new MeshInformationElementVectorBist, TestCase::QUICK);
170 }
171 
173 
ns3::dot11s::IePreq::AddDestinationAddressElement
void AddDestinationAddressElement(bool doFlag, bool rfFlag, Mac48Address dest_address, uint32_t dest_seq_number)
Add a destination address unit: flags, destination and sequence number.
Definition: ie-dot11s-preq.cc:339
MeshTestSuite
Mesh Test Suite.
Definition: mesh-information-element-vector-test-suite.cc:161
ns3::dot11s::IePerr::AddAddressUnit
void AddAddressUnit(HwmpProtocol::FailedDestination unit)
Add address unit function.
Definition: ie-dot11s-perr.cc:99
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::dot11s::IeRann::DecrementTtl
void DecrementTtl()
Decrement TTL function.
Definition: ie-dot11s-rann.cc:100
ns3::dot11s::IeRann::SetOriginatorAddress
void SetOriginatorAddress(Mac48Address originator_address)
Set originator address value.
Definition: ie-dot11s-rann.cc:69
ns3::dot11s::IePreq::SetTTL
void SetTTL(uint8_t ttl)
Set remaining number of hops allowed for this element.
Definition: ie-dot11s-preq.cc:117
ns3::dot11s::IeRann::SetDestSeqNumber
void SetDestSeqNumber(uint32_t dest_seq_number)
Set destination sequence number value.
Definition: ie-dot11s-rann.cc:59
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
ns3::dot11s::IeRann::SetMetric
void SetMetric(uint32_t metric)
Set metric value to cumulative metric from originating root mesh STA to the mesh STA transmitting the...
Definition: ie-dot11s-rann.cc:64
ns3::dot11s::IePrep::SetOriginatorAddress
void SetOriginatorAddress(Mac48Address originator_address)
Set originator address function.
Definition: ie-dot11s-prep.cc:75
MeshInformationElementVectorBist::DoRun
void DoRun()
Implementation to actually run this TestCase.
Definition: mesh-information-element-vector-test-suite.cc:58
ns3::TestCase
encapsulates test code
Definition: test.h:1154
ns3::dot11s::IePeerManagement::SetPeerClose
void SetPeerClose(uint16_t localLinkID, uint16_t peerLinkId, PmpReasonCode reasonCode)
Set peer close function.
Definition: ie-dot11s-peer-management.cc:46
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
MeshInformationElementVectorBist::MeshInformationElementVectorBist
MeshInformationElementVectorBist()
Definition: mesh-information-element-vector-test-suite.cc:50
ns3::dot11s::IePreq::SetOriginatorAddress
void SetOriginatorAddress(Mac48Address originator_address)
Set originator address value.
Definition: ie-dot11s-preq.cc:132
ns3::dot11s::IeRann::GetTtl
uint8_t GetTtl()
Get TTL value.
Definition: ie-dot11s-rann.cc:85
ns3::WifiInformationElementVector::AddInformationElement
bool AddInformationElement(Ptr< WifiInformationElement > element)
add an IE, if maxSize has exceeded, returns false
Definition: wifi-information-element-vector.cc:147
ns3::dot11s::IePreq::SetLifetime
void SetLifetime(uint32_t lifetime)
Set lifetime in TUs for the forwarding information to be considered valid.
Definition: ie-dot11s-preq.cc:142
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
MeshInformationElementVectorBist
Built-in self test for MeshInformationElementVector and all IE.
Definition: mesh-information-element-vector-test-suite.cc:49
ns3::dot11s::IeRann::IncrementMetric
void IncrementMetric(uint32_t metric)
Increment metric.
Definition: ie-dot11s-rann.cc:107
ns3::dot11s::IeRann::GetMetric
uint32_t GetMetric()
Get metric value.
Definition: ie-dot11s-rann.cc:95
ns3::dot11s::IePrep::SetDestinationAddress
void SetDestinationAddress(Mac48Address dest_address)
Set destination address function.
Definition: ie-dot11s-prep.cc:65
ns3::dot11s::IePrep::SetDestinationSeqNumber
void SetDestinationSeqNumber(uint32_t dest_seq_number)
Set destination sequence number function.
Definition: ie-dot11s-prep.cc:60
ns3::dot11s::IePrep::SetOriginatorSeqNumber
void SetOriginatorSeqNumber(uint32_t originator_seq_number)
Set originator sequence number function.
Definition: ie-dot11s-prep.cc:80
ns3::dot11s::HwmpProtocol::FailedDestination::seqnum
uint32_t seqnum
sequence number
Definition: hwmp-protocol.h:80
ns3::dot11s::HwmpProtocol::FailedDestination::destination
Mac48Address destination
destination address
Definition: hwmp-protocol.h:79
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1344
g_meshTestSuite
static MeshTestSuite g_meshTestSuite
the test suite
Definition: mesh-information-element-vector-test-suite.cc:172
ns3::dot11s::IePrep::SetFlags
void SetFlags(uint8_t flags)
Set flags function.
Definition: ie-dot11s-prep.cc:45
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::IePeerManagement::SetPeerConfirm
void SetPeerConfirm(uint16_t localLinkID, uint16_t peerLinkId)
Set peer confirm function.
Definition: ie-dot11s-peer-management.cc:56
ns3::dot11s::IePrep::SetHopcount
void SetHopcount(uint8_t hopcount)
Set hop count function.
Definition: ie-dot11s-prep.cc:50
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::dot11s::IeBeaconTiming::AddNeighboursTimingElementUnit
void AddNeighboursTimingElementUnit(uint16_t aid, Time last_beacon, Time beacon_interval)
Add neighbors timing element unit.
Definition: ie-dot11s-beacon-timing.cc:80
ns3::dot11s::IeRann::SetTTL
void SetTTL(uint8_t ttl)
Set TTL value to the remaining number of hops allowed.
Definition: ie-dot11s-rann.cc:54
ns3::dot11s::IePreq::SetPreqID
void SetPreqID(uint32_t id)
Set path discovery id field.
Definition: ie-dot11s-preq.cc:122
ns3::dot11s::IePrep::SetLifetime
void SetLifetime(uint32_t lifetime)
Set lifetime function.
Definition: ie-dot11s-prep.cc:85
MeshTestSuite::MeshTestSuite
MeshTestSuite()
Definition: mesh-information-element-vector-test-suite.cc:166
ns3::dot11s::IePreq::SetOriginatorSeqNumber
void SetOriginatorSeqNumber(uint32_t originator_seq_number)
Set originator sequence number.
Definition: ie-dot11s-preq.cc:137
ns3::WifiInformationElementVector::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition: wifi-information-element-vector.cc:58
ns3::dot11s::IePreq::SetHopcount
void SetHopcount(uint8_t hopcount)
Set number of hops from originator to mesh STA transmitting this element.
Definition: ie-dot11s-preq.cc:112
ns3::dot11s::IeRann::SetHopcount
void SetHopcount(uint8_t hopcount)
Set hop count value to number of hops from the originating root mesh STA to the mesh STA transmitting...
Definition: ie-dot11s-rann.cc:49
ns3::dot11s::HwmpProtocol::FailedDestination
structure of unreachable destination - address and sequence number
Definition: hwmp-protocol.h:78
ns3::MeshInformationElementVector
Introspection did not find any typical Config paths.
Definition: mesh-information-element-vector.h:32
ns3::dot11s::IePrep::SetMetric
void SetMetric(uint32_t metric)
Set metric function.
Definition: ie-dot11s-prep.cc:70
ns3::dot11s::IePrep::SetTtl
void SetTtl(uint8_t ttl)
Set TTL function.
Definition: ie-dot11s-prep.cc:55
ns3::dot11s::REASON11S_MESH_CAPABILITY_POLICY_VIOLATION
@ REASON11S_MESH_CAPABILITY_POLICY_VIOLATION
Definition: ie-dot11s-peer-management.h:38
ns3::dot11s::IePeerManagement::SetPeerOpen
void SetPeerOpen(uint16_t localLinkId)
Set peer open function.
Definition: ie-dot11s-peer-management.cc:39
ns3::dot11s::IeRann::SetFlags
void SetFlags(uint8_t flags)
Set flags field.
Definition: ie-dot11s-rann.cc:44