A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 IE11S_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 << std::endl << "<information_element id=" << ElementId () << ">" << std::endl;
320  os << " originator address = " << m_originatorAddress << std::endl;
321  os << " TTL = " << (uint16_t) m_ttl << std::endl;
322  os << " hop count = " << (uint16_t) m_hopCount << std::endl;
323  os << " metric = " << m_metric << std::endl;
324  os << " seqno = " << m_originatorSeqNumber << std::endl;
325  os << " lifetime = " << m_lifetime << std::endl;
326  os << " preq ID = " << m_preqId << std::endl;
327  os << " Destinations are:" << std::endl;
328  for (int j = 0; j < m_destCount; j++)
329  {
330  os << " " << m_destinations[j]->GetDestinationAddress () << std::endl;
331  }
332  os << "</information_element>" << std::endl;
333 }
334 std::vector<Ptr<DestinationAddressUnit> >
336 {
337  return m_destinations;
338 }
339 void
340 IePreq::AddDestinationAddressElement (bool doFlag, bool rfFlag, Mac48Address dest_address,
341  uint32_t dest_seq_number)
342 {
343  for (std::vector<Ptr<DestinationAddressUnit> >::const_iterator i = m_destinations.begin (); i
344  != m_destinations.end (); i++)
345  {
346  if ((*i)->GetDestinationAddress () == dest_address)
347  {
348  return;
349  }
350  }
352  Ptr<DestinationAddressUnit> new_element = Create<DestinationAddressUnit> ();
353  new_element->SetFlags (doFlag, rfFlag, (dest_seq_number == 0));
354  new_element->SetDestinationAddress (dest_address);
355  new_element->SetDestSeqNumber (dest_seq_number);
356  m_destinations.push_back (new_element);
357  m_destCount++;
358 }
359 void
361 {
362  for (std::vector<Ptr<DestinationAddressUnit> >::iterator i = m_destinations.begin (); i
363  != m_destinations.end (); i++)
364  {
365  if ((*i)->GetDestinationAddress () == dest_address)
366  {
367  m_destinations.erase (i);
368  m_destCount--;
369  break;
370  }
371  }
372 }
373 void
375 {
376  for (std::vector<Ptr<DestinationAddressUnit> >::iterator j = m_destinations.begin (); j
377  != m_destinations.end (); j++)
378  {
379  (*j) = 0;
380  }
381  m_destinations.clear ();
382  m_destCount = 0;
383 }
384 bool
386 {
387  return (a.m_do == b.m_do && a.m_rf == b.m_rf && a.m_usn == b.m_usn && a.m_destinationAddress
389 }
390 bool
391 operator== (const IePreq & a, const IePreq & b)
392 {
393  bool ok = (a.m_flags == b.m_flags && a.m_hopCount == b.m_hopCount && a.m_ttl == b.m_ttl && a.m_preqId
396  == b.m_destCount);
397 
398  if (!ok)
399  {
400  return false;
401  }
402  if (a.m_destinations.size () != b.m_destinations.size ())
403  {
404  return false;
405  }
406  for (size_t i = 0; i < a.m_destinations.size (); ++i)
407  {
408  if (!(*(PeekPointer (a.m_destinations[i])) == *(PeekPointer (b.m_destinations[i]))))
409  {
410  return false;
411  }
412  }
413  return true;
414 }
415 bool
417 {
418  if (m_originatorAddress != originator)
419  {
420  return false;
421  }
422  if (m_destinations[0]->GetDestinationAddress () == Mac48Address::GetBroadcast ())
423  {
424  return false;
425  }
426  if ((GetInformationFieldSize () + 11) > 255)
427  {
428  return false;
429  }
430  return true;
431 }
432 bool
434 {
435  return ((GetInformationFieldSize () + 11) > 255);
436 }
437 std::ostream &
438 operator << (std::ostream &os, const IePreq &a)
439 {
440  a.Print (os);
441  return os;
442 }
443 } // namespace dot11s
444 } // namespace ns3
445 
void SetPreqID(uint32_t id)
void SetFlags(bool doFlag, bool rfFlag, bool usnFlag)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
void SetTTL(uint8_t ttl)
uint8_t GetHopCount() const
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
std::vector< Ptr< DestinationAddressUnit > > m_destinations
#define NS_ASSERT(condition)
Definition: assert.h:64
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
uint32_t GetLifetime() const
uint32_t m_originatorSeqNumber
bool operator==(const MeshHeader &a, const MeshHeader &b)
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:807
void SetDestSeqNumber(uint32_t dest_seq_number)
iterator in a Buffer instance
Definition: buffer.h:98
void SetLifetime(uint32_t lifetime)
Mac48Address m_originatorAddress
Mac48Address GetOriginatorAddress() const
uint8_t GetTtl() const
void DecrementTtl()
Handle TTL and Metric:
virtual void Print(std::ostream &os) const
In addition, a subclass may optionally override the following...
void IncrementMetric(uint32_t metric)
void SetDestCount(uint8_t dest_count)
virtual WifiInformationElementId ElementId() const
Own unique Element ID.
See 7.3.2.96 of 802.11s draft 2.07.
#define IE11S_PREQ
void ClearDestinationAddressElements()
Clear PREQ: remove all destinations.
T * PeekPointer(const Ptr< T > &p)
Definition: ptr.h:279
static Mac48Address GetBroadcast(void)
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) ...
uint32_t GetOriginatorSeqNumber() const
void SetOriginatorAddress(Mac48Address originator_address)
void SetOriginatorSeqNumber(uint32_t originator_seq_number)
void SetMetric(uint32_t metric)
void AddDestinationAddressElement(bool doFlag, bool rfFlag, Mac48Address dest_address, uint32_t dest_seq_number)
Add a destination address unit: flags, destination and sequence number.
void DelDestinationAddressElement(Mac48Address dest_address)
Delete a destination address unit by destination.
virtual void SerializeInformationField(Buffer::Iterator i) const
Serialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
bool IsNeedNotPrep() const
an EUI-48 address
Definition: mac48-address.h:41
uint8_t GetDestCount() const
std::vector< Ptr< DestinationAddressUnit > > GetDestinationList()
Get all destinations, which are stored in PREQ:
void SetUnicastPreq()
SetProper flags which indicate that PREQ is unicast.
bool MayAddAddress(Mac48Address originator)
uint8_t m_maxSize
how many destinations we support
void WriteU8(uint8_t data)
Definition: buffer.h:690
bool IsUnicastPreq() const
virtual uint8_t GetInformationFieldSize() const
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
uint32_t GetPreqID() const
uint8_t ReadU8(void)
Definition: buffer.h:819
Mac48Address GetDestinationAddress() const
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
uint8_t m_flags
Fields of information element:
uint32_t GetMetric() const
bool IsFull() const
Describes an address unit in PREQ information element See 7.3.2.96 for more details.
void SetDestinationAddress(Mac48Address dest_address)
std::ostream & operator<<(std::ostream &os, const IeBeaconTiming &a)
uint32_t ReadLsbtohU32(void)
Definition: buffer.cc:1101
void SetHopcount(uint8_t hopcount)
void WriteHtolsbU32(uint32_t data)
Definition: buffer.cc:942