A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
21
#include "
wifi-information-element-vector.h
"
22
#include "ns3/packet.h"
23
#include <algorithm>
24
25
namespace
ns3 {
26
27
NS_OBJECT_ENSURE_REGISTERED
(WifiInformationElementVector);
28
29
WifiInformationElementVector::WifiInformationElementVector
()
30
: m_maxSize (1500)
31
{
32
}
33
WifiInformationElementVector::~WifiInformationElementVector
()
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
42
WifiInformationElementVector::GetTypeId
()
43
{
44
static
TypeId
tid =
TypeId
(
"ns3::WifiInformationElementVector"
)
45
.
SetParent
<
Header
> ()
46
.AddConstructor<WifiInformationElementVector> ();
47
return
tid;
48
}
49
TypeId
50
WifiInformationElementVector::GetInstanceTypeId
()
const
51
{
52
return
GetTypeId
();
53
}
54
uint32_t
55
WifiInformationElementVector::GetSerializedSize
()
const
56
{
57
return
GetSize
();
58
}
59
void
60
WifiInformationElementVector::Serialize
(
Buffer::Iterator
start
)
const
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
68
WifiInformationElementVector::Deserialize
(
Buffer::Iterator
start
)
69
{
70
Buffer::Iterator
i =
start
;
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
81
WifiInformationElementVector::DeserializeSingleIe
(
Buffer::Iterator
start
)
82
{
83
Buffer::Iterator
i =
start
;
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
112
WifiInformationElementVector::SetMaxSize
(uint16_t size)
113
{
114
m_maxSize
= size;
115
}
116
WifiInformationElementVector::Iterator
117
WifiInformationElementVector::Begin
()
118
{
119
return
m_elements
.begin ();
120
}
121
WifiInformationElementVector::Iterator
122
WifiInformationElementVector::End
()
123
{
124
return
m_elements
.end ();
125
}
126
bool
127
WifiInformationElementVector::AddInformationElement
(
Ptr<WifiInformationElement>
element)
128
{
129
if
(element->
GetInformationFieldSize
() + 2 +
GetSize
() >
m_maxSize
)
130
{
131
return
false
;
132
}
133
m_elements
.push_back (element);
134
return
true
;
135
}
136
Ptr<WifiInformationElement>
137
WifiInformationElementVector::FindFirst
(
WifiInformationElementId
id
)
const
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
{
149
struct
PIEComparator
150
{
151
bool
152
operator () (
Ptr<WifiInformationElement>
a,
Ptr<WifiInformationElement>
b)
const
153
{
154
return
((*
PeekPointer
(a)) < (*
PeekPointer
(b)));
155
}
156
};
157
}
158
uint32_t
159
WifiInformationElementVector::GetSize
()
const
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
170
WifiInformationElementVector::operator==
(
const
WifiInformationElementVector
& a)
const
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
src
wifi
model
wifi-information-element-vector.cc
Generated on Fri Aug 30 2013 01:43:05 for ns-3 by
1.8.1.2