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  ;
29 
31  : m_maxSize (1500)
32 {
33 }
35 {
36  for (IE_VECTOR::iterator i = m_elements.begin (); i != m_elements.end (); i++)
37  {
38  *i = 0;
39  }
40  m_elements.clear ();
41 }
42 TypeId
44 {
45  static TypeId tid = TypeId ("ns3::WifiInformationElementVector")
46  .SetParent<Header> ()
47  .AddConstructor<WifiInformationElementVector> ();
48  return tid;
49 }
50 TypeId
52 {
53  return GetTypeId ();
54 }
55 uint32_t
57 {
58  return GetSize ();
59 }
60 void
62 {
63  for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
64  {
65  start = (*i)->Serialize (start);
66  }
67 }
68 uint32_t
70 {
72  uint32_t size = start.GetSize ();
73  while (size > 0)
74  {
75  uint32_t deserialized = DeserializeSingleIe (i);
76  i.Next (deserialized);
77  size -= deserialized;
78  }
79  return i.GetDistanceFrom (start);
80 }
81 uint32_t
83 {
85  uint8_t id = i.ReadU8 ();
86  //unused: uint8_t length = i.ReadU8 ();
87  //but need side effects of read:
88  i.ReadU8 ();
89  Ptr<WifiInformationElement> newElement;
90  switch (id)
91  {
92  default:
93  NS_FATAL_ERROR ("Information element " << (uint16_t) id << " is not implemented");
94  return 0;
95  }
96  /* unreachable: b/c switch is guaranteed to return from this function
97  if (GetSize () + length > m_maxSize)
98  {
99  NS_FATAL_ERROR ("Check max size for information element!");
100  }
101  newElement->DeserializeInformationField (i, length);
102  i.Next (length);
103  m_elements.push_back (newElement);
104  return i.GetDistanceFrom (start);
105  */
106 }
107 void
108 WifiInformationElementVector::Print (std::ostream & os) const
109 {
111 }
112 void
114 {
115  m_maxSize = size;
116 }
119 {
120  return m_elements.begin ();
121 }
124 {
125  return m_elements.end ();
126 }
127 bool
129 {
130  if (element->GetInformationFieldSize () + 2 + GetSize () > m_maxSize)
131  {
132  return false;
133  }
134  m_elements.push_back (element);
135  return true;
136 }
139 {
140  for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
141  {
142  if ((*i)->ElementId () == id)
143  {
144  return (*i);
145  }
146  }
147  return 0;
148 }
149 namespace {
151 {
152  bool
154  {
155  return ((*PeekPointer (a)) < (*PeekPointer (b)));
156  }
157 };
158 }
159 uint32_t
161 {
162  uint32_t size = 0;
163  for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
164  {
165  size += ((*i)->GetInformationFieldSize () + 2);
166  }
167  return size;
168 }
169 
170 bool
172 {
173  if (m_elements.size () != a.m_elements.size ())
174  {
175  NS_ASSERT (false);
176  return false;
177  }
178  // In principle we could bypass some of the faffing about (and speed
179  // the comparison) by simply serialising each IE vector into a
180  // buffer and memcmp'ing the two.
181  //
182  // I'm leaving it like this, however, so that there is the option of
183  // having individual Information Elements implement slightly more
184  // flexible equality operators.
185  WifiInformationElementVector::IE_VECTOR::const_iterator j = a.m_elements.begin ();
186  for (WifiInformationElementVector::IE_VECTOR::const_iterator i = m_elements.begin (); i
187  != m_elements.end (); i++, j++)
188  {
189  if (!(*(*i) == *(*j)))
190  {
191  return false;
192  }
193  }
194 
195  return true;
196 }
197 
198 } // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
IE_VECTOR m_elements
Information element vector.
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)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
virtual bool operator==(const WifiInformationElementVector &a) const
Check if the given WifiInformationElementVectors are equivalent.
bool AddInformationElement(Ptr< WifiInformationElement > element)
add an IE, if maxSize has exceeded, returns false
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:807
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
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:279
void Next(void)
go forward by one byte
Definition: buffer.h:666
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:819
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:1183
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611