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
ie-dot11s-beacon-timing.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008,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: Kirill Andreev <andreev@iitp.ru>
19
*/
20
21
#include "
ie-dot11s-beacon-timing.h
"
22
#include "ns3/packet.h"
23
namespace
ns3 {
24
namespace
dot11s {
25
/*******************************************
26
* IeBeaconTimingUnit
27
*******************************************/
28
IeBeaconTimingUnit::IeBeaconTimingUnit
() :
29
m_aid (0), m_lastBeacon (0), m_beaconInterval (0)
30
{
31
}
32
void
33
IeBeaconTimingUnit::SetAid
(uint8_t aid)
34
{
35
m_aid
= aid;
36
}
37
void
38
IeBeaconTimingUnit::SetLastBeacon
(uint16_t lastBeacon)
39
{
40
m_lastBeacon
= lastBeacon;
41
}
42
void
43
IeBeaconTimingUnit::SetBeaconInterval
(uint16_t beaconInterval)
44
{
45
m_beaconInterval
= beaconInterval;
46
}
47
uint8_t
48
IeBeaconTimingUnit::GetAid
()
const
49
{
50
return
m_aid
;
51
}
52
uint16_t
53
IeBeaconTimingUnit::GetLastBeacon
()
const
54
{
55
return
m_lastBeacon
;
56
}
57
uint16_t
58
IeBeaconTimingUnit::GetBeaconInterval
()
const
59
{
60
return
m_beaconInterval
;
61
}
62
/*******************************************
63
* IeBeaconTiming
64
*******************************************/
65
WifiInformationElementId
66
IeBeaconTiming::ElementId
()
const
67
{
68
return
IE11S_BEACON_TIMING
;
69
}
70
IeBeaconTiming::IeBeaconTiming
() :
71
m_numOfUnits (0)
72
{
73
}
74
IeBeaconTiming::NeighboursTimingUnitsList
75
IeBeaconTiming::GetNeighboursTimingElementsList
()
76
{
77
return
m_neighbours
;
78
}
79
void
80
IeBeaconTiming::AddNeighboursTimingElementUnit
(uint16_t aid,
Time
last_beacon,
Time
beacon_interval)
81
{
82
if
(
m_numOfUnits
== 50)
83
{
84
return
;
85
}
86
//First we lookup if this element already exists
87
for
(NeighboursTimingUnitsList::const_iterator i =
m_neighbours
.begin (); i !=
m_neighbours
.end (); i++)
88
{
89
if
(((*i)->GetAid () ==
AidToU8
(aid)) && ((*i)->GetLastBeacon () ==
TimestampToU16
(last_beacon))
90
&& ((*i)->GetBeaconInterval () ==
BeaconIntervalToU16
(beacon_interval)))
91
{
92
return
;
93
}
94
}
95
Ptr<IeBeaconTimingUnit>
new_element = Create<IeBeaconTimingUnit> ();
96
new_element->
SetAid
(
AidToU8
(aid));
97
new_element->
SetLastBeacon
(
TimestampToU16
(last_beacon));
98
new_element->
SetBeaconInterval
(
BeaconIntervalToU16
(beacon_interval));
99
m_neighbours
.push_back (new_element);
100
m_numOfUnits
++;
101
}
102
void
103
IeBeaconTiming::DelNeighboursTimingElementUnit
(uint16_t aid,
Time
last_beacon,
Time
beacon_interval)
104
{
105
for
(NeighboursTimingUnitsList::iterator i =
m_neighbours
.begin (); i !=
m_neighbours
.end (); i++)
106
{
107
if
(((*i)->GetAid () ==
AidToU8
(aid)) && ((*i)->GetLastBeacon () ==
TimestampToU16
(last_beacon))
108
&& ((*i)->GetBeaconInterval () ==
BeaconIntervalToU16
(beacon_interval)))
109
{
110
m_neighbours
.erase (i);
111
m_numOfUnits
--;
112
break
;
113
}
114
}
115
}
116
void
117
IeBeaconTiming::ClearTimingElement
()
118
{
119
for
(NeighboursTimingUnitsList::iterator j =
m_neighbours
.begin (); j !=
m_neighbours
.end (); j++)
120
{
121
(*j) = 0;
122
}
123
m_neighbours
.clear ();
124
}
125
uint8_t
126
IeBeaconTiming::GetInformationFieldSize
()
const
127
{
128
return
(5 *
m_numOfUnits
);
129
}
130
void
131
IeBeaconTiming::Print
(std::ostream& os)
const
132
{
133
os << std::endl <<
"<information_element id="
<<
ElementId
() <<
">"
<< std::endl;
134
os <<
"Number of units: "
<< (uint16_t)
m_numOfUnits
<< std::endl;
135
for
(NeighboursTimingUnitsList::const_iterator j =
m_neighbours
.begin (); j !=
m_neighbours
.end (); j++)
136
{
137
os <<
"AID="
<< (uint16_t)(*j)->GetAid () <<
", Last beacon was at "
<< (*j)->GetLastBeacon ()
138
<<
", with beacon interval "
<< (*j)->GetBeaconInterval () << std::endl;
139
}
140
os <<
"</information_element>"
<< std::endl;
141
}
142
void
143
IeBeaconTiming::SerializeInformationField
(
Buffer::Iterator
i)
const
144
{
145
for
(NeighboursTimingUnitsList::const_iterator j =
m_neighbours
.begin (); j !=
m_neighbours
.end (); j++)
146
{
147
i.
WriteU8
((*j)->GetAid ());
148
i.
WriteHtolsbU16
((*j)->GetLastBeacon ());
149
i.
WriteHtolsbU16
((*j)->GetBeaconInterval ());
150
}
151
}
152
uint8_t
153
IeBeaconTiming::DeserializeInformationField
(
Buffer::Iterator
start
, uint8_t length)
154
{
155
Buffer::Iterator
i =
start
;
156
m_numOfUnits
= length / 5;
157
for
(
int
j = 0; j <
m_numOfUnits
; j++)
158
{
159
Ptr<IeBeaconTimingUnit>
new_element = Create<IeBeaconTimingUnit> ();
160
new_element->
SetAid
(i.
ReadU8
());
161
new_element->
SetLastBeacon
(i.
ReadLsbtohU16
());
162
new_element->
SetBeaconInterval
(i.
ReadLsbtohU16
());
163
m_neighbours
.push_back (new_element);
164
}
165
return
i.
GetDistanceFrom
(start);
166
}
167
;
168
uint16_t
169
IeBeaconTiming::TimestampToU16
(
Time
t)
170
{
171
return
((uint16_t)((t.
GetMicroSeconds
() >> 8) & 0xffff));
172
}
173
;
174
175
uint16_t
176
IeBeaconTiming::BeaconIntervalToU16
(
Time
t)
177
{
178
return
((uint16_t)(t.
GetMicroSeconds
() >> 10) & 0xffff);
179
}
180
uint8_t
181
IeBeaconTiming::AidToU8
(uint16_t
x
)
182
{
183
return
(uint8_t)(x & 0xff);
184
}
185
bool
186
operator==
(
const
IeBeaconTimingUnit
& a,
const
IeBeaconTimingUnit
& b)
187
{
188
return
((a.
GetAid
() == b.
GetAid
()) && (a.
GetLastBeacon
() == b.
GetLastBeacon
())
189
&& (a.
GetBeaconInterval
() == b.
GetBeaconInterval
()));
190
}
191
bool
192
IeBeaconTiming::operator==
(
WifiInformationElement
const
& a)
193
{
194
try
{
195
IeBeaconTiming
const
& aa =
dynamic_cast<
IeBeaconTiming
const
&
>
(a);
196
197
if
(
m_numOfUnits
!= aa.
m_numOfUnits
)
198
{
199
return
false
;
200
}
201
for
(
unsigned
int
i = 0; i <
m_neighbours
.size (); i++)
202
{
203
if
(!(*
PeekPointer
(
m_neighbours
[i]) == *
PeekPointer
(aa.
m_neighbours
[i])))
204
{
205
return
false
;
206
}
207
}
208
return
true
;
209
}
210
catch
(std::bad_cast)
211
{
212
return
false
;
213
}
214
}
215
std::ostream &
216
operator <<
(std::ostream &os,
const
IeBeaconTiming
&a)
217
{
218
a.
Print
(os);
219
return
os;
220
}
221
}
// namespace dot11s
222
}
// namespace ns3
223
src
mesh
model
dot11s
ie-dot11s-beacon-timing.cc
Generated on Tue Oct 9 2012 16:45:42 for ns-3 by
1.8.1.2