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 * 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: Kirill Andreev <andreev@iitp.ru>
18 */
19
20#include "ie-dot11s-preq.h"
21
22#include "ns3/address-utils.h"
23#include "ns3/assert.h"
24#include "ns3/packet.h"
25
26namespace ns3
27{
28namespace dot11s
29{
30/*************************
31 * DestinationAddressUnit
32 ************************/
34 : m_do(false),
35 m_rf(false),
36 m_usn(false),
37 m_destinationAddress(Mac48Address()),
38 m_destSeqNumber(0)
39{
40}
41
42void
43DestinationAddressUnit::SetFlags(bool doFlag, bool rfFlag, bool usnFlag)
44{
45 m_do = doFlag;
46 m_rf = rfFlag;
47 m_usn = usnFlag;
48}
49
50void
52{
53 m_destSeqNumber = dest_seq_number;
54 if (m_destSeqNumber != 0)
55 {
56 m_usn = true;
57 }
58}
59
60void
62{
63 m_destinationAddress = dest_address;
64}
65
66bool
68{
69 return m_do;
70}
71
72bool
74{
75 return m_rf;
76}
77
78bool
80{
81 return m_usn;
82}
83
86{
87 return m_destSeqNumber;
88}
89
92{
94}
95
96/********************************
97 * IePreq
98 *******************************/
100{
101}
102
104 : m_maxSize(32),
105 m_flags(0),
106 m_hopCount(0),
107 m_ttl(0),
108 m_preqId(0),
109 m_originatorAddress(Mac48Address::GetBroadcast()),
110 m_originatorSeqNumber(0),
111 m_lifetime(0),
112 m_metric(0),
113 m_destCount(0)
114{
115}
116
119{
120 return IE_PREQ;
121}
122
123void
125{
126 m_flags |= 1 << 1;
127}
128
129void
131{
132 m_flags |= 1 << 2;
133}
134
135void
136IePreq::SetHopcount(uint8_t hopcount)
137{
138 m_hopCount = hopcount;
139}
140
141void
142IePreq::SetTTL(uint8_t ttl)
143{
144 m_ttl = ttl;
145}
146
147void
149{
150 m_preqId = preq_id;
151}
152
153void
155{
156 m_metric = metric;
157}
158
159void
161{
162 m_originatorAddress = originator_address;
163}
164
165void
167{
168 m_originatorSeqNumber = originator_seq_number;
169}
170
171void
173{
174 m_lifetime = lifetime;
175}
176
177void
178IePreq::SetDestCount(uint8_t dest_count)
179{
180 m_destCount = dest_count;
181}
182
183bool
185{
186 return (m_flags & (1 << 1));
187}
188
189bool
191{
192 return (m_flags & (1 << 2));
193}
194
195uint8_t
197{
198 return m_hopCount;
199}
200
201uint8_t
203{
204 return m_ttl;
205}
206
209{
210 return m_preqId;
211}
212
215{
216 return m_metric;
217}
218
221{
222 return m_originatorAddress;
223}
224
227{
229}
230
233{
234 return m_lifetime;
235}
236
237uint8_t
239{
240 return m_destCount;
241}
242
243void
245{
246 m_ttl--;
247 m_hopCount++;
248}
249
250void
252{
253 m_metric += metric;
254}
255
256void
258{
259 i.WriteU8(m_flags);
261 i.WriteU8(m_ttl);
268 int written = 0;
269 for (auto j = m_destinations.begin(); j != m_destinations.end(); j++)
270 {
271 uint8_t flags = 0;
272 if ((*j)->IsDo())
273 {
274 flags |= 1 << 0;
275 }
276 if ((*j)->IsRf())
277 {
278 flags |= 1 << 1;
279 }
280 if ((*j)->IsUsn())
281 {
282 flags |= 1 << 2;
283 }
284 i.WriteU8(flags);
285 WriteTo(i, (*j)->GetDestinationAddress());
286 i.WriteHtolsbU32((*j)->GetDestSeqNumber());
287 written++;
288 if (written > m_maxSize)
289 {
290 break;
291 }
292 }
293}
294
295uint16_t
297{
298 Buffer::Iterator i = start;
299 m_flags = i.ReadU8();
300 m_hopCount = i.ReadU8();
301 m_ttl = i.ReadU8();
307 m_destCount = i.ReadU8();
308 for (int j = 0; j < m_destCount; j++)
309 {
310 Ptr<DestinationAddressUnit> new_element = Create<DestinationAddressUnit>();
311 bool doFlag = false;
312 bool rfFlag = false;
313 bool usnFlag = false;
314 uint8_t flags = i.ReadU8();
315 if (flags & (1 << 0))
316 {
317 doFlag = true;
318 }
319 if (flags & (1 << 1))
320 {
321 rfFlag = true;
322 }
323 if (flags & (1 << 2))
324 {
325 usnFlag = true;
326 }
327 new_element->SetFlags(doFlag, rfFlag, usnFlag);
328 Mac48Address addr;
329 ReadFrom(i, addr);
330 new_element->SetDestinationAddress(addr);
331 new_element->SetDestSeqNumber(i.ReadLsbtohU32());
332 m_destinations.push_back(new_element);
333 NS_ASSERT(28 + j * 11 < length);
334 }
335 return i.GetDistanceFrom(start);
336}
337
338uint16_t
340{
341 uint16_t retval = 1 // Flags
342 + 1 // Hopcount
343 + 1 // TTL
344 + 4 // PREQ ID
345 + 6 // Source address (originator)
346 + 4 // Originator seqno
347 + 4 // Lifetime
348 + 4 // metric
349 + 1; // destination count
351 {
352 retval += (m_maxSize * 11);
353 }
354 else
355 {
356 retval += (m_destCount * 11);
357 }
358 return retval;
359}
360
361void
362IePreq::Print(std::ostream& os) const
363{
364 os << "PREQ=(originator address=" << m_originatorAddress << ", TTL=" << (uint16_t)m_ttl
365 << ", hop count=" << (uint16_t)m_hopCount << ", metric=" << m_metric
366 << ", seqno=" << m_originatorSeqNumber << ", lifetime=" << m_lifetime
367 << ", preq ID=" << m_preqId << ", Destinations=(";
368 for (int j = 0; j < m_destCount; j++)
369 {
370 os << m_destinations[j]->GetDestinationAddress();
371 }
372 os << ")";
373}
374
375std::vector<Ptr<DestinationAddressUnit>>
377{
378 return m_destinations;
379}
380
381void
383 bool rfFlag,
384 Mac48Address dest_address,
385 uint32_t dest_seq_number)
386{
387 for (auto i = m_destinations.begin(); i != m_destinations.end(); i++)
388 {
389 if ((*i)->GetDestinationAddress() == dest_address)
390 {
391 return;
392 }
393 }
394 /// \todo check overflow
395 Ptr<DestinationAddressUnit> new_element = Create<DestinationAddressUnit>();
396 new_element->SetFlags(doFlag, rfFlag, (dest_seq_number == 0));
397 new_element->SetDestinationAddress(dest_address);
398 new_element->SetDestSeqNumber(dest_seq_number);
399 m_destinations.push_back(new_element);
400 m_destCount++;
401}
402
403void
405{
406 for (auto i = m_destinations.begin(); i != m_destinations.end(); i++)
407 {
408 if ((*i)->GetDestinationAddress() == dest_address)
409 {
410 m_destinations.erase(i);
411 m_destCount--;
412 break;
413 }
414 }
415}
416
417void
419{
420 for (auto j = m_destinations.begin(); j != m_destinations.end(); j++)
421 {
422 (*j) = nullptr;
423 }
424 m_destinations.clear();
425 m_destCount = 0;
426}
427
428bool
430{
431 return (a.m_do == b.m_do && a.m_rf == b.m_rf && a.m_usn == b.m_usn &&
434}
435
436bool
437operator==(const IePreq& a, const IePreq& b)
438{
439 bool ok = (a.m_flags == b.m_flags && a.m_hopCount == b.m_hopCount && a.m_ttl == b.m_ttl &&
442 a.m_metric == b.m_metric && a.m_destCount == b.m_destCount);
443
444 if (!ok)
445 {
446 return false;
447 }
448 if (a.m_destinations.size() != b.m_destinations.size())
449 {
450 return false;
451 }
452 for (size_t i = 0; i < a.m_destinations.size(); ++i)
453 {
454 if (!(*(PeekPointer(a.m_destinations[i])) == *(PeekPointer(b.m_destinations[i]))))
455 {
456 return false;
457 }
458 }
459 return true;
460}
461
462bool
464{
465 if (m_originatorAddress != originator)
466 {
467 return false;
468 }
469 if (m_destinations[0]->GetDestinationAddress() == Mac48Address::GetBroadcast())
470 {
471 return false;
472 }
473 // -fstrict-overflow sensitive, see bug 1868
474 if (GetInformationFieldSize() > 255 - 11)
475 {
476 return false;
477 }
478 return true;
479}
480
481bool
483{
484 // -fstrict-overflow sensitive, see bug 1868
485 return (GetInformationFieldSize() > 255 - 11);
486}
487
488std::ostream&
489operator<<(std::ostream& os, const IePreq& a)
490{
491 a.Print(os);
492 return os;
493}
494} // namespace dot11s
495} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
uint8_t ReadU8()
Definition: buffer.h:1027
void WriteU8(uint8_t data)
Definition: buffer.h:881
void WriteHtolsbU32(uint32_t data)
Definition: buffer.cc:910
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:780
uint32_t ReadLsbtohU32()
Definition: buffer.cc:1076
an EUI-48 address
Definition: mac48-address.h:46
static Mac48Address GetBroadcast()
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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.
uint8_t m_flags
flags
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:66
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:454
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