A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
wifi-information-element-vector.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 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: Pavel Boyko <boyko@iitp.ru>
19  */
20 
22 #include "ns3/packet.h"
23 #include <algorithm>
24 
25 namespace ns3 {
26 
27 NS_OBJECT_ENSURE_REGISTERED (WifiInformationElementVector);
28 
30  : m_maxSize (1500)
31 {
32 }
34 {
35  for (IE_VECTOR::iterator i = m_elements.begin (); i != m_elements.end (); i++)
36  {
37  *i = 0;
38  }
39  m_elements.clear ();
40 }
41 TypeId
43 {
44  static TypeId tid = TypeId ("ns3::WifiInformationElementVector")
45  .SetParent<Header> ()
46  .AddConstructor<WifiInformationElementVector> ();
47  return tid;
48 }
49 TypeId
51 {
52  return GetTypeId ();
53 }
54 uint32_t
56 {
57  return GetSize ();
58 }
59 void
61 {
62  for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
63  {
64  start = (*i)->Serialize (start);
65  }
66 }
67 uint32_t
69 {
71  uint32_t size = start.GetSize ();
72  while (size > 0)
73  {
74  uint32_t deserialized = DeserializeSingleIe (i);
75  i.Next (deserialized);
76  size -= deserialized;
77  }
78  return i.GetDistanceFrom (start);
79 }
80 uint32_t
82 {
84  uint8_t id = i.ReadU8 ();
85  //unused: uint8_t length = i.ReadU8 ();
86  //but need side effects of read:
87  i.ReadU8 ();
88  Ptr<WifiInformationElement> newElement;
89  switch (id)
90  {
91  default:
92  NS_FATAL_ERROR ("Information element " << (uint16_t) id << " is not implemented");
93  return 0;
94  }
95  /* unreachable: b/c switch is guaranteed to return from this function
96  if (GetSize () + length > m_maxSize)
97  {
98  NS_FATAL_ERROR ("Check max size for information element!");
99  }
100  newElement->DeserializeInformationField (i, length);
101  i.Next (length);
102  m_elements.push_back (newElement);
103  return i.GetDistanceFrom (start);
104  */
105 }
106 void
107 WifiInformationElementVector::Print (std::ostream & os) const
108 {
110 }
111 void
113 {
114  m_maxSize = size;
115 }
118 {
119  return m_elements.begin ();
120 }
123 {
124  return m_elements.end ();
125 }
126 bool
128 {
129  if (element->GetInformationFieldSize () + 2 + GetSize () > m_maxSize)
130  {
131  return false;
132  }
133  m_elements.push_back (element);
134  return true;
135 }
138 {
139  for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
140  {
141  if ((*i)->ElementId () == id)
142  {
143  return (*i);
144  }
145  }
146  return 0;
147 }
148 namespace {
150 {
151  bool
153  {
154  return ((*PeekPointer (a)) < (*PeekPointer (b)));
155  }
156 };
157 }
158 uint32_t
160 {
161  uint32_t size = 0;
162  for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
163  {
164  size += ((*i)->GetInformationFieldSize () + 2);
165  }
166  return size;
167 }
168 
169 bool
171 {
172  if (m_elements.size () != a.m_elements.size ())
173  {
174  NS_ASSERT (false);
175  return false;
176  }
177  // In principle we could bypass some of the faffing about (and speed
178  // the comparison) by simply serialising each IE vector into a
179  // buffer and memcmp'ing the two.
180  //
181  // I'm leaving it like this, however, so that there is the option of
182  // having individual Information Elements implement slightly more
183  // flexible equality operators.
184  WifiInformationElementVector::IE_VECTOR::const_iterator j = a.m_elements.begin ();
185  for (WifiInformationElementVector::IE_VECTOR::const_iterator i = m_elements.begin (); i
186  != m_elements.end (); i++, j++)
187  {
188  if (!(*(*i) == *(*j)))
189  {
190  return false;
191  }
192  }
193 
194  return true;
195 }
196 
197 } // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
IE_VECTOR m_elements
Information element vector.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
virtual uint8_t GetInformationFieldSize() const =0
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
virtual bool operator==(const WifiInformationElementVector &a) const
Check if the given WifiInformationElementVectors are equivalent.
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
bool AddInformationElement(Ptr< WifiInformationElement > element)
add an IE, if maxSize has exceeded, returns false
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:811
iterator in a Buffer instance
Definition: buffer.h:98
Iterator End()
Returns End of the vector.
std::vector< Ptr< WifiInformationElement > >::iterator Iterator
As soon as this is a vector, we define an Iterator.
Ptr< WifiInformationElement > FindFirst(WifiInformationElementId id) const
vector of pointers to information elements is the body of IeVector
T * PeekPointer(const Ptr< T > &p)
Definition: ptr.h:280
void Next(void)
go forward by one byte
Definition: buffer.h:852
virtual uint32_t DeserializeSingleIe(Buffer::Iterator start)
Needed when you try to deserialize a lonely IE inside other header.
uint16_t m_maxSize
Size in bytes (actually, max packet length)
virtual void Print(std::ostream &os) const
Iterator Begin()
Returns Begin of the vector.
virtual void Serialize(Buffer::Iterator start) const
virtual uint32_t Deserialize(Buffer::Iterator start)
Information element vectorImplements a vector of WifiInformationElements.
uint32_t GetSize() const
Current number of bytes.
uint8_t ReadU8(void)
Definition: buffer.h:1028
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
void SetMaxSize(uint16_t size)
Set maximum size to control overflow of the max packet length.
uint32_t GetSize(void) const
Definition: buffer.cc:1187
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610