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
23namespace ns3 {
24
25NS_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
43{
44 static TypeId tid = TypeId ("ns3::WifiInformationElementVector")
45 .SetParent<Header> ()
46 .SetGroupName ("Wifi")
47 .AddConstructor<WifiInformationElementVector> ();
48 return tid;
49}
50
53{
54 return GetTypeId ();
55}
56
59{
60 return GetSize ();
61}
62
63void
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
74{
75 NS_FATAL_ERROR ("This variant should not be called on a variable-sized header");
76 return 0;
77}
78
81{
82 uint32_t size = start.GetDistanceFrom (end);
83 uint32_t remaining = size;
84 while (remaining > 0)
85 {
86 uint32_t deserialized = DeserializeSingleIe (start);
87 start.Next (deserialized);
88 NS_ASSERT (deserialized <= remaining);
89 remaining -= deserialized;
90 }
91 NS_ASSERT_MSG (remaining == 0, "Error in deserialization");
92 return size;
93}
94
97{
99 uint8_t id = i.ReadU8 ();
100 //unused: uint8_t length = i.ReadU8 ();
101 //but need side effects of read:
102 i.ReadU8 ();
104 switch (id)
105 {
106 case 0: // eliminate compiler warning
107 default:
108 NS_FATAL_ERROR ("Information element " << +id << " is not implemented");
109 return 0;
110 }
111 /* unreachable: b/c switch is guaranteed to return from this function
112 if (GetSize () + length > m_maxSize)
113 {
114 NS_FATAL_ERROR ("Check max size for information element!");
115 }
116 newElement->DeserializeInformationField (i, length);
117 i.Next (length);
118 m_elements.push_back (newElement);
119 return i.GetDistanceFrom (start);
120 */
121}
122
123void
124WifiInformationElementVector::Print (std::ostream & os) const
125{
126 for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
127 {
128 os << "(";
129 (*i)->Print (os);
130 os << ")";
131 }
132}
133
136{
137 return m_elements.begin ();
138}
139
142{
143 return m_elements.end ();
144}
145
146bool
148{
149 if (element->GetSerializedSize () + GetSize () > m_maxSize)
150 {
151 return false;
152 }
153 m_elements.push_back (element);
154 return true;
155}
156
159{
160 for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
161 {
162 if ((*i)->ElementId () == id)
163 {
164 return (*i);
165 }
166 }
167 return 0;
168}
169
172{
173 uint32_t size = 0;
174 for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++)
175 {
176 size += (*i)->GetSerializedSize ();
177 }
178 return size;
179}
180
181bool
183{
184 if (m_elements.size () != a.m_elements.size ())
185 {
186 NS_ASSERT (false);
187 return false;
188 }
189 //In principle we could bypass some of the faffing about (and speed
190 //the comparison) by simply serialising each IE vector into a
191 //buffer and memcmp'ing the two.
192 //
193 //I'm leaving it like this, however, so that there is the option of
194 //having individual Information Elements implement slightly more
195 //flexible equality operators.
196 WifiInformationElementVector::IE_VECTOR::const_iterator j = a.m_elements.begin ();
197 for (WifiInformationElementVector::IE_VECTOR::const_iterator i = m_elements.begin (); i
198 != m_elements.end (); i++, j++)
199 {
200 if (!(*(*i) == *(*j)))
201 {
202 return false;
203 }
204 }
205
206 return true;
207}
208
209} //namespace ns3
iterator in a Buffer instance
Definition: buffer.h:99
uint8_t ReadU8(void)
Definition: buffer.h:1021
Protocol header serialization and deserialization.
Definition: header.h:43
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
uint16_t GetSerializedSize() const
Get the size of the serialized IE including Element ID and length fields (for every element this IE i...
IE_VECTOR m_elements
Information element vector.
virtual uint32_t DeserializeSingleIe(Buffer::Iterator start)
Needed when you try to deserialize a lonely IE inside other header.
uint32_t GetSize() const
Current number of bytes.
Iterator End()
Returns End of the vector.
Iterator Begin()
Returns Begin of the vector.
void Serialize(Buffer::Iterator start) const override
std::vector< Ptr< WifiInformationElement > >::iterator Iterator
As soon as this is a vector, we define an Iterator.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void Print(std::ostream &os) const override
uint32_t Deserialize(Buffer::Iterator start) override
bool AddInformationElement(Ptr< WifiInformationElement > element)
add an IE, if maxSize has exceeded, returns false
Ptr< WifiInformationElement > FindFirst(WifiInformationElementId id) const
vector of pointers to information elements is the body of IeVector
uint16_t m_maxSize
Size in bytes (actually, max packet length)
virtual bool operator==(const WifiInformationElementVector &a) const
Check if the given WifiInformationElementVectors are equivalent.
#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
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
def start()
Definition: core.py:1852