A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ie-dot11s-preq.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008,2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Kirill Andreev <andreev@iitp.ru>
7 */
8
9#include "ie-dot11s-preq.h"
10
11#include "ns3/address-utils.h"
12#include "ns3/assert.h"
13#include "ns3/packet.h"
14
15namespace ns3
16{
17namespace dot11s
18{
19/*************************
20 * DestinationAddressUnit
21 ************************/
23 : m_do(false),
24 m_rf(false),
25 m_usn(false),
26 m_destinationAddress(Mac48Address()),
27 m_destSeqNumber(0)
28{
29}
30
31void
32DestinationAddressUnit::SetFlags(bool doFlag, bool rfFlag, bool usnFlag)
33{
34 m_do = doFlag;
35 m_rf = rfFlag;
36 m_usn = usnFlag;
37}
38
39void
41{
42 m_destSeqNumber = dest_seq_number;
43 if (m_destSeqNumber != 0)
44 {
45 m_usn = true;
46 }
47}
48
49void
54
55bool
57{
58 return m_do;
59}
60
61bool
63{
64 return m_rf;
65}
66
67bool
69{
70 return m_usn;
71}
72
78
84
85/********************************
86 * IePreq
87 *******************************/
91
93 : m_maxSize(32),
94 m_flags(0),
95 m_hopCount(0),
96 m_ttl(0),
97 m_preqId(0),
98 m_originatorAddress(Mac48Address::GetBroadcast()),
99 m_originatorSeqNumber(0),
100 m_lifetime(0),
101 m_metric(0),
102 m_destCount(0)
103{
104}
105
108{
109 return IE_PREQ;
110}
111
112void
114{
115 m_flags |= 1 << 1;
116}
117
118void
120{
121 m_flags |= 1 << 2;
122}
123
124void
125IePreq::SetHopcount(uint8_t hopcount)
126{
127 m_hopCount = hopcount;
128}
129
130void
131IePreq::SetTTL(uint8_t ttl)
132{
133 m_ttl = ttl;
134}
135
136void
138{
139 m_preqId = preq_id;
140}
141
142void
144{
145 m_metric = metric;
146}
147
148void
150{
151 m_originatorAddress = originator_address;
152}
153
154void
156{
157 m_originatorSeqNumber = originator_seq_number;
158}
159
160void
162{
163 m_lifetime = lifetime;
164}
165
166void
167IePreq::SetDestCount(uint8_t dest_count)
168{
169 m_destCount = dest_count;
170}
171
172bool
174{
175 return (m_flags & (1 << 1));
176}
177
178bool
180{
181 return (m_flags & (1 << 2));
182}
183
184uint8_t
186{
187 return m_hopCount;
188}
189
190uint8_t
192{
193 return m_ttl;
194}
195
198{
199 return m_preqId;
200}
201
204{
205 return m_metric;
206}
207
213
219
222{
223 return m_lifetime;
224}
225
226uint8_t
228{
229 return m_destCount;
230}
231
232void
234{
235 m_ttl--;
236 m_hopCount++;
237}
238
239void
241{
242 m_metric += metric;
243}
244
245void
247{
248 i.WriteU8(m_flags);
250 i.WriteU8(m_ttl);
257 int written = 0;
258 for (auto j = m_destinations.begin(); j != m_destinations.end(); j++)
259 {
260 uint8_t flags = 0;
261 if ((*j)->IsDo())
262 {
263 flags |= 1 << 0;
264 }
265 if ((*j)->IsRf())
266 {
267 flags |= 1 << 1;
268 }
269 if ((*j)->IsUsn())
270 {
271 flags |= 1 << 2;
272 }
273 i.WriteU8(flags);
274 WriteTo(i, (*j)->GetDestinationAddress());
275 i.WriteHtolsbU32((*j)->GetDestSeqNumber());
276 written++;
277 if (written > m_maxSize)
278 {
279 break;
280 }
281 }
282}
283
284uint16_t
286{
287 Buffer::Iterator i = start;
288 m_flags = i.ReadU8();
289 m_hopCount = i.ReadU8();
290 m_ttl = i.ReadU8();
296 m_destCount = i.ReadU8();
297 for (int j = 0; j < m_destCount; j++)
298 {
300 bool doFlag = false;
301 bool rfFlag = false;
302 bool usnFlag = false;
303 uint8_t flags = i.ReadU8();
304 if (flags & (1 << 0))
305 {
306 doFlag = true;
307 }
308 if (flags & (1 << 1))
309 {
310 rfFlag = true;
311 }
312 if (flags & (1 << 2))
313 {
314 usnFlag = true;
315 }
316 new_element->SetFlags(doFlag, rfFlag, usnFlag);
317 Mac48Address addr;
318 ReadFrom(i, addr);
319 new_element->SetDestinationAddress(addr);
320 new_element->SetDestSeqNumber(i.ReadLsbtohU32());
321 m_destinations.push_back(new_element);
322 NS_ASSERT(28 + j * 11 < length);
323 }
324 return i.GetDistanceFrom(start);
325}
326
327uint16_t
329{
330 uint16_t retval = 1 // Flags
331 + 1 // Hopcount
332 + 1 // TTL
333 + 4 // PREQ ID
334 + 6 // Source address (originator)
335 + 4 // Originator seqno
336 + 4 // Lifetime
337 + 4 // metric
338 + 1; // destination count
340 {
341 retval += (m_maxSize * 11);
342 }
343 else
344 {
345 retval += (m_destCount * 11);
346 }
347 return retval;
348}
349
350void
351IePreq::Print(std::ostream& os) const
352{
353 os << "PREQ=(originator address=" << m_originatorAddress << ", TTL=" << (uint16_t)m_ttl
354 << ", hop count=" << (uint16_t)m_hopCount << ", metric=" << m_metric
355 << ", seqno=" << m_originatorSeqNumber << ", lifetime=" << m_lifetime
356 << ", preq ID=" << m_preqId << ", Destinations=(";
357 for (int j = 0; j < m_destCount; j++)
358 {
359 os << m_destinations[j]->GetDestinationAddress();
360 }
361 os << ")";
362}
363
364std::vector<Ptr<DestinationAddressUnit>>
369
370void
372 bool rfFlag,
373 Mac48Address dest_address,
374 uint32_t dest_seq_number)
375{
376 for (auto i = m_destinations.begin(); i != m_destinations.end(); i++)
377 {
378 if ((*i)->GetDestinationAddress() == dest_address)
379 {
380 return;
381 }
382 }
383 /// @todo check overflow
385 new_element->SetFlags(doFlag, rfFlag, (dest_seq_number == 0));
386 new_element->SetDestinationAddress(dest_address);
387 new_element->SetDestSeqNumber(dest_seq_number);
388 m_destinations.push_back(new_element);
389 m_destCount++;
390}
391
392void
394{
395 for (auto i = m_destinations.begin(); i != m_destinations.end(); i++)
396 {
397 if ((*i)->GetDestinationAddress() == dest_address)
398 {
399 m_destinations.erase(i);
400 m_destCount--;
401 break;
402 }
403 }
404}
405
406void
408{
409 for (auto j = m_destinations.begin(); j != m_destinations.end(); j++)
410 {
411 (*j) = nullptr;
412 }
413 m_destinations.clear();
414 m_destCount = 0;
415}
416
417bool
419{
420 return (a.m_do == b.m_do && a.m_rf == b.m_rf && a.m_usn == b.m_usn &&
423}
424
425bool
426operator==(const IePreq& a, const IePreq& b)
427{
428 bool ok = (a.m_flags == b.m_flags && a.m_hopCount == b.m_hopCount && a.m_ttl == b.m_ttl &&
431 a.m_metric == b.m_metric && a.m_destCount == b.m_destCount);
432
433 if (!ok)
434 {
435 return false;
436 }
437 if (a.m_destinations.size() != b.m_destinations.size())
438 {
439 return false;
440 }
441 for (size_t i = 0; i < a.m_destinations.size(); ++i)
442 {
443 if (!(*(PeekPointer(a.m_destinations[i])) == *(PeekPointer(b.m_destinations[i]))))
444 {
445 return false;
446 }
447 }
448 return true;
449}
450
451bool
453{
454 if (m_originatorAddress != originator)
455 {
456 return false;
457 }
458 if (m_destinations[0]->GetDestinationAddress() == Mac48Address::GetBroadcast())
459 {
460 return false;
461 }
462 // -fstrict-overflow sensitive, see bug 1868
463 if (GetInformationFieldSize() > 255 - 11)
464 {
465 return false;
466 }
467 return true;
468}
469
470bool
472{
473 // -fstrict-overflow sensitive, see bug 1868
474 return (GetInformationFieldSize() > 255 - 11);
475}
476
477std::ostream&
478operator<<(std::ostream& os, const IePreq& a)
479{
480 a.Print(os);
481 return os;
482}
483} // namespace dot11s
484} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
void WriteHtolsbU32(uint32_t data)
Definition buffer.cc:899
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
uint32_t ReadLsbtohU32()
Definition buffer.cc:1065
an EUI-48 address
static Mac48Address GetBroadcast()
Smart pointer class similar to boost::intrusive_ptr.
Describes an address unit in PREQ information element See 7.3.2.96 for more details.
bool IsUsn() const
Is USN function.
uint32_t GetDestSeqNumber() const
Get destination sequence number.
bool IsRf() const
is RF function
void SetDestSeqNumber(uint32_t dest_seq_number)
Set destination sequence number.
Mac48Address m_destinationAddress
destination address
uint32_t m_destSeqNumber
destination sequence number
Mac48Address GetDestinationAddress() const
Get destination address function.
void SetFlags(bool doFlag, bool rfFlag, bool usnFlag)
Set flags function.
void SetDestinationAddress(Mac48Address dest_address)
Set destination address function.
bool IsDo() const
Is do function.
See 7.3.2.96 of 802.11s draft 2.07.
uint32_t GetOriginatorSeqNumber() const
Get originator sequence number value.
uint32_t m_originatorSeqNumber
originator sequence number
void DelDestinationAddressElement(Mac48Address dest_address)
Delete a destination address unit by destination.
uint8_t m_destCount
destination count
void SetHopcount(uint8_t hopcount)
Set number of hops from originator to mesh STA transmitting this element.
uint8_t GetDestCount() const
Get destination count.
void SetNeedNotPrep()
Set Proactive PREP subfield to off.
bool IsUnicastPreq() const
Is unicast PREQ function.
uint16_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
uint8_t GetHopCount() const
Get hop count value.
void SetUnicastPreq()
Set flag indicating that PREQ is unicast.
std::vector< Ptr< DestinationAddressUnit > > GetDestinationList()
Get all destinations, which are stored in PREQ:
void SetOriginatorSeqNumber(uint32_t originator_seq_number)
Set originator sequence number.
uint32_t GetMetric() const
Get metric value.
void SetTTL(uint8_t ttl)
Set remaining number of hops allowed for this element.
uint32_t m_preqId
PREQ ID.
void SetOriginatorAddress(Mac48Address originator_address)
Set originator address value.
void Print(std::ostream &os) const override
Generate human-readable form of IE.
Mac48Address GetOriginatorAddress() const
Get originator address value.
void DecrementTtl()
Handle TTL.
uint32_t GetPreqID() const
Get path discovery id field.
uint8_t m_hopCount
hop count
void ClearDestinationAddressElements()
Clear PREQ: remove all destinations.
void SetDestCount(uint8_t dest_count)
Set destination count value.
void SetMetric(uint32_t metric)
Set metric value.
bool IsFull() const
Is full function.
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
uint16_t DeserializeInformationField(Buffer::Iterator i, uint16_t length) override
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
bool MayAddAddress(Mac48Address originator)
Checks that preq's originator address equals to originator, and this preq is not proactive.
uint32_t m_metric
metric
void SerializeInformationField(Buffer::Iterator i) const override
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
uint8_t GetTtl() const
Get TTL value.
void SetPreqID(uint32_t id)
Set path discovery id field.
void IncrementMetric(uint32_t metric)
Handle Metric:
Mac48Address m_originatorAddress
originator address
uint8_t m_maxSize
how many destinations we support
uint32_t GetLifetime() const
Get lifetime value.
std::vector< Ptr< DestinationAddressUnit > > m_destinations
the destinations
void AddDestinationAddressElement(bool doFlag, bool rfFlag, Mac48Address dest_address, uint32_t dest_seq_number)
Add a destination address unit: flags, destination and sequence number.
bool IsNeedNotPrep() const
Check whether Proactive PREP subfield to off.
void SetLifetime(uint32_t lifetime)
Set lifetime in TUs for the forwarding information to be considered valid.
uint32_t m_lifetime
lifetime
#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
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
bool operator==(const MeshHeader &a, const MeshHeader &b)
std::ostream & operator<<(std::ostream &os, const IeBeaconTiming &a)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
Definition ptr.h:443
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
#define IE_PREQ