A Discrete-Event Network Simulator
API
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 
23 namespace ns3 {
24 
25 NS_OBJECT_ENSURE_REGISTERED (WifiInformationElementVector);
26 
28  : m_maxSize (1500)
29 {
30 }
31 
33 {
34  for (IE_VECTOR::iterator i = m_elements.begin (); i != m_elements.end (); i++)
35  {
36  *i = 0;
37  }
38  m_elements.clear ();
39 }
40 
41 TypeId
43 {
44  static TypeId tid = TypeId ("ns3::WifiInformationElementVector")
45  .SetParent<Header> ()
46  .SetGroupName ("Wifi")
47  .AddConstructor<WifiInformationElementVector> ();
48  return tid;
49 }
50 
51 TypeId
53 {
54  return GetTypeId ();
55 }
56 
57 uint32_t
59 {
60  return GetSize ();
61 }
62 
63 void
65 {
66  for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
67  {
68  start = (*i)->Serialize (start);
69  }
70 }
71 
72 uint32_t
74 {
76  uint32_t size = start.GetSize ();
77  while (size > 0)
78  {
79  uint32_t deserialized = DeserializeSingleIe (i);
80  i.Next (deserialized);
81  size -= deserialized;
82  }
83  return i.GetDistanceFrom (start);
84 }
85 
86 uint32_t
88 {
90  uint8_t id = i.ReadU8 ();
91  //unused: uint8_t length = i.ReadU8 ();
92  //but need side effects of read:
93  i.ReadU8 ();
94  Ptr<WifiInformationElement> newElement;
95  switch (id)
96  {
97  default:
98  NS_FATAL_ERROR ("Information element " << (uint16_t) id << " is not implemented");
99  return 0;
100  }
101  /* unreachable: b/c switch is guaranteed to return from this function
102  if (GetSize () + length > m_maxSize)
103  {
104  NS_FATAL_ERROR ("Check max size for information element!");
105  }
106  newElement->DeserializeInformationField (i, length);
107  i.Next (length);
108  m_elements.push_back (newElement);
109  return i.GetDistanceFrom (start);
110  */
111 }
112 
113 void
114 WifiInformationElementVector::Print (std::ostream & os) const
115 {
116  for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
117  {
118  os << "(";
119  (*i)->Print (os);
120  os << ")";
121  }
122 }
123 
124 void
126 {
127  m_maxSize = size;
128 }
129 
132 {
133  return m_elements.begin ();
134 }
135 
138 {
139  return m_elements.end ();
140 }
141 
142 bool
144 {
145  if (element->GetInformationFieldSize () + 2 + GetSize () > m_maxSize)
146  {
147  return false;
148  }
149  m_elements.push_back (element);
150  return true;
151 }
152 
155 {
156  for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
157  {
158  if ((*i)->ElementId () == id)
159  {
160  return (*i);
161  }
162  }
163  return 0;
164 }
165 
166 
167 namespace {
168 
171 {
179  bool
181  {
182  return ((*PeekPointer (a)) < (*PeekPointer (b)));
183  }
184 };
185 
186 }
187 
188 
189 uint32_t
191 {
192  uint32_t size = 0;
193  for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
194  {
195  size += ((*i)->GetInformationFieldSize () + 2);
196  }
197  return size;
198 }
199 
200 bool
202 {
203  if (m_elements.size () != a.m_elements.size ())
204  {
205  NS_ASSERT (false);
206  return false;
207  }
208  //In principle we could bypass some of the faffing about (and speed
209  //the comparison) by simply serialising each IE vector into a
210  //buffer and memcmp'ing the two.
211  //
212  //I'm leaving it like this, however, so that there is the option of
213  //having individual Information Elements implement slightly more
214  //flexible equality operators.
215  WifiInformationElementVector::IE_VECTOR::const_iterator j = a.m_elements.begin ();
216  for (WifiInformationElementVector::IE_VECTOR::const_iterator i = m_elements.begin (); i
217  != m_elements.end (); i++, j++)
218  {
219  if (!(*(*i) == *(*j)))
220  {
221  return false;
222  }
223  }
224 
225  return true;
226 }
227 
228 } //namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
static TypeId GetTypeId()
Get the type ID.
IE_VECTOR m_elements
Information element vector.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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...
def start()
Definition: core.py:1790
#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
virtual bool operator==(const WifiInformationElementVector &a) const
Check if the given WifiInformationElementVectors are equivalent.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
bool AddInformationElement(Ptr< WifiInformationElement > element)
add an IE, if maxSize has exceeded, returns false
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:786
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
void Next(void)
go forward by one byte
Definition: buffer.h:845
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:1021
TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
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:1161
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914