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
uint8_t length = i.
ReadU8
();
86
Ptr<WifiInformationElement>
newElement;
87
switch
(
id
)
88
{
89
default
:
90
NS_FATAL_ERROR
(
"Information element "
<< (uint16_t)
id
<<
" is not implemented"
);
91
return
0;
92
}
93
if
(
GetSize
() + length >
m_maxSize
)
94
{
95
NS_FATAL_ERROR
(
"Check max size for information element!"
);
96
}
97
newElement->
DeserializeInformationField
(i, length);
98
i.
Next
(length);
99
m_elements
.push_back (newElement);
100
return
i.
GetDistanceFrom
(start);
101
}
102
void
103
WifiInformationElementVector::Print
(std::ostream & os)
const
104
{
105
//TODO
106
}
107
void
108
WifiInformationElementVector::SetMaxSize
(uint16_t size)
109
{
110
m_maxSize
= size;
111
}
112
WifiInformationElementVector::Iterator
113
WifiInformationElementVector::Begin
()
114
{
115
return
m_elements
.begin ();
116
}
117
WifiInformationElementVector::Iterator
118
WifiInformationElementVector::End
()
119
{
120
return
m_elements
.end ();
121
}
122
bool
123
WifiInformationElementVector::AddInformationElement
(
Ptr<WifiInformationElement>
element)
124
{
125
if
(element->
GetInformationFieldSize
() + 2 +
GetSize
() >
m_maxSize
)
126
{
127
return
false
;
128
}
129
m_elements
.push_back (element);
130
return
true
;
131
}
132
Ptr<WifiInformationElement>
133
WifiInformationElementVector::FindFirst
(
WifiInformationElementId
id
)
const
134
{
135
for
(IE_VECTOR::const_iterator i =
m_elements
.begin (); i !=
m_elements
.end (); i++)
136
{
137
if
((*i)->ElementId () == id)
138
{
139
return
(*i);
140
}
141
}
142
return
0;
143
}
144
namespace
{
145
struct
PIEComparator
146
{
147
bool
148
operator () (
Ptr<WifiInformationElement>
a,
Ptr<WifiInformationElement>
b)
const
149
{
150
return
((*
PeekPointer
(a)) < (*
PeekPointer
(b)));
151
}
152
};
153
}
154
uint32_t
155
WifiInformationElementVector::GetSize
()
const
156
{
157
uint32_t size = 0;
158
for
(IE_VECTOR::const_iterator i =
m_elements
.begin (); i !=
m_elements
.end (); i++)
159
{
160
size += ((*i)->GetInformationFieldSize () + 2);
161
}
162
return
size;
163
}
164
165
bool
166
WifiInformationElementVector::operator==
(
const
WifiInformationElementVector
& a)
const
167
{
168
if
(
m_elements
.size () != a.
m_elements
.size ())
169
{
170
NS_ASSERT
(
false
);
171
return
false
;
172
}
173
// In principle we could bypass some of the faffing about (and speed
174
// the comparison) by simply serialising each IE vector into a
175
// buffer and memcmp'ing the two.
176
//
177
// I'm leaving it like this, however, so that there is the option of
178
// having individual Information Elements implement slightly more
179
// flexible equality operators.
180
WifiInformationElementVector::IE_VECTOR::const_iterator j = a.
m_elements
.begin ();
181
for
(WifiInformationElementVector::IE_VECTOR::const_iterator i =
m_elements
.begin (); i
182
!=
m_elements
.end (); i++, j++)
183
{
184
if
(!(*(*i) == *(*j)))
185
{
186
return
false
;
187
}
188
}
189
190
return
true
;
191
}
192
193
}
// namespace ns3
src
wifi
model
wifi-information-element-vector.cc
Generated on Tue Nov 13 2012 10:32:25 for ns-3 by
1.8.1.2