A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mesh-information-element-vector.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Pavel Boyko <boyko@iitp.ru>
7 */
8
10
11#include "ns3/hwmp-protocol.h"
12#include "ns3/packet.h"
13
14#include <algorithm>
15// All information elements:
16#include "ns3/ie-dot11s-beacon-timing.h"
17#include "ns3/ie-dot11s-configuration.h"
18#include "ns3/ie-dot11s-id.h"
19#include "ns3/ie-dot11s-metric-report.h"
20#include "ns3/ie-dot11s-peer-management.h"
21#include "ns3/ie-dot11s-peering-protocol.h"
22#include "ns3/ie-dot11s-perr.h"
23#include "ns3/ie-dot11s-prep.h"
24#include "ns3/ie-dot11s-preq.h"
25#include "ns3/ie-dot11s-rann.h"
26
27namespace ns3
28{
29
30NS_OBJECT_ENSURE_REGISTERED(MeshInformationElementVector);
31
36
38{
39 for (auto i = m_elements.begin(); i != m_elements.end(); i++)
40 {
41 *i = nullptr;
42 }
43 m_elements.clear();
44}
45
48{
49 static TypeId tid = TypeId("ns3::MeshInformationElementVector")
51 .SetGroupName("Mesh")
52 .AddConstructor<MeshInformationElementVector>();
53 return tid;
54}
55
61
67
68void
70{
71 for (auto i = m_elements.begin(); i != m_elements.end(); i++)
72 {
73 start = (*i)->Serialize(start);
74 }
75}
76
79{
80 NS_FATAL_ERROR("This variant should not be called on a variable-sized header");
81 return 0;
82}
83
86{
87 uint32_t size = start.GetDistanceFrom(end);
88 uint32_t remaining = size;
89 while (remaining > 0)
90 {
91 uint32_t deserialized = DeserializeSingleIe(start);
92 start.Next(deserialized);
93 NS_ASSERT(deserialized <= remaining);
94 remaining -= deserialized;
95 }
96 NS_ASSERT_MSG(remaining == 0, "Error in deserialization");
97 return size;
98}
99
102{
103 Buffer::Iterator i = start;
104 uint8_t id = i.ReadU8();
105 uint8_t length = i.ReadU8();
106 i.Prev(2);
108 switch (id)
109 {
111 newElement = Create<dot11s::IeConfiguration>();
112 break;
113 case IE_MESH_ID:
114 newElement = Create<dot11s::IeMeshId>();
115 break;
118 break;
121 break;
122 case IE_BEACON_TIMING:
123 newElement = Create<dot11s::IeBeaconTiming>();
124 break;
125 case IE_RANN:
126 newElement = Create<dot11s::IeRann>();
127 break;
128 case IE_PREQ:
129 newElement = Create<dot11s::IePreq>();
130 break;
131 case IE_PREP:
132 newElement = Create<dot11s::IePrep>();
133 break;
134 case IE_PERR:
135 newElement = Create<dot11s::IePerr>();
136 break;
139 break;
140 default:
141 NS_FATAL_ERROR("Information element " << +id << " is not implemented");
142 return 0;
143 }
144 if (GetSize() + length > m_maxSize)
145 {
146 NS_FATAL_ERROR("Check max size for information element!");
147 }
148 i = newElement->Deserialize(i);
149 m_elements.push_back(newElement);
150 return i.GetDistanceFrom(start);
151}
152
153void
155{
156 for (auto i = m_elements.begin(); i != m_elements.end(); i++)
157 {
158 os << "(";
159 (*i)->Print(os);
160 os << ")";
161 }
162}
163
166{
167 return m_elements.begin();
168}
169
172{
173 return m_elements.end();
174}
175
176bool
178{
179 if (element->GetSerializedSize() + GetSize() > m_maxSize)
180 {
181 return false;
182 }
183 m_elements.push_back(element);
184 return true;
185}
186
189{
190 for (auto i = m_elements.begin(); i != m_elements.end(); i++)
191 {
192 if ((*i)->ElementId() == id)
193 {
194 return *i;
195 }
196 }
197 return nullptr;
198}
199
202{
203 uint32_t size = 0;
204 for (auto i = m_elements.begin(); i != m_elements.end(); i++)
205 {
206 size += (*i)->GetSerializedSize();
207 }
208 return size;
209}
210
211bool
213{
214 if (m_elements.size() != a.m_elements.size())
215 {
216 NS_ASSERT(false);
217 return false;
218 }
219 // In principle we could bypass some of the faffing about (and speed
220 // the comparison) by simply serialising each IE vector into a
221 // buffer and memcmp'ing the two.
222 //
223 // I'm leaving it like this, however, so that there is the option of
224 // having individual Information Elements implement slightly more
225 // flexible equality operators.
226 auto j = a.m_elements.begin();
227 for (auto i = m_elements.begin(); i != m_elements.end(); i++, j++)
228 {
229 if (!(*(*i) == *(*j)))
230 {
231 return false;
232 }
233 }
234
235 return true;
236}
237
238} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
void Prev()
go backward by one byte
Definition buffer.h:849
Protocol header serialization and deserialization.
Definition header.h:33
Iterator End()
Returns End of the vector.
uint32_t Deserialize(Buffer::Iterator start) override
bool AddInformationElement(Ptr< WifiInformationElement > element)
add an IE, if maxSize has exceeded, returns false
IE_VECTOR m_elements
Information element vector.
uint32_t GetSize() const
Current number of bytes.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint16_t m_maxSize
Size in bytes (actually, max packet length)
std::vector< Ptr< WifiInformationElement > >::iterator Iterator
As soon as this is a vector, we define an Iterator.
Ptr< WifiInformationElement > FindFirst(WifiInformationElementId id) const
vector of pointers to information elements is the body of IeVector
Iterator Begin()
Returns Begin of the vector.
void Serialize(Buffer::Iterator start) const override
void Print(std::ostream &os) const override
virtual bool operator==(const MeshInformationElementVector &a) const
Check if the given WifiInformationElementVectors are equivalent.
uint32_t DeserializeSingleIe(Buffer::Iterator start)
Needed when you try to deserialize a lonely IE inside other header.
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#define IE11S_MESH_PEERING_PROTOCOL_VERSION
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
#define IE_PREQ
#define IE_RANN
#define IE_MESH_CONFIGURATION
#define IE_PREP
#define IE_BEACON_TIMING
#define IE_MESH_LINK_METRIC_REPORT
#define IE_MESH_PEERING_MANAGEMENT
#define IE_MESH_ID
#define IE_PERR