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 
26 namespace ns3 {
27 namespace dot11s {
28 /*************************
29  * DestinationAddressUnit
30  ************************/
32  m_do (false), m_rf (false), m_usn (false), m_destinationAddress (Mac48Address ()), m_destSeqNumber (0)
33 {
34 }
35 void
36 DestinationAddressUnit::SetFlags (bool doFlag, bool rfFlag, bool usnFlag)
37 {
38  m_do = doFlag;
39  m_rf = rfFlag;
40  m_usn = usnFlag;
41 }
42 
43 void
44 DestinationAddressUnit::SetDestSeqNumber (uint32_t dest_seq_number)
45 {
46  m_destSeqNumber = dest_seq_number;
47  if (m_destSeqNumber != 0)
48  {
49  m_usn = true;
50  }
51 }
52 void
54 {
55  m_destinationAddress = dest_address;
56 }
57 bool
59 {
60  return m_do;
61 }
62 
63 bool
65 {
66  return m_rf;
67 }
68 bool
70 {
71  return m_usn;
72 }
73 uint32_t
75 {
76  return m_destSeqNumber;
77 }
80 {
81  return m_destinationAddress;
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 }
100 void
102 {
103  m_flags |= 1 << 1;
104 }
105 
106 void
108 {
109  m_flags |= 1 << 2;
110 }
111 void
112 IePreq::SetHopcount (uint8_t hopcount)
113 {
114  m_hopCount = hopcount;
115 }
116 void
117 IePreq::SetTTL (uint8_t ttl)
118 {
119  m_ttl = ttl;
120 }
121 void
122 IePreq::SetPreqID (uint32_t preq_id)
123 {
124  m_preqId = preq_id;
125 }
126 void
127 IePreq::SetMetric (uint32_t metric)
128 {
129  m_metric = metric;
130 }
131 void
133 {
134  m_originatorAddress = originator_address;
135 }
136 void
137 IePreq::SetOriginatorSeqNumber (uint32_t originator_seq_number)
138 {
139  m_originatorSeqNumber = originator_seq_number;
140 }
141 void
142 IePreq::SetLifetime (uint32_t lifetime)
143 {
144  m_lifetime = lifetime;
145 }
146 void
147 IePreq::SetDestCount (uint8_t dest_count)
148 {
149  m_destCount = dest_count;
150 }
151 bool
153 {
154  return (m_flags & (1 << 1));
155 }
156 bool
158 {
159  return (m_flags & (1 << 2));
160 }
161 uint8_t
163 {
164  return m_hopCount;
165 }
166 uint8_t
168 {
169  return m_ttl;
170 }
171 uint32_t
173 {
174  return m_preqId;
175 }
176 uint32_t
178 {
179  return m_metric;
180 }
183 {
184  return m_originatorAddress;
185 }
186 uint32_t
188 {
189  return m_originatorSeqNumber;
190 }
191 uint32_t
193 {
194  return m_lifetime;
195 }
196 
197 uint8_t
199 {
200  return m_destCount;
201 }
202 void
204 {
205  m_ttl--;
206  m_hopCount++;
207 }
208 void
209 IePreq::IncrementMetric (uint32_t metric)
210 {
211  m_metric += metric;
212 }
213 void
215 {
216  i.WriteU8 (m_flags);
217  i.WriteU8 (m_hopCount);
218  i.WriteU8 (m_ttl);
224  i.WriteU8 (m_destCount);
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 }
252 uint8_t
254 {
256  m_flags = i.ReadU8 ();
257  m_hopCount = i.ReadU8 ();
258  m_ttl = i.ReadU8 ();
259  m_preqId = i.ReadLsbtohU32 ();
262  m_lifetime = 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 }
294 uint8_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
306  if (m_destCount > m_maxSize)
307  {
308  retval += (m_maxSize * 11);
309  }
310  else
311  {
312  retval += (m_destCount * 11);
313  }
314  return retval;
315 }
316 void
317 IePreq::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 }
333 std::vector<Ptr<DestinationAddressUnit> >
335 {
336  return m_destinations;
337 }
338 void
339 IePreq::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 }
358 void
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 }
372 void
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 }
383 bool
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 }
389 bool
390 operator== (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 }
414 bool
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 }
432 bool
434 {
435  // -fstrict-overflow sensitive, see bug 1868
436  return ( GetInformationFieldSize () > 255 - 11 );
437 }
438 std::ostream &
439 operator << (std::ostream &os, const IePreq &a)
440 {
441  a.Print (os);
442  return os;
443 }
444 } // namespace dot11s
445 } // namespace ns3
446 
virtual uint8_t GetInformationFieldSize() const
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
void SetPreqID(uint32_t id)
Set path discovery id field.
void SetFlags(bool doFlag, bool rfFlag, bool usnFlag)
Set flags function.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void SetTTL(uint8_t ttl)
Set remaining number of hops allowed for this element.
Mac48Address GetOriginatorAddress() const
Get originator address value.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
def start()
Definition: core.py:1844
std::vector< Ptr< DestinationAddressUnit > > m_destinations
the destinations
uint32_t GetOriginatorSeqNumber() const
Get originator sequence numnber value.
uint8_t m_destCount
destination count
uint32_t m_destSeqNumber
destination sequence number
#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
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:564
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
uint8_t m_hopCount
hop count
virtual void SerializeInformationField(Buffer::Iterator i) const
Serialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
uint8_t GetDestCount() const
Get destination count.
uint32_t m_originatorSeqNumber
originator sequence number
bool operator==(const MeshHeader &a, const MeshHeader &b)
void SetDestSeqNumber(uint32_t dest_seq_number)
Set destination sequence number.
void SetNeedNotPrep()
Set Proactive PREP subfield to off.
iterator in a Buffer instance
Definition: buffer.h:98
void SetLifetime(uint32_t lifetime)
Set lifetime in TUs for the forwarding information to be considered valid.
bool IsUnicastPreq() const
Is unicast PREQ function.
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:783
Mac48Address m_originatorAddress
originator address
void DecrementTtl()
Handle TTL.
Mac48Address m_destinationAddress
destination address
void IncrementMetric(uint32_t metric)
Handle Metric:
void SetDestCount(uint8_t dest_count)
Set destination count value.
virtual WifiInformationElementId ElementId() const
See 7.3.2.96 of 802.11s draft 2.07.
uint32_t m_preqId
PREQ ID.
void ClearDestinationAddressElements()
Clear PREQ: remove all destinations.
virtual void Print(std::ostream &os) const
Generate human-readable form of IE.
uint32_t m_metric
metric
bool IsFull() const
Is full function.
static Mac48Address GetBroadcast(void)
uint8_t GetTtl() const
Get TTL 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) ...
void SetOriginatorAddress(Mac48Address originator_address)
Set originator address value.
void SetOriginatorSeqNumber(uint32_t originator_seq_number)
Set originator sequence number.
Mac48Address GetDestinationAddress() const
Get destination address function.
void SetMetric(uint32_t metric)
Set metric value.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void AddDestinationAddressElement(bool doFlag, bool rfFlag, Mac48Address dest_address, uint32_t dest_seq_number)
Add a destination address unit: flags, destination and sequence number.
uint32_t GetLifetime() const
Get lifetime value.
void DelDestinationAddressElement(Mac48Address dest_address)
Delete a destination address unit by destination.
an EUI-48 address
Definition: mac48-address.h:43
std::vector< Ptr< DestinationAddressUnit > > GetDestinationList()
Get all destinations, which are stored in PREQ:
void SetUnicastPreq()
Set flag indicating that PREQ is unicast.
bool MayAddAddress(Mac48Address originator)
Checks that preq&#39;s originator address equals to originator, and this preq is not proactive.
#define IE_PREQ
bool IsNeedNotPrep() const
Check whether Proactive PREP subfield to off.
uint8_t m_maxSize
how many destinations we support
void WriteU8(uint8_t data)
Definition: buffer.h:869
uint32_t GetMetric() const
Get metric value.
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
uint8_t m_flags
flags
uint32_t GetDestSeqNumber() const
Get destination sequence number.
uint32_t GetPreqID() const
Get path discovery id field.
Describes an address unit in PREQ information element See 7.3.2.96 for more details.
void SetDestinationAddress(Mac48Address dest_address)
Set destination address function.
std::ostream & operator<<(std::ostream &os, const IeBeaconTiming &a)
uint32_t ReadLsbtohU32(void)
Definition: buffer.cc:1076
void SetHopcount(uint8_t hopcount)
Set number of hops from originator to mesh STA transmitting this element.
uint8_t GetHopCount() const
Get hop count value.
uint32_t m_lifetime
lifetime
void WriteHtolsbU32(uint32_t data)
Definition: buffer.cc:917