A Discrete-Event Network Simulator
API
ie-dot11s-preq.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2008,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: Kirill Andreev <andreev@iitp.ru>
19 */
20
21#include "ie-dot11s-preq.h"
22#include "ns3/address-utils.h"
23#include "ns3/assert.h"
24#include "ns3/packet.h"
25
26namespace ns3 {
27namespace dot11s {
28/*************************
29 * DestinationAddressUnit
30 ************************/
32 m_do (false), m_rf (false), m_usn (false), m_destinationAddress (Mac48Address ()), m_destSeqNumber (0)
33{
34}
35void
36DestinationAddressUnit::SetFlags (bool doFlag, bool rfFlag, bool usnFlag)
37{
38 m_do = doFlag;
39 m_rf = rfFlag;
40 m_usn = usnFlag;
41}
42
43void
45{
46 m_destSeqNumber = dest_seq_number;
47 if (m_destSeqNumber != 0)
48 {
49 m_usn = true;
50 }
51}
52void
54{
55 m_destinationAddress = dest_address;
56}
57bool
59{
60 return m_do;
61}
62
63bool
65{
66 return m_rf;
67}
68bool
70{
71 return m_usn;
72}
75{
76 return m_destSeqNumber;
77}
80{
82}
83/********************************
84 * IePreq
85 *******************************/
87{
88}
90 m_maxSize (32), m_flags (0), m_hopCount (0), m_ttl (0), m_preqId (0), m_originatorAddress (
91 Mac48Address::GetBroadcast ()), m_originatorSeqNumber (0), m_lifetime (0), m_metric (0),
92 m_destCount (0)
93{
94}
97{
98 return IE_PREQ;
99}
100void
102{
103 m_flags |= 1 << 1;
104}
105
106void
108{
109 m_flags |= 1 << 2;
110}
111void
112IePreq::SetHopcount (uint8_t hopcount)
113{
114 m_hopCount = hopcount;
115}
116void
117IePreq::SetTTL (uint8_t ttl)
118{
119 m_ttl = ttl;
120}
121void
123{
124 m_preqId = preq_id;
125}
126void
128{
129 m_metric = metric;
130}
131void
133{
134 m_originatorAddress = originator_address;
135}
136void
138{
139 m_originatorSeqNumber = originator_seq_number;
140}
141void
143{
144 m_lifetime = lifetime;
145}
146void
147IePreq::SetDestCount (uint8_t dest_count)
148{
149 m_destCount = dest_count;
150}
151bool
153{
154 return (m_flags & (1 << 1));
155}
156bool
158{
159 return (m_flags & (1 << 2));
160}
161uint8_t
163{
164 return m_hopCount;
165}
166uint8_t
168{
169 return m_ttl;
170}
173{
174 return m_preqId;
175}
178{
179 return m_metric;
180}
183{
184 return m_originatorAddress;
185}
188{
190}
193{
194 return m_lifetime;
195}
196
197uint8_t
199{
200 return m_destCount;
201}
202void
204{
205 m_ttl--;
206 m_hopCount++;
207}
208void
210{
211 m_metric += metric;
212}
213void
215{
216 i.WriteU8 (m_flags);
218 i.WriteU8 (m_ttl);
225 int written = 0;
226 for (std::vector<Ptr<DestinationAddressUnit> >::const_iterator j = m_destinations.begin (); j
227 != m_destinations.end (); j++)
228 {
229 uint8_t flags = 0;
230 if ((*j)->IsDo ())
231 {
232 flags |= 1 << 0;
233 }
234 if ((*j)->IsRf ())
235 {
236 flags |= 1 << 1;
237 }
238 if ((*j)->IsUsn ())
239 {
240 flags |= 1 << 2;
241 }
242 i.WriteU8 (flags);
243 WriteTo (i, (*j)->GetDestinationAddress ());
244 i.WriteHtolsbU32 ((*j)->GetDestSeqNumber ());
245 written++;
246 if (written > m_maxSize)
247 {
248 break;
249 }
250 }
251}
252uint8_t
254{
256 m_flags = i.ReadU8 ();
257 m_hopCount = i.ReadU8 ();
258 m_ttl = i.ReadU8 ();
259 m_preqId = i.ReadLsbtohU32 ();
263 m_metric = i.ReadLsbtohU32 ();
264 m_destCount = i.ReadU8 ();
265 for (int j = 0; j < m_destCount; j++)
266 {
267 Ptr<DestinationAddressUnit> new_element = Create<DestinationAddressUnit> ();
268 bool doFlag = false;
269 bool rfFlag = false;
270 bool usnFlag = false;
271 uint8_t flags = i.ReadU8 ();
272 if (flags & (1 << 0))
273 {
274 doFlag = true;
275 }
276 if (flags & (1 << 1))
277 {
278 rfFlag = true;
279 }
280 if (flags & (1 << 2))
281 {
282 usnFlag = true;
283 }
284 new_element->SetFlags (doFlag, rfFlag, usnFlag);
285 Mac48Address addr;
286 ReadFrom (i, addr);
287 new_element->SetDestinationAddress (addr);
288 new_element->SetDestSeqNumber (i.ReadLsbtohU32 ());
289 m_destinations.push_back (new_element);
290 NS_ASSERT (28 + j * 11 < length);
291 }
292 return i.GetDistanceFrom (start);
293}
294uint8_t
296{
297 uint8_t retval = 1 //Flags
298 + 1 //Hopcount
299 + 1 //TTL
300 + 4 //PREQ ID
301 + 6 //Source address (originator)
302 + 4 //Originator seqno
303 + 4 //Lifetime
304 + 4 //metric
305 + 1; //destination count
307 {
308 retval += (m_maxSize * 11);
309 }
310 else
311 {
312 retval += (m_destCount * 11);
313 }
314 return retval;
315}
316void
317IePreq::Print (std::ostream &os) const
318{
319 os << "PREQ=(originator address=" << m_originatorAddress
320 << ", TTL=" << (uint16_t) m_ttl
321 << ", hop count=" << (uint16_t) m_hopCount
322 << ", metric=" << m_metric
323 << ", seqno=" << m_originatorSeqNumber
324 << ", lifetime=" << m_lifetime
325 << ", preq ID=" << m_preqId
326 << ", Destinations=(";
327 for (int j = 0; j < m_destCount; j++)
328 {
329 os << m_destinations[j]->GetDestinationAddress ();
330 }
331 os << ")";
332}
333std::vector<Ptr<DestinationAddressUnit> >
335{
336 return m_destinations;
337}
338void
339IePreq::AddDestinationAddressElement (bool doFlag, bool rfFlag, Mac48Address dest_address,
340 uint32_t dest_seq_number)
341{
342 for (std::vector<Ptr<DestinationAddressUnit> >::const_iterator i = m_destinations.begin (); i
343 != m_destinations.end (); i++)
344 {
345 if ((*i)->GetDestinationAddress () == dest_address)
346 {
347 return;
348 }
349 }
351 Ptr<DestinationAddressUnit> new_element = Create<DestinationAddressUnit> ();
352 new_element->SetFlags (doFlag, rfFlag, (dest_seq_number == 0));
353 new_element->SetDestinationAddress (dest_address);
354 new_element->SetDestSeqNumber (dest_seq_number);
355 m_destinations.push_back (new_element);
356 m_destCount++;
357}
358void
360{
361 for (std::vector<Ptr<DestinationAddressUnit> >::iterator i = m_destinations.begin (); i
362 != m_destinations.end (); i++)
363 {
364 if ((*i)->GetDestinationAddress () == dest_address)
365 {
366 m_destinations.erase (i);
367 m_destCount--;
368 break;
369 }
370 }
371}
372void
374{
375 for (std::vector<Ptr<DestinationAddressUnit> >::iterator j = m_destinations.begin (); j
376 != m_destinations.end (); j++)
377 {
378 (*j) = 0;
379 }
380 m_destinations.clear ();
381 m_destCount = 0;
382}
383bool
385{
386 return (a.m_do == b.m_do && a.m_rf == b.m_rf && a.m_usn == b.m_usn && a.m_destinationAddress
388}
389bool
390operator== (const IePreq & a, const IePreq & b)
391{
392 bool ok = (a.m_flags == b.m_flags && a.m_hopCount == b.m_hopCount && a.m_ttl == b.m_ttl && a.m_preqId
395 == b.m_destCount);
396
397 if (!ok)
398 {
399 return false;
400 }
401 if (a.m_destinations.size () != b.m_destinations.size ())
402 {
403 return false;
404 }
405 for (size_t i = 0; i < a.m_destinations.size (); ++i)
406 {
407 if (!(*(PeekPointer (a.m_destinations[i])) == *(PeekPointer (b.m_destinations[i]))))
408 {
409 return false;
410 }
411 }
412 return true;
413}
414bool
416{
417 if (m_originatorAddress != originator)
418 {
419 return false;
420 }
421 if (m_destinations[0]->GetDestinationAddress () == Mac48Address::GetBroadcast ())
422 {
423 return false;
424 }
425 // -fstrict-overflow sensitive, see bug 1868
426 if ( GetInformationFieldSize () > 255 - 11 )
427 {
428 return false;
429 }
430 return true;
431}
432bool
434{
435 // -fstrict-overflow sensitive, see bug 1868
436 return ( GetInformationFieldSize () > 255 - 11 );
437}
438std::ostream &
439operator << (std::ostream &os, const IePreq &a)
440{
441 a.Print (os);
442 return os;
443}
444} // namespace dot11s
445} // namespace ns3
446
iterator in a Buffer instance
Definition: buffer.h:99
uint32_t ReadLsbtohU32(void)
Definition: buffer.cc:1077
void WriteU8(uint8_t data)
Definition: buffer.h:869
void WriteHtolsbU32(uint32_t data)
Definition: buffer.cc:918
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
an EUI-48 address
Definition: mac48-address.h:44
static Mac48Address GetBroadcast(void)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Describes an address unit in PREQ information element See 7.3.2.96 for more details.
uint32_t GetDestSeqNumber() const
Get destination sequence number.
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.
See 7.3.2.96 of 802.11s draft 2.07.
uint32_t GetOriginatorSeqNumber() const
Get originator sequence numnber 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.
virtual uint8_t GetInformationFieldSize() const
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
uint8_t GetDestCount() const
Get destination count.
void SetNeedNotPrep()
Set Proactive PREP subfield to off.
bool IsUnicastPreq() const
Is unicast PREQ function.
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.
virtual uint8_t DeserializeInformationField(Buffer::Iterator i, uint8_t length)
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
virtual WifiInformationElementId ElementId() const
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.
virtual void Print(std::ostream &os) const
Generate human-readable form of IE.
void SetMetric(uint32_t metric)
Set metric value.
bool IsFull() const
Is full function.
uint8_t m_flags
flags
bool MayAddAddress(Mac48Address originator)
Checks that preq's originator address equals to originator, and this preq is not proactive.
virtual void SerializeInformationField(Buffer::Iterator i) const
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
uint32_t m_metric
metric
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:67
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:415
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.
def start()
Definition: core.py:1853
#define IE_PREQ